Patch "nilfs2: avoid undefined behavior in nilfs_cnt32_ge macro" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    nilfs2: avoid undefined behavior in nilfs_cnt32_ge macro

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     nilfs2-avoid-undefined-behavior-in-nilfs_cnt32_ge-ma.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit a2bd13c8be52b9375a85e47dbf9955d26bece3c6
Author: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx>
Date:   Wed Jul 3 03:35:12 2024 +0900

    nilfs2: avoid undefined behavior in nilfs_cnt32_ge macro
    
    [ Upstream commit 0f3819e8c483771a59cf9d3190cd68a7a990083c ]
    
    According to the C standard 3.4.3p3, the result of signed integer overflow
    is undefined.  The macro nilfs_cnt32_ge(), which compares two sequence
    numbers, uses signed integer subtraction that can overflow, and therefore
    the result of the calculation may differ from what is expected due to
    undefined behavior in different environments.
    
    Similar to an earlier change to the jiffies-related comparison macros in
    commit 5a581b367b5d ("jiffies: Avoid undefined behavior from signed
    overflow"), avoid this potential issue by changing the definition of the
    macro to perform the subtraction as unsigned integers, then cast the
    result to a signed integer for comparison.
    
    Link: https://lkml.kernel.org/r/20130727225828.GA11864@xxxxxxxxxxxxxxxxxx
    Link: https://lkml.kernel.org/r/20240702183512.6390-1-konishi.ryusuke@xxxxxxxxx
    Fixes: 9ff05123e3bf ("nilfs2: segment constructor")
    Signed-off-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 440e628f9d4fc..c90435e8e7489 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -136,7 +136,7 @@ static void nilfs_dispose_list(struct the_nilfs *, struct list_head *, int);
 
 #define nilfs_cnt32_ge(a, b)   \
 	(typecheck(__u32, a) && typecheck(__u32, b) && \
-	 ((__s32)(a) - (__s32)(b) >= 0))
+	 ((__s32)((a) - (b)) >= 0))
 
 static int nilfs_prepare_segment_lock(struct super_block *sb,
 				      struct nilfs_transaction_info *ti)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux