Skip to content

sysctl: Disallow partial updates of miss-formatted sysctl vectors

Joel Granados b4-sent linux-fsdevel linux-kselftest linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20260813-lklm-partial_ctlvec-bd8867b70d5c

Versions newest first

  1. v2 Latest4 patches 16 repliesIn review
  2. v14 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Avoid doc compilation warnings related to apply_conv_on_vec function
- Initialize rc in testing to avoid a false positive when executing 0013 individually
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4sysctl: Split data conversion and file position handlingkernel/sysctl.c+126 -852 replies
2/4sysctl: Reject uint arrays before calling the general proc_veckernel/sysctl.c+7 -101 reply
3/4sysctl: Disallow partial updates for erroneous sysctl vectorskernel/sysctl.c+52 -134 replies
4/4sysctl: Add 0013 to test partially updated vectorstools/testing/selftests/sysctl/sysctl.sh+60 -03 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchBradley Morgan
SeriesR-b T-b
1/4R-b
2/4R-b
3/4R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/4] sysctl: Disallow partial updates of miss-formatted sysctl vectors

What?
=====

Stage table->data when writing INT & ULONG ctl_tables. Commit staged data to kernel variable only when all the conversions have succeeded. This is applicable only to variables that represent a vector; paths pertaining to scalers are left unchanged. Notice that partial updates can still happen if less than the size of the vector are passed and correctly formatted.

This is the behavior we are protecting against:

  # echo "4 4 1 7" > /proc/sys/kernel/printk
  # echo "1 x" > /proc/sys/kernel/printk
  -bash: echo: write error: Invalid argument
  # cat /proc/sys/kernel/printk
  1 4 1 7    <- the write failed, the first element changed anyway

Why?
====
Allowing a partial change to a vector after returning from an erroneous proc_handler is just plain wrong. This should be handled within sysctl to avoid users having to do it for themselves [1].

Behavioral Changes
==================
1. A failed write will not update the vector
2. Vector writes can now fail with -ENOMEM

Testing
=======
This went through regular sysctl kunit and self test. Also is posted to 0-day.

I always find it difficult to know who wants to receive this. Please let me know if you want to be removed from the Cc/To.

Best

[1] https://lore.kernel.org/all/[email protected]/

---
Changes in v2:
- Avoid doc compilation warnings related to apply_conv_on_vec function
- Initialize rc in testing to avoid a false positive when executing 0013 individually
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Joel Granados (4):
sysctl: Split data conversion and file position handling
sysctl: Reject uint arrays before calling the general proc_vec
sysctl: Disallow partial updates for erroneous sysctl vectors
sysctl: Add 0013 to test partially updated vectors

 kernel/sysctl.c                          | 237 ++++++++++++++++++++-----------
 tools/testing/selftests/sysctl/sysctl.sh |  60 ++++++++
 2 files changed, 217 insertions(+), 80 deletions(-)

---
base-commit: 4c12287001da60f3c022bb25932aa7a5590fc0b1
change-id: 20260813-lklm-partial_ctlvec-bd8867b70d5c

Best regards,

Signature · 1 line
Joel Granados <[email protected]>