[Devel] [PATCH RHEL7 COMMIT] ms/fs: fix undefined behavior in bit shift for SB_NOUSER
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Mar 29 20:54:02 MSK 2024
The commit is pushed to "branch-rh7-3.10.0-1160.108.1.vz7.221.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.108.1.vz7.221.2
------>
commit 489476409bfc74da4d0353ddb1fe0d35b7868d5c
Author: Hao Ge <gehao at kylinos.cn>
Date: Mon Apr 24 13:18:35 2023 +0800
ms/fs: fix undefined behavior in bit shift for SB_NOUSER
Shifting signed 32-bit value by 31 bits is undefined, so changing
significant bit to unsigned. It was spotted by UBSAN.
So let's just fix this by using the BIT() helper for all SB_* flags.
mFixes: e462ec50cb5f ("VFS: Differentiate mount flags (MS_*) from internal superblock flags")
Signed-off-by: Hao Ge <gehao at kylinos.cn>
Message-Id: <20230424051835.374204-1-gehao at kylinos.cn>
[brauner at kernel.org: use BIT() for all SB_* flags]
Signed-off-by: Christian Brauner <brauner at kernel.org>
Backport notes:
* 27th bit: SB_FORCE in ms, SB_NOREMOTELOCK in vz7 kernel
* dropped 17th bit: SB_INLINECRYPT
https://virtuozzo.atlassian.net/browse/PSBM-153598
(cherry picked from commit f15afbd34d8fadbd375f1212e97837e32bc170cc)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
include/linux/fs.h | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b36ed59f6072..deddfe8fd62b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1539,28 +1539,28 @@ struct mm_struct;
* sb->s_flags. Note that these mirror the equivalent MS_* flags where
* represented in both.
*/
-#define SB_RDONLY 1 /* Mount read-only */
-#define SB_NOSUID 2 /* Ignore suid and sgid bits */
-#define SB_NODEV 4 /* Disallow access to device special files */
-#define SB_NOEXEC 8 /* Disallow program execution */
-#define SB_SYNCHRONOUS 16 /* Writes are synced at once */
-#define SB_MANDLOCK 64 /* Allow mandatory locks on an FS */
-#define SB_DIRSYNC 128 /* Directory modifications are synchronous */
-#define SB_NOATIME 1024 /* Do not update access times. */
-#define SB_NODIRATIME 2048 /* Do not update directory access times */
-#define SB_SILENT 32768
-#define SB_POSIXACL (1<<16) /* VFS does not apply the umask */
-#define SB_KERNMOUNT (1<<22) /* this is a kern_mount call */
-#define SB_I_VERSION (1<<23) /* Update inode I_version field */
-#define SB_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
+#define SB_RDONLY BIT(0) /* Mount read-only */
+#define SB_NOSUID BIT(1) /* Ignore suid and sgid bits */
+#define SB_NODEV BIT(2) /* Disallow access to device special files */
+#define SB_NOEXEC BIT(3) /* Disallow program execution */
+#define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */
+#define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */
+#define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */
+#define SB_NOATIME BIT(10) /* Do not update access times. */
+#define SB_NODIRATIME BIT(11) /* Do not update directory access times */
+#define SB_SILENT BIT(15)
+#define SB_POSIXACL BIT(16) /* VFS does not apply the umask */
+#define SB_KERNMOUNT BIT(22) /* this is a kern_mount call */
+#define SB_I_VERSION BIT(23) /* Update inode I_version field */
+#define SB_LAZYTIME BIT(25) /* Update the on-disk [acm]times lazily */
/* These sb flags are internal to the kernel */
-#define SB_SUBMOUNT (1<<26)
-#define SB_NOREMOTELOCK (1<<27)
-#define SB_NOSEC (1<<28)
-#define SB_BORN (1<<29)
-#define SB_ACTIVE (1<<30)
-#define SB_NOUSER (1<<31)
+#define SB_SUBMOUNT BIT(26)
+#define SB_NOREMOTELOCK BIT(27)
+#define SB_NOSEC BIT(28)
+#define SB_BORN BIT(29)
+#define SB_ACTIVE BIT(30)
+#define SB_NOUSER BIT(31)
/*
* Umount options
More information about the Devel
mailing list