[PATCH] ioctl: fix conflicts command number decoding in case of conflicts

Dmitry V. Levin ldv at altlinux.org
Wed Sep 23 00:28:09 UTC 2015


On Wed, Sep 23, 2015 at 01:45:52AM +0200, Gabriel Laskar wrote:
> When a command number was decoded through ioctl_decode_command_number(),
> there was no check for conflicts with other potential ioctls numbers.
> 
> For example:
> 	ioctl(fd, MCE_GET_RECORD_LEN, &i);
> output:
> 	ioctl(3, MIXER_READ(1), 0x7ffddce74a58) = 0
> instead of:
> 	ioctl(3, MIXER_READ(1) or MCE_GET_RECORD_LEN, 0x7ffee435ce08) = 0

Indeed.

> --- a/ioctl.c
> +++ b/ioctl.c
> @@ -277,15 +277,16 @@ SYS_FUNC(ioctl)
>  	if (entering(tcp)) {
>  		printfd(tcp, tcp->u_arg[0]);
>  		tprints(", ");
> -		if (!ioctl_decode_command_number(tcp)) {
> -			iop = ioctl_lookup(tcp->u_arg[1]);
> -			if (iop) {
> -				tprints(iop->symbol);
> -				while ((iop = ioctl_next_match(iop)))
> -					tprintf(" or %s", iop->symbol);
> -			} else {
> +		ret = ioctl_decode_command_number(tcp);
> +		iop = ioctl_lookup(tcp->u_arg[1]);
> +		if (!iop && !ret) {
>  				ioctl_print_code(tcp->u_arg[1]);
> -			}
> +		} else {
> +			if (ret)
> +				tprints(" or ");
> +			tprints(iop->symbol);

What if iop == NULL?

Please check your patch with tests/ioctl.c -- the test should pass.


> +			while ((iop = ioctl_next_match(iop)))
> +				tprintf(" or %s", iop->symbol);
>  		}
>  		ret = ioctl_decode(tcp);
>  	} else {

Please add a case for this to the test, e.g.

--- tests/ioctl.c
+++ tests/ioctl.c
@@ -38,6 +38,7 @@
 	    ioctl(-1, HIDIOCGVERSION, &data) != -1 ||
 	    ioctl(-1, HIDIOCGPHYS(8), &data) != -1 ||
 	    ioctl(-1, EVIOCGBIT(EV_KEY, 8), &data) != -1 ||
+	    ioctl(-1, _IOW('M', 14, int), &data) != -1 ||
 	    ioctl(-1, _IOR(0xde, 0xad, data), &data) != -1)
 		return 77;
 

-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20150923/22a8cbf8/attachment.bin>


More information about the Strace-devel mailing list