android_kernel_motorola_sm6375/fs/overlayfs
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Kees Cook 094353c10f ovl: Check for NULL d_inode() in ovl_dentry_upper()
[ Upstream commit 8a39f1c870e9d6fbac5638f3a42a6a6363829c49 ]

In ovl_path_type() and ovl_is_metacopy_dentry() GCC notices that it is
possible for OVL_E() to return NULL (which implies that d_inode(dentry)
may be NULL). This would result in out of bounds reads via container_of(),
seen with GCC 15's -Warray-bounds -fdiagnostics-details. For example:

In file included from arch/x86/include/generated/asm/rwonce.h:1,
                 from include/linux/compiler.h:339,
                 from include/linux/export.h:5,
                 from include/linux/linkage.h:7,
                 from include/linux/fs.h:5,
                 from fs/overlayfs/util.c:7:
In function 'ovl_upperdentry_dereference',
    inlined from 'ovl_dentry_upper' at ../fs/overlayfs/util.c:305:9,
    inlined from 'ovl_path_type' at ../fs/overlayfs/util.c:216:6:
include/asm-generic/rwonce.h:44:26: error: array subscript 0 is outside array bounds of 'struct inode[7486503276667837]' [-Werror=array-bounds=]
   44 | #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:50:9: note: in expansion of macro '__READ_ONCE'
   50 |         __READ_ONCE(x);                                                 \
      |         ^~~~~~~~~~~
fs/overlayfs/ovl_entry.h:195:16: note: in expansion of macro 'READ_ONCE'
  195 |         return READ_ONCE(oi->__upperdentry);
      |                ^~~~~~~~~
  'ovl_path_type': event 1
  185 |         return inode ? OVL_I(inode)->oe : NULL;
  'ovl_path_type': event 2

Avoid this by allowing ovl_dentry_upper() to return NULL if d_inode() is
NULL, as that means the problematic dereferencing can never be reached.
Note that this fixes the over-eager compiler warning in an effort to
being able to enable -Warray-bounds globally. There is no known
behavioral bug here.

Suggested-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-07-17 18:24:51 +02:00
..
copy_up.c overlayfs: set ctime when setting mtime and atime 2023-10-25 11:53:23 +02:00
dir.c ovl: Use ovl mounter's fsuid and fsgid in ovl_link() 2023-01-18 11:41:43 +01:00
export.c ovl: drop WARN_ON() dentry is NULL in ovl_encode_fh() 2022-08-25 11:17:23 +02:00
file.c
inode.c
Kconfig
Makefile
namei.c new helper: lookup_positive_unlocked() 2023-09-23 10:59:40 +02:00
overlayfs.h ovl: fix warning in ovl_create_real() 2021-12-22 09:29:40 +01:00
ovl_entry.h ovl: check type and offset of struct vfsmount in ovl_entry 2023-08-30 16:27:09 +02:00
readdir.c
super.c ovl: skip overlayfs superblocks at global sync 2023-12-08 08:44:27 +01:00
util.c ovl: Check for NULL d_inode() in ovl_dentry_upper() 2025-07-17 18:24:51 +02:00