From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3711DE77198 for ; Tue, 7 Jan 2025 23:06:20 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tVIeO-0006kf-Pk; Tue, 07 Jan 2025 23:06:16 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tVIeI-0006kU-CL for linux-f2fs-devel@lists.sourceforge.net; Tue, 07 Jan 2025 23:06:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=aouLblihd9vge8sY+NmimzZq/5 qBzJmEIf/TKxReTJ3PGgp70k6x539WoHhp6fCtwKXf/z9oI++I9h4O7hMOuKQ0PHplCVVaseauuKL OtUCPPh9KbQCGt2dE5Kczh7v9aURlm86TldXQYHWiRLLM8LqLAod4OhacM57SKWx2cDU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Subject:Cc:To:From:Date:Sender: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=l s3TsitcLnor418UdM0jRsF76BkAy7b/vDnlE+CJSzoXhAYfLITbQKvQDoPeXqmPMd9I1yLfPa+sje wh9cd5lNUV0gswjYXpqp9Yn35a3Chdy1gPGm2oF3sG7Uoo+o9RBULPOSMIGPRklcMJph7dpR3afBH 9rE8zbTlGIDovUgs=; Received: from mail-wm1-f47.google.com ([209.85.128.47]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tVIeH-0004si-NN for linux-f2fs-devel@lists.sourceforge.net; Tue, 07 Jan 2025 23:06:10 +0000 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4362bae4d7dso115557845e9.1 for ; Tue, 07 Jan 2025 15:06:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736291158; x=1736895958; darn=lists.sourceforge.net; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=LW5Bx0UbOoBd9YzA7XIAuCL8VAfhgN6hGwYSohRp6dhi+/Nst6M4YY6l9xKw8qdzGA cdJONc24qR3NDV2jzj/ZuxOT45kywACFuIM/LeYFzdl4tpGi6RjmY7+Eo5dGjksJBrtE xZqgyJM/M6fB5p5+X8EPLkYOhldHL4MIKZBhnNWWq6Zlc9CRjPxjOV8fnYmY3kpUzFxZ V8UuPUYAp4+xqcnaZ3yrbuX1RnNdAmUIApE6QwWnHfRzsRznP0IEa7FmbvPX+o75hd+P qVp4b+me2SLFO6UPaTP7JcYhehPCWMUL2AxVhKucHKMB1uAQ34sc7PaLjiKDoGwX1KpL o5fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736291158; x=1736895958; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=uKo/zZiOI46K99Jj0k7l8xIdgBcPfPYHIp2PEDFZhOf9MAtvN5a9BewPQKDSlvYpuA 58b7WF+PanhFEJnrq7VMLLqkvHpO1uLTTtWqWCWcwbFZoODqXchp2aBzqvguScQPBIY6 uYtGRmxx1G/nu6XR+ybr9qeCHDzGkuFCf3xxt1gX/wQbMMICu0HZ3ecVHNjRmOXjSnBD XaWSzu2N1eQbDuaTRkhhiVa7laVJg0OhtigM1Rnm7q+ec2R4Hd/0BTmxV030MrtDCiHC VfihgxopUWGqVZYV2DYdkO5LViyFI9bZTttJZtUAv94MlSuHhCJKIp1KBgPkWqaaPIEj cnYw== X-Gm-Message-State: AOJu0Ywb6pKfwU272ueSjLz3RM2CeEwNStuAcoXkEk/GM4+pv6eXzQqI F43ycBrmvP+hE1yXKIhmB6FQh6PfzFwB7smdGbC4zKtB1+2Ci3hr X-Gm-Gg: ASbGncv5kMfdAKmN8bJpEaJGapwoN9Qm3T90Me0uNrBaROYFqBd7A+3smErHgiJQhc4 k2fkv6ADPQjBOZtcgX9a3kRF/rTvRoHwP05/sbukfYtmFfL/JUX+IfC1PHiElFov3+hoPhIWjdK aWwXpAzjSngRh/d6s7JBm35jDC6ALmyv3a0Shjn4k7B9lqcOZNm1mn/MBu7kIeXK9SywFRwXiKV LNp/zMIJ0YC9/zkxqyIS1lJQ2y1m+SsNfzFRdYawRyMOqFp4cP6/kl7Q+KX X-Google-Smtp-Source: AGHT+IFGCe0C20Fo0avw1jLEwAvhWq8rItDlf3GJUdm69RUiJxtO3tf5B2yb75utz9xvlX4+Jtq+dw== X-Received: by 2002:a05:600c:4510:b0:434:f3a1:b210 with SMTP id 5b1f17b1804b1-436e27076bcmr2361305e9.32.1736291157873; Tue, 07 Jan 2025 15:05:57 -0800 (PST) Received: from qasdev.system ([2a02:c7c:6696:8300:bdab:f479:c8fc:cd3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8292f4sm52311645f8f.3.2025.01.07.15.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 15:05:57 -0800 (PST) Date: Tue, 7 Jan 2025 23:03:50 +0000 From: qasdev To: Jaegeuk Kim , Chao Yu Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Headers-End: 1tVIeH-0004si-NN Subject: [f2fs-dev] [PATCH] f2fs: Fix slab-out-of-bounds Read KASAN bug in f2fs_getxattr() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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. 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) -- 2.39.5 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 EA4FB1DE4CA for ; Tue, 7 Jan 2025 23:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736291161; cv=none; b=S5xQNSyb0rLdl2cjBO0In9kV4TID+Li8KnnN5SQh44spwDsAUtvyv5Ng0ziVyHywN2JkJ6hpiZHFq4dE4enrSAgFHYHFHjh0/p0n7pbMWONNTKWZ5jEGDyLQy7/73oqKtAA06cBg16x436mzmJbaaQ7B0TmwMn9tvfqgG1shzHA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736291161; c=relaxed/simple; bh=OV3nfOFlWQk0kXDPHlLZRfmuYGF7D7BO7eSQ40kVTlU=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=n+MgbXOmwGIIA0cSohMGsFD4uYBrZw+QJUyNSswwZPeS8WFvPbefiSbaM41CbcXQbL1Y1QKrodpwSL31Wde5e8qPzuUROKjZhQclHW4WhQHHM3gQMjxPLHUpg9IkI56V9Sx1sfyUy65fgRL7MRvjm54g1RgTWlYCUKX0QDPHM+M= 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=IRTgDL90; arc=none smtp.client-ip=209.85.128.44 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="IRTgDL90" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43634b570c1so115629005e9.0 for ; Tue, 07 Jan 2025 15:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736291158; x=1736895958; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=IRTgDL90zPJ5+eXal1gRGDoDLJKmqsxGVP6WAkShWw8HQpRkhjavnNBiljKRHyz/KM h9HaoNp2Ztz+dOl9Mxv7TE5Qt5sOdDz6GBKvGsIaUJYklC3dBBTY6/BFWGksvH42Mdmv IJKWsVn1WVCQn51LH562B3RRqGyZoAQTp2uDjZICf8bcaCGwWVeRbfbheUJvLkdefvSk yYvqDH+Y+thbxIPGpY4Y7yzr2yAXWJzYwADFi0a0EegHHwA+KCfaV8X8r36oyzXxoZb7 GNLLh9o8HLPujYpRNJ8QPVM0lvuY+ue4DgxezjUn1AmnSlL3JXi8HhFitMwNUYJWU+VS Yc2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736291158; x=1736895958; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XPemyXbGyvV6+ScDDFDykFExz4MulQ9KtjAgrvdBziM=; b=Sy5vnYpunhG0Cm1gDPZ6/vZx5db2KQNQgpLE8wCfEX283xd4pBgW1AlsVO+QGufaV3 oMgOTo4akjn4wbnQdthMF8lmT/g7T+7uaGfsqP2cvHSQhMZUaVYI1lB8EAoapE4jDg0n GaKKtOmf5OF3PBFygYUu/eHOCWECR7WnDhfeSZoDvcllkBNZ3SaSJXH/1hyvVkjU07cg te71vKfAE25tjR0IXiz5VIIV4l+Oz45oJ1+vfVXiUwf2fXmDqwa9uNL4LhcK2bN0KYZj fcatX+uzQqoP0xpppD7aNj/Sw/byK+vZGnH8rhW+icwdj2XbuU/2KbKu0m9RuevOGkdI 1pgg== X-Forwarded-Encrypted: i=1; AJvYcCWzMHFCqlXIG67V6sFybjjlcrObPsNTab2mpqwGowpP5LmIilyW7rucmJTJU/CSOu78NHe/EvNwkBz1Pvk=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7fhzDMWuMF9hF/SWlQ/fYVqKYT+S4K4HjwfDmYW7KO5mtN8Dp 0eOM3Vn5kBxVBH+O8GYvrjaA+nd46Hk2kdwY89dEUoCHmV7u4SMcOL2Oog== X-Gm-Gg: ASbGnctDUh8YWkawm0CWEBGuydh58X+QFDDuPSOMN2QPc+6J5mT5o4BgwAlHGyRd8Gp uSCmRh/CJ88hTNnwBott+PCXCwmwoBi2N66ikZO0AfalYny2T2NM+zDSwAQpjX8N/TJvVAwBlMP R7p+xwMSH0DAQRe9uipZG+zFx8kZheq9MXJMKvmcHhecMcFYNr67HkFjhitf9NpjkCT63SbZS+b +2yrlWV0+MeuFuMOonhlO3fxIpL1QuDkUQc2PGTXnY90+iQmrPiz3mZGYTX X-Google-Smtp-Source: AGHT+IFGCe0C20Fo0avw1jLEwAvhWq8rItDlf3GJUdm69RUiJxtO3tf5B2yb75utz9xvlX4+Jtq+dw== X-Received: by 2002:a05:600c:4510:b0:434:f3a1:b210 with SMTP id 5b1f17b1804b1-436e27076bcmr2361305e9.32.1736291157873; Tue, 07 Jan 2025 15:05:57 -0800 (PST) Received: from qasdev.system ([2a02:c7c:6696:8300:bdab:f479:c8fc:cd3b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8292f4sm52311645f8f.3.2025.01.07.15.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 15:05:57 -0800 (PST) Date: Tue, 7 Jan 2025 23:03:50 +0000 From: qasdev To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: Fix slab-out-of-bounds Read KASAN bug in f2fs_getxattr() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. 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) -- 2.39.5