Skip to contentSkip to conversation

x86: Enforce only whole copies for ssp_set()

PATCH New Rick Edgecombe 1 participant 1 message Mar 25, 2023 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Enforce only whole copies for ssp_set()

The regset set interface takes pos and count arguments to allow for partial copies. No callers use a non-zero pos, but ptrace allows for the count to be specified. It limits count to be a multiple of regset size, so this still allows for a zero size to be passed to ssp_set().

In ssp_set(), user_regset_copyin() returns success for copying zero bytes, which means user_ssp can later be accessed uninitialized. So add enforcement for this case. The other regset's also enforce pos == 0, so do that as well even though there is no caller today.

In the case of partial copies, some regsets return -EINVAL and some return -EFAULT. -EINVAL seems more appropriate, so use that error code.

Fixes d84e6ee122e5 ("x86: Add PTRACE interface for shadow stack")

---
Hi x86 maintainers,

While debugging this I wrote a shadow stack ptrace selftest that tries a bunch of invalid values. I thought to save it for a future series with selftests enhancements, unless you'd like to see it sooner.

Thanks,

Rick

---
 arch/x86/kernel/fpu/regset.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/fpu/regset.c +3 -0
index f0a8eaf7c52e..6bc1eb2a21bd 100644
@@ -223,6 +223,9 @@ int ssp_set(struct task_struct *target, const struct user_regset *regset,
 	    !ssp_active(target, regset))
 		return -ENODEV;
 
+	if (pos != 0 || count != sizeof(user_ssp))
+		return -EINVAL;
+
 	r = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &user_ssp, 0, -1);
 	if (r)
 		return r;

base-commit: b642e9e5f0dc797f543b431d4ba910a3da72a074

Signature · 1 line
2.17.1