diff options
| author | Ali Ahmet Memis <ali@iusegentoo.com> | 2026-08-21 01:45:27 +0000 |
|---|---|---|
| committer | Stafford Horne <shorne@gmail.com> | 2026-08-29 07:32:26 +0100 |
| commit | 78004e9a87f240df03e2f73120d291763c32e0a7 (patch) | |
| tree | 137c22dd795222931b9d2bf2501d37cd766741aa /fs/sysfs/mount.c | |
| download | linux-stable-78004e9a87f240df03e2f73120d291763c32e0a7.tar.gz linux-stable-78004e9a87f240df03e2f73120d291763c32e0a7.zip | |
openrisc: fix arbitrary kernel memory access via or1k_atomic syscallgrafted
sys_or1k_atomic() (syscall 244 in the "or1k" ABI) takes two user
pointers, v1 and v2, and swaps the words they point to in hand-written
assembly.
l.lwz r29,0(r4)
l.lwz r27,0(r5)
l.sw 0(r4),r27
l.sw 0(r5),r29
The pointers are not checked with access_ok(). The four memory
accesses also have no exception table entries.
A caller passes a kernel address as either pointer, and the syscall
reads from and writes to it directly.
This gives an unprivileged process a kernel read/write primitive. It
overwrites kernel data such as the sys_call_table, gaining code
execution in kernel context.
Check both pointers before entering the critical section. Add fixups
for the four memory accesses so faults on valid but unmapped user
addresses return -EFAULT.
[shorne@gmail.com: fix comment style]
Fixes: 9d02a4283e9c ("OpenRISC: Boot code")
Cc: stable@vger.kernel.org
Signed-off-by: Ali Ahmet Memis <ali@iusegentoo.com>
Signed-off-by: Stafford Horne <shorne@gmail.com>
Diffstat (limited to 'fs/sysfs/mount.c')
| -rw-r--r-- | fs/sysfs/mount.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c new file mode 100644 index 000000000..88c10823f --- /dev/null +++ b/fs/sysfs/mount.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * fs/sysfs/symlink.c - operations for initializing and mounting sysfs + * + * Copyright (c) 2001-3 Patrick Mochel + * Copyright (c) 2007 SUSE Linux Products GmbH + * Copyright (c) 2007 Tejun Heo <teheo@suse.de> + * + * Please see Documentation/filesystems/sysfs.rst for more information. + */ + +#include <linux/fs.h> +#include <linux/magic.h> +#include <linux/mount.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/user_namespace.h> +#include <linux/fs_context.h> +#include <net/net_namespace.h> + +#include "sysfs.h" + +static struct kernfs_root *sysfs_root; +struct kernfs_node *sysfs_root_kn; + +static void sysfs_fs_context_free(struct fs_context *fc) +{ + struct kernfs_fs_context *kfc = fc->fs_private; + + if (kfc->ns_tag) + kobj_ns_drop(KOBJ_NS_TYPE_NET, kfc->ns_tag); + kernfs_free_fs_context(fc); + kfree(kfc); +} + +static const struct fs_context_operations sysfs_fs_context_ops = { + .free = sysfs_fs_context_free, + .get_tree = kernfs_get_tree, +}; + +static int sysfs_init_fs_context(struct fs_context *fc) +{ + struct kernfs_fs_context *kfc; + struct ns_common *ns; + + if (!(fc->sb_flags & SB_KERNMOUNT)) { + if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) + return -EPERM; + } + + kfc = kzalloc_obj(struct kernfs_fs_context); + if (!kfc) + return -ENOMEM; + + kfc->ns_tag = ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET); + kfc->root = sysfs_root; + kfc->magic = SYSFS_MAGIC; + fc->fs_private = kfc; + fc->ops = &sysfs_fs_context_ops; + if (ns) { + struct net *netns = to_net_ns(ns); + + put_user_ns(fc->user_ns); + fc->user_ns = get_user_ns(netns->user_ns); + } + fc->global = true; + return 0; +} + +static void sysfs_kill_sb(struct super_block *sb) +{ + struct ns_common *ns = (struct ns_common *)kernfs_super_ns(sb); + + kernfs_kill_sb(sb); + kobj_ns_drop(KOBJ_NS_TYPE_NET, ns); +} + +static struct file_system_type sysfs_fs_type = { + .name = "sysfs", + .init_fs_context = sysfs_init_fs_context, + .kill_sb = sysfs_kill_sb, + .fs_flags = FS_USERNS_MOUNT | FS_USERNS_MOUNT_RESTRICTED, +}; + +int __init sysfs_init(void) +{ + int err; + + sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK, + NULL); + if (IS_ERR(sysfs_root)) + return PTR_ERR(sysfs_root); + + sysfs_root_kn = kernfs_root_to_node(sysfs_root); + + err = register_filesystem(&sysfs_fs_type); + if (err) { + kernfs_destroy_root(sysfs_root); + return err; + } + + return 0; +} |
