2019-06-18 11:52:06

by Puranjay Mohan

[permalink] [raw]
Subject: [PATCH v2] fs: cramfs_fs.h: Fix shifting signed 32-bit value by 31 bits problem

Fix CRAMFS_BLK_FLAG_UNCOMPRESSED to use "U" cast to avoid shifting signed
32-bit value by 31 bits problem. This isn't a problem for kernel builds
with gcc.

This could be problem since this header is part of public API which
could be included for builds using compilers that don't handle this
condition safely resulting in undefined behavior.

Signed-off-by: Puranjay Mohan <[email protected]>
---
V2 - use the unsigned constants for all flags, not just one

include/uapi/linux/cramfs_fs.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/cramfs_fs.h b/include/uapi/linux/cramfs_fs.h
index 6713669aa2ed..71cb602d4198 100644
--- a/include/uapi/linux/cramfs_fs.h
+++ b/include/uapi/linux/cramfs_fs.h
@@ -98,8 +98,8 @@ struct cramfs_super {
*
* That leaves room for 3 flag bits in the block pointer table.
*/
-#define CRAMFS_BLK_FLAG_UNCOMPRESSED (1 << 31)
-#define CRAMFS_BLK_FLAG_DIRECT_PTR (1 << 30)
+#define CRAMFS_BLK_FLAG_UNCOMPRESSED (1U << 31)
+#define CRAMFS_BLK_FLAG_DIRECT_PTR (1U << 30)

#define CRAMFS_BLK_FLAGS ( CRAMFS_BLK_FLAG_UNCOMPRESSED \
| CRAMFS_BLK_FLAG_DIRECT_PTR )
--
2.21.0


2019-06-18 16:09:43

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [Linux-kernel-mentees] [PATCH v2] fs: cramfs_fs.h: Fix shifting signed 32-bit value by 31 bits problem

On Tue, Jun 18, 2019 at 05:19:47PM +0530, Puranjay Mohan wrote:
> Fix CRAMFS_BLK_FLAG_UNCOMPRESSED to use "U" cast to avoid shifting signed
> 32-bit value by 31 bits problem. This isn't a problem for kernel builds
> with gcc.
>
> This could be problem since this header is part of public API which
> could be included for builds using compilers that don't handle this
> condition safely resulting in undefined behavior.
>
> Signed-off-by: Puranjay Mohan <[email protected]>

Reviewed-by: Greg Kroah-Hartman <[email protected]>

You should resend this and cc: Nicolas Pitre <[email protected]> as he is
the cramfs maintainer.

thanks,

greg k-h

2019-06-18 16:16:56

by Shuah Khan

[permalink] [raw]
Subject: Re: [Linux-kernel-mentees] [PATCH v2] fs: cramfs_fs.h: Fix shifting signed 32-bit value by 31 bits problem

On 6/18/19 10:08 AM, Greg KH wrote:
> On Tue, Jun 18, 2019 at 05:19:47PM +0530, Puranjay Mohan wrote:
>> Fix CRAMFS_BLK_FLAG_UNCOMPRESSED to use "U" cast to avoid shifting signed
>> 32-bit value by 31 bits problem. This isn't a problem for kernel builds
>> with gcc.
>>
>> This could be problem since this header is part of public API which
>> could be included for builds using compilers that don't handle this
>> condition safely resulting in undefined behavior.
>>
>> Signed-off-by: Puranjay Mohan <[email protected]>
>
> Reviewed-by: Greg Kroah-Hartman <[email protected]>
>
> You should resend this and cc: Nicolas Pitre <[email protected]> as he is
> the cramfs maintainer.
>

Puranjay! You can add all the Reviewed-by tags when you resend the patch
with Nicolas Pitre <[email protected]> on the thread.


Reviewed-by: Shuah Khan <[email protected]>

thanks,
-- Shuah

2019-06-18 16:40:32

by Puranjay Mohan

[permalink] [raw]
Subject: Re: [Linux-kernel-mentees] [PATCH v2] fs: cramfs_fs.h: Fix shifting signed 32-bit value by 31 bits problem

On Tue, Jun 18, 2019 at 10:15:11AM -0600, Shuah Khan wrote:
> On 6/18/19 10:08 AM, Greg KH wrote:
> > On Tue, Jun 18, 2019 at 05:19:47PM +0530, Puranjay Mohan wrote:
> > > Fix CRAMFS_BLK_FLAG_UNCOMPRESSED to use "U" cast to avoid shifting signed
> > > 32-bit value by 31 bits problem. This isn't a problem for kernel builds
> > > with gcc.
> > >
> > > This could be problem since this header is part of public API which
> > > could be included for builds using compilers that don't handle this
> > > condition safely resulting in undefined behavior.
> > >
> > > Signed-off-by: Puranjay Mohan <[email protected]>
> >
> > Reviewed-by: Greg Kroah-Hartman <[email protected]>
> >
> > You should resend this and cc: Nicolas Pitre <[email protected]> as he is
> > the cramfs maintainer.
> >
>
> Puranjay! You can add all the Reviewed-by tags when you resend the patch
> with Nicolas Pitre <[email protected]> on the thread.
>
>
> Reviewed-by: Shuah Khan <[email protected]>
>
> thanks,
> -- Shuah

Thanks, I have sent the mail with Nicolas Pitre in CC.

--Puranjay