From: David Laight <David.Laight@ACULAB.COM>
To: "'Paul Moore'" <paul@paul-moore.com>,
"Christian Göttsche" <cgzones@googlemail.com>,
"selinux@vger.kernel.org" <selinux@vger.kernel.org>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>,
Eric Paris <eparis@parisplace.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code
Date: Fri, 4 Aug 2023 15:11:49 +0000 [thread overview]
Message-ID: <52329f0195a549d1b7abb3417cb2c225@AcuMS.aculab.com> (raw)
In-Reply-To: <c8f7b16afb26b2357fdc2b590a8cdcba.paul@paul-moore.com>
From: Paul Moore
> Sent: 04 August 2023 03:20
>
> On Jul 28, 2023 =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com> wrote:
....
> > + last_startbit = (u32)-1;
>
> I can't say I'm as current on all of the C standards and compilier
> oddities as some other in the Linux kernel space, but my
> understanding is that on assignment the right value is always
> implicitly type cast to the type of the left variable, is that not
> true? Assuming it is true, I think this explicit cast isn't
> necessary and could actually be harmful if we need to change the
> ebitmap types in the future.
The only question is where any required sign extend happens.
If you do:
u64 val = -1;
then the signed int is first sign extended to 64 bit and then
converted to unsigned (which just copies the bit pattern on any
sane system that Linux might run on).
Whereas:
u64 val = (u32)-1;
Converts an (assumed) 32bit -1 to unsigned and then zero extends it.
What you should really be using is a named constant that is
(for the current implementation) (~0u) and doesn't ever need
any casts and is always unsigned.
If you are actually worried about 'int' being other than 32bits
then there will be a lot more places that need fixing.
But you could use ((u32)~(u32)0) if you really want to allow
for 'u32' being both smaller and larger than 'int' and for
non 2's compliment (eg 1's compliment and sign overpunch)
systems.
(Good luck on finding a working C compiler for either of those.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2023-08-04 15:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 15:54 Christian Göttsche
2023-07-28 15:54 ` [PATCH v2 3/9] selinux: use identical iterator type in hashtab_duplicate() Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 4/9] selinux: avoid implicit conversions in mls code Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 5/9] selinux: services: update type for number of class permissions Christian Göttsche
2023-07-31 1:46 ` Gong Ruiqi
2023-08-04 2:20 ` Paul Moore
2023-08-04 15:21 ` David Laight
2023-07-28 15:54 ` [PATCH v2 6/9] selinux: avoid implicit conversions in services code Christian Göttsche
2023-07-31 2:01 ` Gong Ruiqi
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 7/9] selinux: avoid implicit conversions in selinuxfs code Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 8/9] selinux: policydb: implicit conversions Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:54 ` [PATCH v2 9/9] selinux: avoid implicit conversion in nlmsgtab code Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-07-28 15:55 ` [PATCH v2 1/9] selinux: avoid implicit conversions in avtab code Christian Göttsche
2023-08-04 2:20 ` Paul Moore
2023-08-04 2:20 ` [PATCH v2 2/9] selinux: use u32 as bit type in ebitmap code Paul Moore
2023-08-04 15:11 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52329f0195a549d1b7abb3417cb2c225@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=cgzones@googlemail.com \
--cc=eparis@parisplace.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®