Skip to content

Commit 820eb59

Browse files
keesbrauner
authored andcommitted
jfs: Use unsigned variable for length calculations
To avoid confusing the compiler about possible negative sizes, switch "ssize" which can never be negative from int to u32. Seen with GCC 13: ../fs/jfs/namei.c: In function 'jfs_symlink': ../include/linux/fortify-string.h:57:33: warning: '__builtin_memcpy' pointer overflow between offset 0 and size [-2147483648, -1] [-Warray-bounds=] 57 | #define __underlying_memcpy __builtin_memcpy | ^ ... ../fs/jfs/namei.c:950:17: note: in expansion of macro 'memcpy' 950 | memcpy(ip->i_link, name, ssize); | ^~~~~~ Cc: Dave Kleikamp <shaggy@kernel.org> Cc: Christian Brauner <brauner@kernel.org> Cc: Dave Chinner <dchinner@redhat.com> Cc: jfs-discussion@lists.sourceforge.net Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Jeff Xu <jeffxu@chromium.org> Message-Id: <20230204183355.never.877-kees@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent ea2b62f commit 820eb59

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

fs/jfs/namei.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ static int jfs_symlink(struct mnt_idmap *idmap, struct inode *dip,
876876
tid_t tid;
877877
ino_t ino = 0;
878878
struct component_name dname;
879-
int ssize; /* source pathname size */
879+
u32 ssize; /* source pathname size */
880880
struct btstack btstack;
881881
struct inode *ip = d_inode(dentry);
882882
s64 xlen = 0;
@@ -957,7 +957,7 @@ static int jfs_symlink(struct mnt_idmap *idmap, struct inode *dip,
957957
if (ssize > sizeof (JFS_IP(ip)->i_inline))
958958
JFS_IP(ip)->mode2 &= ~INLINEEA;
959959

960-
jfs_info("jfs_symlink: fast symlink added ssize:%d name:%s ",
960+
jfs_info("jfs_symlink: fast symlink added ssize:%u name:%s ",
961961
ssize, name);
962962
}
963963
/*
@@ -987,7 +987,7 @@ static int jfs_symlink(struct mnt_idmap *idmap, struct inode *dip,
987987
ip->i_size = ssize - 1;
988988
while (ssize) {
989989
/* This is kind of silly since PATH_MAX == 4K */
990-
int copy_size = min(ssize, PSIZE);
990+
u32 copy_size = min_t(u32, ssize, PSIZE);
991991

992992
mp = get_metapage(ip, xaddr, PSIZE, 1);
993993

0 commit comments

Comments
 (0)