Skip to content

Commit 42e9df0

Browse files
author
Miklos Szeredi
committed
ovl: pass realinode to ovl_encode_real_fh() instead of realdentry
JIRA: https://issues.redhat.com/browse/RHEL-77301 CVE: CVE-2025-21654 commit 07aeefa Author: Amir Goldstein <amir73il@gmail.com> Date: Sun Jan 5 17:24:03 2025 +0100 ovl: pass realinode to ovl_encode_real_fh() instead of realdentry We want to be able to encode an fid from an inode with no alias. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://lore.kernel.org/r/20250105162404.357058-2-amir73il@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent fa82cad commit 42e9df0

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

fs/overlayfs/copy_up.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@ int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upperdentry,
416416
return err;
417417
}
418418

419-
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
419+
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
420420
bool is_upper)
421421
{
422422
struct ovl_fh *fh;
423423
int fh_type, dwords;
424424
int buflen = MAX_HANDLE_SZ;
425-
uuid_t *uuid = &real->d_sb->s_uuid;
425+
uuid_t *uuid = &realinode->i_sb->s_uuid;
426426
int err;
427427

428428
/* Make sure the real fid stays 32bit aligned */
@@ -439,7 +439,8 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
439439
* the price or reconnecting the dentry.
440440
*/
441441
dwords = buflen >> 2;
442-
fh_type = exportfs_encode_fh(real, (void *)fh->fb.fid, &dwords, 0);
442+
fh_type = exportfs_encode_inode_fh(realinode, (void *)fh->fb.fid,
443+
&dwords, NULL, 0);
443444
buflen = (dwords << 2);
444445

445446
err = -EIO;
@@ -481,7 +482,7 @@ struct ovl_fh *ovl_get_origin_fh(struct ovl_fs *ofs, struct dentry *origin)
481482
if (!ovl_can_decode_fh(origin->d_sb))
482483
return NULL;
483484

484-
return ovl_encode_real_fh(ofs, origin, false);
485+
return ovl_encode_real_fh(ofs, d_inode(origin), false);
485486
}
486487

487488
int ovl_set_origin_fh(struct ovl_fs *ofs, const struct ovl_fh *fh,
@@ -506,7 +507,7 @@ static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
506507
const struct ovl_fh *fh;
507508
int err;
508509

509-
fh = ovl_encode_real_fh(ofs, upper, true);
510+
fh = ovl_encode_real_fh(ofs, d_inode(upper), true);
510511
if (IS_ERR(fh))
511512
return PTR_ERR(fh);
512513

fs/overlayfs/export.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ static int ovl_check_encode_origin(struct dentry *dentry)
223223
static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct dentry *dentry,
224224
u32 *fid, int buflen)
225225
{
226+
struct inode *inode = d_inode(dentry);
226227
struct ovl_fh *fh = NULL;
227228
int err, enc_lower;
228229
int len;
@@ -236,8 +237,8 @@ static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct dentry *dentry,
236237
goto fail;
237238

238239
/* Encode an upper or lower file handle */
239-
fh = ovl_encode_real_fh(ofs, enc_lower ? ovl_dentry_lower(dentry) :
240-
ovl_dentry_upper(dentry), !enc_lower);
240+
fh = ovl_encode_real_fh(ofs, enc_lower ? ovl_inode_lower(inode) :
241+
ovl_inode_upper(inode), !enc_lower);
241242
if (IS_ERR(fh))
242243
return PTR_ERR(fh);
243244

fs/overlayfs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ int ovl_verify_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry,
542542
struct ovl_fh *fh;
543543
int err;
544544

545-
fh = ovl_encode_real_fh(ofs, real, is_upper);
545+
fh = ovl_encode_real_fh(ofs, d_inode(real), is_upper);
546546
err = PTR_ERR(fh);
547547
if (IS_ERR(fh)) {
548548
fh = NULL;
@@ -738,7 +738,7 @@ int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,
738738
struct ovl_fh *fh;
739739
int err;
740740

741-
fh = ovl_encode_real_fh(ofs, origin, false);
741+
fh = ovl_encode_real_fh(ofs, d_inode(origin), false);
742742
if (IS_ERR(fh))
743743
return PTR_ERR(fh);
744744

fs/overlayfs/overlayfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ int ovl_copy_up_with_data(struct dentry *dentry);
869869
int ovl_maybe_copy_up(struct dentry *dentry, int flags);
870870
int ovl_copy_xattr(struct super_block *sb, const struct path *path, struct dentry *new);
871871
int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat);
872-
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
872+
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
873873
bool is_upper);
874874
struct ovl_fh *ovl_get_origin_fh(struct ovl_fs *ofs, struct dentry *origin);
875875
int ovl_set_origin_fh(struct ovl_fs *ofs, const struct ovl_fh *fh,

0 commit comments

Comments
 (0)