From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 703D91DE895 for ; Wed, 8 Jan 2025 11:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336650; cv=none; b=bI/hMoJpR1OtbAAlL+YQ/z0P6L/Z5Rr3wF48vsIlMFOgfjelCkUcOVRrumbrEEvP0gMvsU/78cbdJn6HpbnGsuD1w0eL12G8ELd2WOEZc5o1DVD8r/IXDzqFFV5lY02VeevXnaRTvtFg8T0uijufydG0l2EkaYfuwU2cROUN+qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336650; c=relaxed/simple; bh=vZUZXlQtqy6x5JVkmRBxdMYe9T7dmpB5GPXALnouEFA=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=jcqU8OuABefk8etdZbp0ktRMTI+EaOKoXL/B68LVg0cdF3sDwn9XYoBzAk60pEW5EQGdZYv8Lfe31GWWKkBvBwi1vUA7vFVVCynaKHhwvIl33op7qGx6XlTCewZf97Xx1G44id9WJyAl0RCLrLCASxCkiko0JOWU6vgDtI0mXtA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P+Rrl0s0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P+Rrl0s0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB519C4CEDD; Wed, 8 Jan 2025 11:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736336650; bh=vZUZXlQtqy6x5JVkmRBxdMYe9T7dmpB5GPXALnouEFA=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=P+Rrl0s0c7KzGL7Qq7Svr/iviU19HK3beanbc/sDlacnxanEyudoZfKGHIYNSMFUq rH4Vccczta0EovNCWWvlcC80vwmFm1IiuPGEPJMo2kFcA35ULV00Qy3rGNlAZ5nEwZ dexjcVeTiRjLp1Id5WAz6aldOo1/r6m7PZhnpTv/4K3dkNR3aMQFZE/SMVD8B8UOtz NbDAqGavhptS0hnvdpmhcfhr/FTVCD6Dc5TSSCg2j3g4PBxjlEco1uAAl8XxIs7XUX 2KuGHN+GpTXEytk2U9CfwDFjcrymbiyPHwXV8d7rFCZhNgx4UR0BD5lgocdUTL4PlN 6JobIGpIR+h+g== Message-ID: <60ec8f56-5d00-426a-978d-a31894262705@kernel.org> Date: Wed, 8 Jan 2025 19:44:03 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] f2fs: Fix slab-out-of-bounds Read KASAN bug in f2fs_getxattr() To: qasdev , Jaegeuk Kim References: Content-Language: en-US From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Qasim, On 2025/1/8 07:03, qasdev wrote: > In f2fs_getxattr(), the function lookup_all_xattrs() allocates a 12-byte > (base_size) buffer for an inline extended attribute. However, when > __find_inline_xattr() calls __find_xattr(), it uses the macro > "list_for_each_xattr(entry, addr)", which starts by calling > XATTR_FIRST_ENTRY(addr). This skips a 24-byte struct f2fs_xattr_header > at the beginning of the buffer, causing an immediate out-of-bounds read > in a 12-byte allocation. The subsequent !IS_XATTR_LAST_ENTRY(entry) > check then dereferences memory outside the allocated region, triggering > the slab-out-of bounds read. > > This patch prevents the out-of-bounds read by adding a check to bail > out early if inline_size is too small and does not account for the > header plus the 4-byte value that IS_XATTR_LAST_ENTRY reads. Thank you very much for analyzing this issue, the root cause you figured out makes sense to me. Can you please check the patch in below link? It seems it can fix this issue as well? IIUC. https://lore.kernel.org/linux-f2fs-devel/20241216134600.8308-1-chao@kernel.org/ Thanks, > > Reported-by: syzbot > Closes: https://syzkaller.appspot.com/bug?extid=f5e74075e096e757bdbf > Tested-by: syzbot > Tested-by: Qasim Ijaz > Fixes: 388a2a0640e1 ("f2fs: remove redundant sanity check in sanity_check_inode()") > Signed-off-by: Qasim Ijaz > --- > fs/f2fs/xattr.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c > index 3f3874943679..cf82646bca0e 100644 > --- a/fs/f2fs/xattr.c > +++ b/fs/f2fs/xattr.c > @@ -329,6 +329,9 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, > if (!xnid && !inline_size) > return -ENODATA; > > + if (inline_size < sizeof(struct f2fs_xattr_header) + sizeof(__u32)) > + return -ENODATA; > + > *base_size = XATTR_SIZE(inode) + XATTR_PADDING_SIZE; > txattr_addr = xattr_alloc(F2FS_I_SB(inode), *base_size, is_inline); > if (!txattr_addr)