From nobody Fri Dec 19 21:27:05 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B89BE4A29 for ; Thu, 13 Feb 2025 00:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739406048; cv=none; b=hQ4rFHjurJOFash/LMSQwZViVfN8MV53EBWCV0PP9s4lloevEx6fwUU8I50sgtjIFbK/fyURjoMQcBmCd0OIXC/adZzs5IoUwlTtorkaP2P3fgO/dcwAof9qpiRIyLwyl5t2iVx2MnyqbBic3PEWu7FbCexQbMZS+3rpxbeM31g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739406048; c=relaxed/simple; bh=QiyX/b7o6aoVr7+FLINVljRVt+/cZ0yqMI8VVVXXSbQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=HqIjh9sf095hJ8VZXc35bCq6rsU+e00gRbpgek7d11k2CrnzyvyFaXmWx68nlpWCPmIwKcvpDoQsogSAu0iHCB2tsDPasyK+jhyg05fmRCsPEWrrwranHL569oV49iO5p/KJ4gwoU45spRyNn8LLkUaICl/ZdKmPlT5+HuZE7GE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CRql5tcK; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CRql5tcK" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4395561ab71so3102405e9.2 for ; Wed, 12 Feb 2025 16:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739406045; x=1740010845; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=X84lYtUnaPKcu+sxp9VlxXdEt5jePr1I7AgWIclWzJo=; b=CRql5tcKi81tgFBCK3mK+7Q1ZpwqpftD06KMwUx+0h44WeP/M27NvFO4jHDqiX1NXl GwvC/pxOh+k/dHHMIkvdGrRm+3bgPDSPkt1h05Jh8whNmVmCLAgajyhSYPoI+vWCqr6c kCFbj2+cZKwCKEYZdN7PIvEPxWmFK2J44RO6emhDYZaawBGREq5/LjZNJ7g834zgXrTP 3DVkfm/Zn9gP+CE61NJC+seN6anpvWtY4a55PA3/aRmK6ocixEqtgbiXdkydsxX/VsbO s5gGiDqMsU7inA1MhQY7WCHdlAp03jxMNaahhNi6a4z8oKW3ur+GQxuWTtW60LR2cwyj PNVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739406045; x=1740010845; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X84lYtUnaPKcu+sxp9VlxXdEt5jePr1I7AgWIclWzJo=; b=DU59elUWJjekeozxDGWeTAaIL/9xqerwcMWIbY1kHJtSnS3dWTtzt7rU4+cj2sgbC6 Fu7gJ8IofGCoLeKxi8QnOXNPNIWbztEwj0SuX6mGu4dnFeyIMV8mlF6VQ2bla+CYJMvD aSCHsXG8NzQ4H8T0uYlNb4VTw+hgODSqGNnYdKDC2tWSfGRgRVNb+Uf8WREv/SrKFHyx watvLeG0ih5AQKHjAYkfd52J+uqJ8XYQFHbCCATcK9rOo/m/xGLYP9Ws/u6eCxDV13Lv Xyid/3qfkuq03EF6zIL3nfUQ4v3AY9S21/V4KSs0N4oq9n2hf1VtZ8vTz1GXoPrO38t1 FrIg== X-Forwarded-Encrypted: i=1; AJvYcCVhGvy7wdn/oSQk1k9AlC1N5Xe30iHtrxgcjyDo1lwmTCtur1j6bD+EvuIXEqutDjTC5DYZuvXHbXImxOA=@vger.kernel.org X-Gm-Message-State: AOJu0YxI6lA5ehEQ1niV4SmEUgsMZoT9rWvEJxKP+4pku5BB6fziFj3p hCsIWq6hHZsPOXP3+bE+962ODsU91Zp0UAiggfqPX6vtCHN/cLWL X-Gm-Gg: ASbGncuEmzyq1zmxRlATBTqXzT/HFSRKby3wItRu6JaOpWv1xi1MsVchBsGjq8/EmOO HWAPF3QwBoy05X3tZFlg2XiZyw9aPGE1x2Qi3QfP8yeHrBBauRZ6WjZNQZhwOSYWl6pAZuqxmCs dDCAM0sFPkvjubxALb6enI4RR1gGPm/9sjY6l4CgGWh/KZHk4mW+7ce6LT7ZiqNBMVcPOG3uUwr 7vG25Js344WOWkfJ/aC8AIJngzADMLPrfr82SMA5drb3WmKq6MR/HcJdeukvJxgvs/s1eCqxtyA DkFEHzpbzXcdKjXg X-Google-Smtp-Source: AGHT+IF9zrFLHKVKmPSx9KGxXSoCk0hMnf8jkpOryo17zak+fTnqo0TeSRGwZkokpw4GpxYL4MZ87g== X-Received: by 2002:a5d:588a:0:b0:38f:2073:14a7 with SMTP id ffacd0b85a97d-38f24526be2mr1294596f8f.47.1739406044857; Wed, 12 Feb 2025 16:20:44 -0800 (PST) Received: from qasdev.Home ([2a02:c7c:6696:8300:a5eb:311f:6a00:dedb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f2591570esm332014f8f.59.2025.02.12.16.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2025 16:20:43 -0800 (PST) From: Qasim Ijaz To: shaggy@kernel.org, zhaomengmeng@kylinos.cn, llfamsec@gmail.com, gregkh@linuxfoundation.org, ancowi69@gmail.com Cc: jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot Subject: [PATCH] jfs: fix slab-out-of-bounds read in ea_get() Date: Thu, 13 Feb 2025 00:20:25 +0000 Message-Id: <20250213002025.6602-1-qasdev00@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During the "size_check" label in ea_get(), the code checks if the extended=20 attribute list (xattr) size matches ea_size. If not, it logs=20 "ea_get: invalid extended attribute" and calls print_hex_dump(). Here, EALIST_SIZE(ea_buf->xattr) returns 4110417968, which exceeds=20 INT_MAX (2,147,483,647). Then ea_size is clamped: int size =3D clamp_t(int, ea_size, 0, EALIST_SIZE(ea_buf->xattr)); Although clamp_t aims to bound ea_size between 0 and 4110417968, the upper=20 limit is treated as an int, causing an overflow above 2^31 - 1. This leads=20 "size" to wrap around and become negative (-184549328). The "size" is then passed to print_hex_dump() (called "len" in=20 print_hex_dump()), it is passed as type size_t (an unsigned=20 type), this is then stored inside a variable called=20 "int remaining", which is then assigned to "int linelen" which=20 is then passed to hex_dump_to_buffer(). In print_hex_dump()=20 the for loop, iterates through 0 to len-1, where len is=20 18446744073525002176, calling hex_dump_to_buffer()=20 on each iteration: for (i =3D 0; i < len; i +=3D rowsize) { linelen =3D min(remaining, rowsize); remaining -=3D rowsize; hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, linebuf, sizeof(linebuf), ascii); =09 ... } =09 The expected stopping condition (i < len) is effectively broken=20 since len is corrupted and very large. This eventually leads to=20 the "ptr+i" being passed to hex_dump_to_buffer() to get closer=20 to the end of the actual bounds of "ptr", eventually an out of=20 bounds access is done in hex_dump_to_buffer() in the following=20 for loop: for (j =3D 0; j < len; j++) { if (linebuflen < lx + 2) goto overflow2; ch =3D ptr[j]; ... } To fix this we should validate "EALIST_SIZE(ea_buf->xattr)"=20 before it is utilised. Reported-by: syzbot Tested-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=3D4e6e7e4279d046613bc5 Fixes: d9f9d96136cb ("jfs: xattr: check invalid xattr size more strictly") Signed-off-by: Qasim Ijaz --- fs/jfs/xattr.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c index 24afbae87225..7575c51cce9b 100644 --- a/fs/jfs/xattr.c +++ b/fs/jfs/xattr.c @@ -559,11 +555,16 @@ static int ea_get(struct inode *inode, struct ea_buff= er *ea_buf, int min_size) =20 size_check: if (EALIST_SIZE(ea_buf->xattr) !=3D ea_size) { - int size =3D 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, - ea_buf->xattr, size, 1); + if (unlikely(EALIST_SIZE(ea_buf->xattr) > INT_MAX)) { + printk(KERN_ERR "ea_get: extended attribute size too large: %u > INT_MA= X\n", + EALIST_SIZE(ea_buf->xattr)); + } else { + int size =3D 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, + ea_buf->xattr, size, 1); + } ea_release(inode, ea_buf); rc =3D -EIO; goto clean_up; --=20 2.39.5