rseq: Use pr_warn_once() when deprecated/unknown ABI flags are encountered

These commits use WARN_ON_ONCE() and kill the offending processes when
deprecated and unknown flags are encountered:

commit c17a6ff93213 ("rseq: Kill process when unknown flags are encountered in ABI structures")
commit 0190e4198e47 ("rseq: Deprecate RSEQ_CS_FLAG_NO_RESTART_ON_* flags")

The WARN_ON_ONCE() triggered by userspace input prevents use of
Syzkaller to fuzz the rseq system call.

Replace this WARN_ON_ONCE() by pr_warn_once() messages which contain
actually useful information.

Reported-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://lkml.kernel.org/r/20221102130635.7379-1-mathieu.desnoyers@efficios.com

authored by Mathieu Desnoyers and committed by Peter Zijlstra 448dca8c 094226ad

+17 -2
+17 -2
kernel/rseq.c
··· 171 171 return 0; 172 172 } 173 173 174 + static bool rseq_warn_flags(const char *str, u32 flags) 175 + { 176 + u32 test_flags; 177 + 178 + if (!flags) 179 + return false; 180 + test_flags = flags & RSEQ_CS_NO_RESTART_FLAGS; 181 + if (test_flags) 182 + pr_warn_once("Deprecated flags (%u) in %s ABI structure", test_flags, str); 183 + test_flags = flags & ~RSEQ_CS_NO_RESTART_FLAGS; 184 + if (test_flags) 185 + pr_warn_once("Unknown flags (%u) in %s ABI structure", test_flags, str); 186 + return true; 187 + } 188 + 174 189 static int rseq_need_restart(struct task_struct *t, u32 cs_flags) 175 190 { 176 191 u32 flags, event_mask; 177 192 int ret; 178 193 179 - if (WARN_ON_ONCE(cs_flags & RSEQ_CS_NO_RESTART_FLAGS) || cs_flags) 194 + if (rseq_warn_flags("rseq_cs", cs_flags)) 180 195 return -EINVAL; 181 196 182 197 /* Get thread flags. */ ··· 199 184 if (ret) 200 185 return ret; 201 186 202 - if (WARN_ON_ONCE(flags & RSEQ_CS_NO_RESTART_FLAGS) || flags) 187 + if (rseq_warn_flags("rseq", flags)) 203 188 return -EINVAL; 204 189 205 190 /*