Write safe driver input/output check

Source: Internet
Author: User
Write safe driver input/output check

The input/output check is a process of checking the validity of untrusted input/output addresses and data lengths. This method is widely used in Windows Kernel APIs.

For example, in the ntreadfile function, if the previusmode is not kernelmode, that is, the ntreadfile function is called from the user State, you can use the probeforwrite function to check whether the input/output buffer is writable. See the code in reactos as follows:

Ntstatus ntapi ntreadfile (inhandle filehandle,

In handle event optional,

In pio_apc_routine apcroutineoptional,

In pvoid apccontext optional,

Out pio_status_block iostatusblock,

Out pvoid buffer,

In ulong length,

In plarge_integer byteoffset optional,

In Pulong key optional)

{

Kprocessor_mode previusmode = kegetpreviusmode ();

// Omit Part of the code ......

/* Validate user-mode buffers */

If (previusmode! = Kernelmode)

{

_ Seh2_try

{

/* Probe the status block */

Probeforwriteiostatusblock (iostatusblock );

/* Probe the read buffer */

Probeforwrite (buffer, length, 1 );

// Omit Part of the code ......

Similarly, when the ntwritefile function finds that previusmode is not kernelmode, that is, it is called from the user State, you can use the probeforread function for detection.

In iocontrol, if the mthod specified by iocontrolcode is method_neither, use the probeforread and probeforwrite functions for the input and output addresses.

 

This article is excerpted from "0-day security: software vulnerability analysis technology (version 2nd.

Book details: http://blog.csdn.net/broadview2006/article/details/6596921

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.