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 CAE6E176AA1; Thu, 12 Dec 2024 17:06:47 +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=1734023207; cv=none; b=kc+QrzNWPYwY4/CCbWpNz24VUyz45c9jnoDr4qCFXteTPk6UtH12aQF0oTH3reP4n7ipG1o845uPG0QCJAhtEbpoVzZWJSbj0q8ZObPVtIMysMH1JuA8hnbj8IgO1oKJSLG/HpvQuqUOki9dTTf9829av9KRCnqkPYsUfxJIeTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734023207; c=relaxed/simple; bh=mtYhSOmw0hNn/bZbQzCCJzdhc25pWBlNuRN6c99FS1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N3ijhznGoPVD6LoO97vznc3sqUHTF0mgftaORn7A6qHa97josaW4akuAXK47eLUr7Roo0KBfmW8b7BjSjaFq4E2L9y04pk6WwFiQp0bDspuc/FjV8C5fBP0ZrnZqYtF7x6OGbk2C80t6i9LfNxzQMrqyvDW9UAqrGMEIxs3xy74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=w8ReUGn1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="w8ReUGn1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03078C4CED3; Thu, 12 Dec 2024 17:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734023207; bh=mtYhSOmw0hNn/bZbQzCCJzdhc25pWBlNuRN6c99FS1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w8ReUGn1fZHhVbruA4amSKvo4SJiOE/dI+LqDg48Zi0kmFNUrjKIL01Ys90UA123W DYm2zI8DvKmrEwFunS6LFVv9HR6ZFN5TEw+9dEl+YCXnI1+xNyRKtQERmIMHMYIKlW LPmmqPgWvllT70jWCo3eOkMeHHYunYEBILDoc36Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ryusuke Konishi , syzbot+96d5d14c47d97015c624@syzkaller.appspotmail.com, Andrew Morton Subject: [PATCH 5.15 459/565] nilfs2: fix potential out-of-bounds memory access in nilfs_find_entry() Date: Thu, 12 Dec 2024 16:00:54 +0100 Message-ID: <20241212144329.871899642@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144311.432886635@linuxfoundation.org> References: <20241212144311.432886635@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ryusuke Konishi commit 985ebec4ab0a28bb5910c3b1481a40fbf7f9e61d upstream. Syzbot reported that when searching for records in a directory where the inode's i_size is corrupted and has a large value, memory access outside the folio/page range may occur, or a use-after-free bug may be detected if KASAN is enabled. This is because nilfs_last_byte(), which is called by nilfs_find_entry() and others to calculate the number of valid bytes of directory data in a page from i_size and the page index, loses the upper 32 bits of the 64-bit size information due to an inappropriate type of local variable to which the i_size value is assigned. This caused a large byte offset value due to underflow in the end address calculation in the calling nilfs_find_entry(), resulting in memory access that exceeds the folio/page size. Fix this issue by changing the type of the local variable causing the bit loss from "unsigned int" to "u64". The return value of nilfs_last_byte() is also of type "unsigned int", but it is truncated so as not to exceed PAGE_SIZE and no bit loss occurs, so no change is required. Link: https://lkml.kernel.org/r/20241119172403.9292-1-konishi.ryusuke@gmail.com Fixes: 2ba466d74ed7 ("nilfs2: directory entry operations") Signed-off-by: Ryusuke Konishi Reported-by: syzbot+96d5d14c47d97015c624@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=96d5d14c47d97015c624 Tested-by: syzbot+96d5d14c47d97015c624@syzkaller.appspotmail.com Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -76,7 +76,7 @@ static inline void nilfs_put_page(struct */ static unsigned int nilfs_last_byte(struct inode *inode, unsigned long page_nr) { - unsigned int last_byte = inode->i_size; + u64 last_byte = inode->i_size; last_byte -= page_nr << PAGE_SHIFT; if (last_byte > PAGE_SIZE)