Skip to contentSkip to conversation

RISC-V: hwprobe: Check for the reserved flags

PATCH In review Palmer Dabbelt 2 participants 3 messages Jan 3, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: hwprobe: Check for the reserved flags

This check got dropped when RISCV_HWPROBE_WHICH_CPUS was added, but we've still got a bunch of other reserved flags. So check for them, just to make sure userspace doesn't get confused later.

Fixes e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag")
---
 arch/riscv/kernel/sys_hwprobe.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/sys_hwprobe.c +4 -0
index ccf61b040536..10d72893b04f 100644
@@ -347,6 +347,10 @@ static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
 			    unsigned long __user *cpus_user,
 			    unsigned int flags)
 {
+	/* The rest of the flags are still reserved. */
+	if (flags & ~RISCV_HWPROBE_WICHH_CPUS)
+		return -EINVAL;
+
 	if (flags & RISCV_HWPROBE_WHICH_CPUS)
 		return hwprobe_get_cpus(pairs, pair_count, cpusetsize,
 					cpus_user, flags);
Signature · 7 lines
2.43.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

Hi Palmer,

Quoted 5 lines · Palmer Dabbelt

This check got dropped when RISCV_HWPROBE_WHICH_CPUS was added, but we've still got a bunch of other reserved flags. So check for them, just to make sure userspace doesn't get confused later.

Fixes e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag")

I'm having trouble finding the tree/branch for this commit hash.

Quoted 10 lines
---
 arch/riscv/kernel/sys_hwprobe.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/sys_hwprobe.c +0 -0
index ccf61b040536..10d72893b04f 100644

arch/riscv/kernel/sys_hwprobe.c static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, · line 351

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -347,6 +347,10 @@ static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
 			    unsigned long __user *cpus_user,
 			    unsigned int flags)
 {
+	/* The rest of the flags are still reserved. */
+	if (flags & ~RISCV_HWPROBE_WICHH_CPUS)

^ WHICH

We shouldn't need this check since the way v3 of the series has do_riscv_hwprobe() is

static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
size_t pair_count, size_t cpusetsize, unsigned long __user *cpus_user, unsigned int flags)
{
if (flags & RISCV_HWPROBE_WHICH_CPUS)
return hwprobe_get_cpus(pairs, pair_count, cpusetsize,
cpus_user, flags);

return hwprobe_get_values(pairs, pair_count, cpusetsize,
cpus_user, flags);
}

And hwprobe_get_cpus() starts with this check

      if (flags != RISCV_HWPROBE_WHICH_CPUS)
               return -EINVAL;

And hwprobe_get_values() starts with the original check

      /* Check the reserved flags. */
      if (flags != 0)
              return -EINVAL;

IOW, we don't check flags at the top level, but each branch checks for its flags and hwprobe_get_values() doesn't have any.

Thanks,
drew

Quoted 8 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
+		return -EINVAL;
+
 	if (flags & RISCV_HWPROBE_WHICH_CPUS)
 		return hwprobe_get_cpus(pairs, pair_count, cpusetsize,
 					cpus_user, flags);
Signature · 1 line
2.43.0

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 10 lines · On Wed, 03 Jan 2024 05:23:57 PST (-0800), [email protected] wrote:

Hi Palmer,

Quoted 5 lines · Palmer Dabbelt

This check got dropped when RISCV_HWPROBE_WHICH_CPUS was added, but we've still got a bunch of other reserved flags. So check for them, just to make sure userspace doesn't get confused later.

Fixes e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag")

I'm having trouble finding the tree/branch for this commit hash.

It's just over here <https://git.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git/log/?h=for-next>, that's where I push stuff before it goes to my testing box. Something rebooted, though, so it ended up tied up for a bit...

Quoted 42 lines
Quoted 11 lines
---
 arch/riscv/kernel/sys_hwprobe.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/sys_hwprobe.c +0 -0
index ccf61b040536..10d72893b04f 100644

arch/riscv/kernel/sys_hwprobe.c static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs, · line 351

Quoted 5 lines
arch/riscv/kernel/sys_hwprobe.c +2 -0
@@ -347,6 +347,10 @@ static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
 			    unsigned long __user *cpus_user,
 			    unsigned int flags)
 {
+	/* The rest of the flags are still reserved. */
+	if (flags & ~RISCV_HWPROBE_WICHH_CPUS)

^ WHICH

We shouldn't need this check since the way v3 of the series has do_riscv_hwprobe() is

static int do_riscv_hwprobe(struct riscv_hwprobe __user *pairs,
size_t pair_count, size_t cpusetsize, unsigned long __user *cpus_user, unsigned int flags)
{
if (flags & RISCV_HWPROBE_WHICH_CPUS)
return hwprobe_get_cpus(pairs, pair_count, cpusetsize,
cpus_user, flags);

return hwprobe_get_values(pairs, pair_count, cpusetsize,
cpus_user, flags);
}

And hwprobe_get_cpus() starts with this check

      if (flags != RISCV_HWPROBE_WHICH_CPUS)
               return -EINVAL;

And hwprobe_get_values() starts with the original check

Quoted 7 lines
      /* Check the reserved flags. */
      if (flags != 0)
              return -EINVAL;

IOW, we don't check flags at the top level, but each branch checks for its flags and hwprobe_get_values() doesn't have any.

Ya, sorry, I think I was just still asleep.

Quoted 4 lines

Thanks,
drew

Quoted 8 lines
Quoted 8 lines
arch/riscv/kernel/sys_hwprobe.c +2 -1
+		return -EINVAL;
+
 	if (flags & RISCV_HWPROBE_WHICH_CPUS)
 		return hwprobe_get_cpus(pairs, pair_count, cpusetsize,
 					cpus_user, flags);
--

2.43.0

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv