lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 27 Aug 2019 11:33:19 -0700
From:   Joe Perches <joe@...ches.com>
To:     Geert Uytterhoeven <geert@...ux-m68k.org>,
        Al Viro <viro@...iv.linux.org.uk>,
        Andrew Morton <akpm@...ux-foundation.org>
Cc:     David Laight <David.Laight@...lab.com>,
        Bernard Metzler <bmt@...ich.ibm.com>,
        Doug Ledford <dledford@...hat.com>,
        Jason Gunthorpe <jgg@...pe.ca>,
        linux-rdma <linux-rdma@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] RDMA/siw: Fix compiler warnings on 32-bit due to
 u64/pointer abuse

On Tue, 2019-08-27 at 19:59 +0200, Geert Uytterhoeven wrote:
> On Tue, Aug 27, 2019 at 7:46 PM Al Viro <viro@...iv.linux.org.uk> wrote:
> > On Tue, Aug 27, 2019 at 07:29:52PM +0200, Geert Uytterhoeven wrote:
> > > On Tue, Aug 27, 2019 at 4:17 PM David Laight <David.Laight@...lab.com> wrote:
> > > > From: Geert Uytterhoeven
> > > > > Sent: 19 August 2019 18:15
> > > > ...
> > > > > > I think a cast to unsigned long is rather more common.
> > > > > > 
> > > > > > uintptr_t is used ~1300 times in the kernel.
> > > > > > I believe a cast to unsigned long is much more common.

btw: apparently that's not true.

This grep may be incomplete but it seems there are fewer
kernel uses of a cast to unsigned long then pointer:

$ git grep -P '\(\s*\w+(\s+\w+){0,3}(\s*\*)+\s*\)\s*\(\s*unsigned\s+long\s*\)'|wc -l
423

Maybe add a cast_to_ptr macro like

#define cast_to_ptr(type, val)	((type)(uintptr_t)(val))

though that may not save any horizontal space

and/or a checkpatch test like:
---
 scripts/checkpatch.pl | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 287fe73688f0..4ec88bc53f2f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6281,6 +6281,15 @@ sub process {
 			}
 		}
 
+# check for casts to pointer with intermediate casts to (unsigned long) not (uintptr_t)
+		if ($line =~ /\(\s*\w+(?:\s+\w+){0,3}(?:\s*\*){1,4}\s*\)\s*\(\s*unsigned\s+long\s*\)/) {
+			if (WARN("PREFER_UINTPTR_T",
+				 "prefer intermediate cast to uintptr_t\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(\(\s*\w+(?:\s+\w+){0,3}(?:\s*\*){1,4}\s*\))\s*\(\s*unsigned\s+long\s*\)/$1(uintptr_t)/;
+			}
+		}
+
 # check for pointless casting of alloc functions
 		if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
 			WARN("UNNECESSARY_CASTS",

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ