diff mbox series

[v2,08/18] stackleak: don't modify ctl_table argument

Message ID 20231204-const-sysctl-v2-8-7a5060b11447@weissschuh.net (mailing list archive)
State In Next
Commit 109e1faa2061a865cce500e8cc3b7d72a7fc72b7
Headers show
Series sysctl: constify sysctl ctl_tables | expand

Commit Message

Thomas Weißschuh Dec. 4, 2023, 7:52 a.m. UTC
In a future commit the proc_handlers will change to
"const struct ctl_table".
As a preparation for that adapt the logic to work with a temporary
variable, similar to how it is done in other parts of the kernel.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 kernel/stackleak.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Kees Cook Dec. 4, 2023, 10:14 p.m. UTC | #1
On Mon, Dec 04, 2023 at 08:52:21AM +0100, Thomas Weißschuh wrote:
> In a future commit the proc_handlers will change to
> "const struct ctl_table".
> As a preparation for that adapt the logic to work with a temporary
> variable, similar to how it is done in other parts of the kernel.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Looks good -- thanks for catching the table-modification cases.

Acked-by: Kees Cook <keescook@chromium.org>
diff mbox series

Patch

diff --git a/kernel/stackleak.c b/kernel/stackleak.c
index 34c9d81eea94..b292e5ca0b7d 100644
--- a/kernel/stackleak.c
+++ b/kernel/stackleak.c
@@ -27,10 +27,11 @@  static int stack_erasing_sysctl(struct ctl_table *table, int write,
 	int ret = 0;
 	int state = !static_branch_unlikely(&stack_erasing_bypass);
 	int prev_state = state;
+	struct ctl_table tmp = *table;
 
-	table->data = &state;
-	table->maxlen = sizeof(int);
-	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+	tmp.data = &state;
+	tmp.maxlen = sizeof(int);
+	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 	state = !!state;
 	if (ret || !write || state == prev_state)
 		return ret;