Skip to contentSkip to conversation

fs: cramfs_fs.h: Fix shifting signed 32-bit value by 31 bits problem

PATCH RESEND In review Puranjay Mohan 2 participants 2 messages Jun 18, 2019 – Jun 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 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 <puranjay12 at gmail.com>
Reviewed-by Christoph Hellwig <hch at lst.de>
Reviewed-by Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Reviewed-by Shuah Khan <skhan at linuxfoundation.org>

---
V2 - use the unsigned constants for all flags, not just one RESEND - Added Nicolas Pitre to CC list, added reviewed by tags.

 include/uapi/linux/cramfs_fs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/cramfs_fs.h +2 -2
index 6713669aa2ed..71cb602d4198 100644
@@ -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 )
Signature · 1 line
2.21.0
Acked-by on v2 1/1
#1 lore raw
Quoted 4 lines · Puranjay Mohan

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.

Quoted 8 lines

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 <puranjay12 at gmail.com>
Reviewed-by Christoph Hellwig <hch at lst.de>
Reviewed-by Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Reviewed-by Shuah Khan <skhan at linuxfoundation.org>
Acked-by Nicolas Pitre <nico at fluxnic.net>
Quoted 26 lines

---
V2 - use the unsigned constants for all flags, not just one RESEND - Added Nicolas Pitre to CC list, added reviewed by tags.

 include/uapi/linux/cramfs_fs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/cramfs_fs.h +2 -2
index 6713669aa2ed..71cb602d4198 100644
@@ -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 )
Signature · 1 line
2.21.0