public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] jfs: xattr: check invalid xattr size more strictly
@ 2024-10-05 10:06 Artem Sadovnikov
  2024-10-29 22:18 ` Dave Kleikamp
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Sadovnikov @ 2024-10-05 10:06 UTC (permalink / raw)
  To: Dave Kleikamp
  Cc: Artem Sadovnikov, Christian Brauner, Greg Kroah-Hartman,
	jfs-discussion, linux-kernel, lvc-project, stable

Commit 7c55b78818cf ("jfs: xattr: fix buffer overflow for invalid xattr")
also addresses this issue but it only fixes it for positive values, while
ea_size is an integer type and can take negative values, e.g. in case of
a corrupted filesystem. This still breaks validation and would overflow
because of implicit conversion from int to size_t in print_hex_dump().

Fix this issue by clamping the ea_size value instead.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Cc: stable@vger.kernel.org
Signed-off-by: Artem Sadovnikov <ancowi69@gmail.com>
---
 fs/jfs/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 8ef8dfc3c194..95bcbbf7359c 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -557,7 +557,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
 
       size_check:
 	if (EALIST_SIZE(ea_buf->xattr) != ea_size) {
-		int size = min_t(int, EALIST_SIZE(ea_buf->xattr), ea_size);
+		int size = clamp_t(int, ea_size, 0, EALIST_SIZE(ea_buf->xattr));
 
 		printk(KERN_ERR "ea_get: invalid extended attribute\n");
 		print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1,
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] jfs: xattr: check invalid xattr size more strictly
  2024-10-05 10:06 [PATCH] jfs: xattr: check invalid xattr size more strictly Artem Sadovnikov
@ 2024-10-29 22:18 ` Dave Kleikamp
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Kleikamp @ 2024-10-29 22:18 UTC (permalink / raw)
  To: Artem Sadovnikov
  Cc: Christian Brauner, Greg Kroah-Hartman, jfs-discussion,
	linux-kernel, lvc-project, stable

On 10/5/24 5:06AM, Artem Sadovnikov wrote:
> Commit 7c55b78818cf ("jfs: xattr: fix buffer overflow for invalid xattr")
> also addresses this issue but it only fixes it for positive values, while
> ea_size is an integer type and can take negative values, e.g. in case of
> a corrupted filesystem. This still breaks validation and would overflow
> because of implicit conversion from int to size_t in print_hex_dump().
> 
> Fix this issue by clamping the ea_size value instead.
> 
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Artem Sadovnikov <ancowi69@gmail.com>

Looks good. I'll apply this one.

Shaggy
> ---
>   fs/jfs/xattr.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
> index 8ef8dfc3c194..95bcbbf7359c 100644
> --- a/fs/jfs/xattr.c
> +++ b/fs/jfs/xattr.c
> @@ -557,7 +557,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
>   
>         size_check:
>   	if (EALIST_SIZE(ea_buf->xattr) != ea_size) {
> -		int size = min_t(int, EALIST_SIZE(ea_buf->xattr), ea_size);
> +		int size = clamp_t(int, ea_size, 0, EALIST_SIZE(ea_buf->xattr));
>   
>   		printk(KERN_ERR "ea_get: invalid extended attribute\n");
>   		print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-29 22:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-05 10:06 [PATCH] jfs: xattr: check invalid xattr size more strictly Artem Sadovnikov
2024-10-29 22:18 ` Dave Kleikamp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox