From nobody Fri Dec 19 20:50:53 2025 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-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3Df5e74075e096e757bdbf Tested-by: syzbot Tested-by: Qasim Ijaz Fixes: 388a2a0640e1 ("f2fs: remove redundant sanity check in sanity_check_i= node()") 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, struc= t page *ipage, if (!xnid && !inline_size) return -ENODATA; =20 + if (inline_size < sizeof(struct f2fs_xattr_header) + sizeof(__u32)) + return -ENODATA; + *base_size =3D XATTR_SIZE(inode) + XATTR_PADDING_SIZE; txattr_addr =3D xattr_alloc(F2FS_I_SB(inode), *base_size, is_inline); if (!txattr_addr) --=20 2.39.5