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 0CB0812BF21; Tue, 30 Apr 2024 10:42:59 +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=1714473779; cv=none; b=mz9qtVwNulLFNvaOkl9sQvxfkJpkFAw3/S0p5l0Bf3E33YMwoX890UdB4zL/amUKq1Ku4V+wRnz3RW3e7ZBQb0J2NOwJZiGC/7pOl+4+wADzsmSRhK0a4qwrXWAbIFq4dwsvtamUQon8ikw8b8cCeoUmJwXnWuaSPsApmUhBaHQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714473779; c=relaxed/simple; bh=CwWatjVT7RuWWLgKdEudEFnQt3CZme1TieN1pfzH9aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I4pztvnXShUvmtXlm3oKdZ86Ev7cNstYBLiGBIYyPyiB+cXbcbNM+fm5/7XGfKscP/0R+TkxnfAXu1tTDA+uwcugbzMdNjAvTEMirsni/E5k7aN+QTffnfiRFgmq/eFdqWEke0GVt5dgqJuA69gb7Ra6Kyo4fHhegNp6NGayIL0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Jdh46bM9; 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="Jdh46bM9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81606C2BBFC; Tue, 30 Apr 2024 10:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714473778; bh=CwWatjVT7RuWWLgKdEudEFnQt3CZme1TieN1pfzH9aU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jdh46bM9HMDy14wnh0XtlcsW4vyGzt0eQL5FYBaWd/A+/1wlKyNngBh5Bp3bVOtEt N5aknrDNWPHhEelgNBSjMSG91O7onWjRUeKDyJbO3/zs7i5HU018C4i8NbG9d9L8El I1slUZTHo5HFpXO2dK7NBXepAD8Hb/C8pRVt6KlE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+2e22057de05b9f3b30d8@syzkaller.appspotmail.com, Jeongjun Park , Ryusuke Konishi , Andrew Morton Subject: [PATCH 4.19 35/77] nilfs2: fix OOB in nilfs_set_de_type Date: Tue, 30 Apr 2024 12:39:14 +0200 Message-ID: <20240430103042.169054782@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103041.111219002@linuxfoundation.org> References: <20240430103041.111219002@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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeongjun Park commit c4a7dc9523b59b3e73fd522c73e95e072f876b16 upstream. The size of the nilfs_type_by_mode array in the fs/nilfs2/dir.c file is defined as "S_IFMT >> S_SHIFT", but the nilfs_set_de_type() function, which uses this array, specifies the index to read from the array in the same way as "(mode & S_IFMT) >> S_SHIFT". static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) { umode_t mode = inode->i_mode; de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; // oob } However, when the index is determined this way, an out-of-bounds (OOB) error occurs by referring to an index that is 1 larger than the array size when the condition "mode & S_IFMT == S_IFMT" is satisfied. Therefore, a patch to resize the nilfs_type_by_mode array should be applied to prevent OOB errors. Link: https://lkml.kernel.org/r/20240415182048.7144-1-konishi.ryusuke@gmail.com Reported-by: syzbot+2e22057de05b9f3b30d8@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=2e22057de05b9f3b30d8 Fixes: 2ba466d74ed7 ("nilfs2: directory entry operations") Signed-off-by: Jeongjun Park Signed-off-by: Ryusuke Konishi Tested-by: Ryusuke Konishi 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 @@ -243,7 +243,7 @@ nilfs_filetype_table[NILFS_FT_MAX] = { #define S_SHIFT 12 static unsigned char -nilfs_type_by_mode[S_IFMT >> S_SHIFT] = { +nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { [S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE, [S_IFDIR >> S_SHIFT] = NILFS_FT_DIR, [S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV,