Skip to content

Commit ae2108a

Browse files
htejungregkh
authored andcommitted
sysfs: make __sysfs_add_one() fail if the parent isn't a directory
Currently the kobject based interface guarantees that a parent sysfs_dirent is always a directory; however, the planned kernfs interface will be directly based on sysfs_dirents and the caller may specify non-directory node as the parent. Add an explicit check in __sysfs_add_one() so that such attempts fail with -EINVAL. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c84a3b2 commit ae2108a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
429429
return -EINVAL;
430430
}
431431

432+
if (sysfs_type(parent_sd) != SYSFS_DIR)
433+
return -EINVAL;
434+
432435
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
433436
sd->s_parent = sysfs_get(parent_sd);
434437

0 commit comments

Comments
 (0)