Bug 170510

Summary: Don't warn about ioctl of size 0 without direction hint
Product: [Developer tools] valgrind Reporter: Guillaume Melquiond <guillaume.melquiond>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: wishlist CC: pjfloyd
Priority: NOR    
Version First Reported In: 3.3.1   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Guillaume Melquiond 2008-09-06 08:33:30 UTC
Version:           3.3.1 (using Devel)
OS:                Linux
Installed from:    Compiled sources

Valgrind complains when it encounters an unknown ioctl call without direction hint, even when the buffer size is 0. Strangely enough, it doesn't complain when the user tries to read or write a zero-sized buffer with an unknown ioctl.

The following patch changes the behavior so that Valgrind complains only when there is a buffer but there are no direction hints in the generic ioctl code. It also changes the warning message, which was outdated even before this fix.

(Bear with me, it's the first time I use the kde bugzilla, and I can't find the damn button for uploading an attachment, so I will just paste it below.)

--- syswrap-generic.c.old	2008-09-06 08:11:13.000000000 +0200
+++ syswrap-generic.c	2008-09-06 08:11:58.000000000 +0200
@@ -4155,13 +4155,13 @@
 	  * drivers with a large number of strange ioctl
 	  * commands becomes very tiresome.
 	  */
-      } else if (/* size == 0 || */ dir == _VKI_IOC_NONE) {
+      } else if ((dir == _VKI_IOC_NONE) && size > 0) {
 	 static Int moans = 3;
 	 if (moans > 0 && !VG_(clo_xml)) {
 	    moans--;
 	    VG_(message)(Vg_UserMsg, 
 			 "Warning: noted but unhandled ioctl 0x%x"
-			 " with no size/direction hints",
+			 " with no direction hints",
 			 ARG2); 
 	    VG_(message)(Vg_UserMsg, 
 			 "   This could cause spurious value errors"
Comment 1 Julian Seward 2008-11-06 11:23:46 UTC
Hmm, it's a simple patch but I'm nervous about breaking the
ioctl checking in some way.  Can you supply a couple of 
test cases, one where V should really report an error, and
one where it reports and error without the patch but does
not report the error with the patch?
Comment 2 Paul Floyd 2020-07-01 06:14:35 UTC
Simply running xterm under Valgrind on FreeBSD produces this warning. I haven't tried on Linux. I don't have a genuine error example.

I'm tracking this in parallel here

https://github.com/paulfloyd/freebsd_valgrind/issues/15
Comment 3 Paul Floyd 2022-11-10 21:34:00 UTC
The has been done on FreeBSD for a couple of years and no-one has complained. So pushing this change on all platforms.

To ssh://sourceware.org/git/valgrind.git
   873f37669..f2550057e  master -> master