]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: add a bunch of missing ceph_path_info initializers
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 24 Feb 2026 13:10:29 +0000 (14:10 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 9 Mar 2026 11:34:40 +0000 (12:34 +0100)
ceph_mdsc_build_path() must be called with a zero-initialized
ceph_path_info parameter, or else the following
ceph_mdsc_free_path_info() may crash.

Example crash (on Linux 6.18.12):

  virt_to_cache: Object is not a Slab page!
  WARNING: CPU: 184 PID: 2871736 at mm/slub.c:6732 kmem_cache_free+0x316/0x400
  [...]
  Call Trace:
   [...]
   ceph_open+0x13d/0x3e0
   do_dentry_open+0x134/0x480
   vfs_open+0x2a/0xe0
   path_openat+0x9a3/0x1160
  [...]
  cache_from_obj: Wrong slab cache. names_cache but object is from ceph_inode_info
  WARNING: CPU: 184 PID: 2871736 at mm/slub.c:6746 kmem_cache_free+0x2dd/0x400
  [...]
  kernel BUG at mm/slub.c:634!
  Oops: invalid opcode: 0000 [#1] SMP NOPTI
  RIP: 0010:__slab_free+0x1a4/0x350

Some of the ceph_mdsc_build_path() callers had initializers, but
others had not, even though they were all added by commit 15f519e9f883
("ceph: fix race condition validating r_parent before applying state").
The ones without initializer are suspectible to random crashes.  (I can
imagine it could even be possible to exploit this bug to elevate
privileges.)

Unfortunately, these Ceph functions are undocumented and its semantics
can only be derived from the code.  I see that ceph_mdsc_build_path()
initializes the structure only on success, but not on error.

Calling ceph_mdsc_free_path_info() after a failed
ceph_mdsc_build_path() call does not even make sense, but that's what
all callers do, and for it to be safe, the structure must be
zero-initialized.  The least intrusive approach to fix this is
therefore to add initializers everywhere.

Cc: stable@vger.kernel.org
Fixes: 15f519e9f883 ("ceph: fix race condition validating r_parent before applying state")
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/debugfs.c
fs/ceph/dir.c
fs/ceph/file.c
fs/ceph/inode.c

index f3fe786b4143d4bd7a24ed33351c8c9059a8112d..7dc3077902401ed00c7f2e353d7f948964f7d65d 100644 (file)
@@ -79,7 +79,7 @@ static int mdsc_show(struct seq_file *s, void *p)
                if (req->r_inode) {
                        seq_printf(s, " #%llx", ceph_ino(req->r_inode));
                } else if (req->r_dentry) {
-                       struct ceph_path_info path_info;
+                       struct ceph_path_info path_info = {0};
                        path = ceph_mdsc_build_path(mdsc, req->r_dentry, &path_info, 0);
                        if (IS_ERR(path))
                                path = NULL;
@@ -98,7 +98,7 @@ static int mdsc_show(struct seq_file *s, void *p)
                }
 
                if (req->r_old_dentry) {
-                       struct ceph_path_info path_info;
+                       struct ceph_path_info path_info = {0};
                        path = ceph_mdsc_build_path(mdsc, req->r_old_dentry, &path_info, 0);
                        if (IS_ERR(path))
                                path = NULL;
index 415db39a56d808f4cc083404740e2592f3235b8c..bac9cfb6b982f23a457b12cf81e1f96b673d5281 100644 (file)
@@ -1364,7 +1364,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
        if (!dn) {
                try_async = false;
        } else {
-               struct ceph_path_info path_info;
+               struct ceph_path_info path_info = {0};
                path = ceph_mdsc_build_path(mdsc, dn, &path_info, 0);
                if (IS_ERR(path)) {
                        try_async = false;
index 66bbf6d517a99b93763e94659b3dafb7de7c86f6..5e7c73a29aa3e94f86689e8f7d454669805883c5 100644 (file)
@@ -397,7 +397,7 @@ int ceph_open(struct inode *inode, struct file *file)
        if (!dentry) {
                do_sync = true;
        } else {
-               struct ceph_path_info path_info;
+               struct ceph_path_info path_info = {0};
                path = ceph_mdsc_build_path(mdsc, dentry, &path_info, 0);
                if (IS_ERR(path)) {
                        do_sync = true;
@@ -807,7 +807,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
        if (!dn) {
                try_async = false;
        } else {
-               struct ceph_path_info path_info;
+               struct ceph_path_info path_info = {0};
                path = ceph_mdsc_build_path(mdsc, dn, &path_info, 0);
                if (IS_ERR(path)) {
                        try_async = false;
index d76f9a79dc0c244cdbf790e998753b662e64d966..d99e12d1100b172e6353a2a42472de32157acc7b 100644 (file)
@@ -2551,7 +2551,7 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode,
        if (!dentry) {
                do_sync = true;
        } else {
-               struct ceph_path_info path_info;
+               struct ceph_path_info path_info = {0};
                path = ceph_mdsc_build_path(mdsc, dentry, &path_info, 0);
                if (IS_ERR(path)) {
                        do_sync = true;