Skip to content

sysctl: encode the min/max values directly in the table entry

Wen Yang lkml 8 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest posting 2/25 patches 0 repliesNew
  2. v5 posting 1/21 patch 18 repliesSuperseded
  3. v4 posting 2/21 patch 3 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v4 posting 1/21 patch0 repliesSuperseded
v3 posting 2/21 patch5 repliesSuperseded
v3 posting 1/21 patch0 repliesSuperseded
v21 patch2 repliesSuperseded
v11 patch0 repliesSuperseded

Patches in v5 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5sysctl: simplify the min/max boundary checkkernel/sysctl.c+73 -1260 replies
2/5sysctl: add helper functions to extract table->extra1/extra2fs/proc/proc_sysctl.c include/linux/sysctl.h kernel/sysctl.c+63 -230 replies
3/5sysctl: support encoding values directly in the table entryfs/proc/proc_sysctl.c include/linux/sysctl.h+32 -60 replies
4/5sysctl: add kunit test code to check the min/max encoding of sysctl table entrieskernel/sysctl-test.c+581 -00 replies
5/5sysctl: delete six_hundred_forty_kb to save 4 byteskernel/sysctl.c+3 -100 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/5] sysctl: encode the min/max values directly in the table entry

Many modules use these additional static/global variables (such as two_five_five, n_65535, ue_int_max, etc.) in the boundary checking of sysctl, and they are read-only and never changed.

Eric points out:

- One of the things that happens and that is worth acknowledging is there
- is code that wraps proc_doulongvec_minmax and proc_dointvec_minmax.
- Having the minmax information separate from the data pointer makes that
- wrapping easier.

- Further the min/max information is typically separate from other kinds
- of data. So even when not wrapped it is nice just to take a quick
- glance and see what the minimums and maximums are.

- My original suggest was that we change struct ctl_table from:

- > /* A sysctl table is an array of struct ctl_table: */
- > struct ctl_table {
- > const char *procname; /* Text ID for /proc/sys */
- > void *data;
- > int maxlen;
- > umode_t mode;
- > proc_handler *proc_handler; /* Callback for text formatting */
- > struct ctl_table_poll *poll;
- > void *extra1;
- > void *extra2;
- > } __randomize_layout;

- to:

- > /* A sysctl table is an array of struct ctl_table: */
- > struct ctl_table {
- > const char *procname; /* Text ID for /proc/sys */
- > void *data;
- > int maxlen;
- > umode_t mode;
- > proc_handler *proc_handler; /* Callback for text formatting */
- > struct ctl_table_poll *poll;
- > unsigned long min;
- > unsigned long max;
- > } __randomize_layout;

- That is just replace extra1 and extra2 with min and max members. The
- members don't have any reason to be pointers. Without being pointers
- the min/max functions can just use long values to cap either ints or
- longs, and there is no room for error. The integer promotion rules
- will ensure that even negative values can be stored in unsigned long
- min and max values successfully. Plus it is all bog standard C
- so there is nothing special to learn.

- There are a bunch of fiddly little details to transition from where we
- are today. The most straightforward way I can see of making the
- transition is to add the min and max members. Come up with replacements
- for proc_doulongvec_minmax and proc_dointvec_minmax that read the new
- min and max members. Update all of the users. Update the few users
- that use extra1 or extra2 for something besides min and max. Then
- remove extra1 and extra2. At the end it is simpler and requires the
- same or a little less space.

This patch series achieves direct encoding min/max values in table entries and still maintains compatibility with existing extra1/extra2 pointers. Afterwards, we can remove these unnecessary static variables progressively and also finally kill the shared const array.

v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

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

Wen Yang (5):
sysctl: simplify the min/max boundary check
sysctl: add helper functions to extract table->extra1/extra2
sysctl: support encoding values directly in the table entry
sysctl: add kunit test code to check the min/max encoding of sysctl
table entries
sysctl: delete six_hundred_forty_kb to save 4 bytes

 fs/proc/proc_sysctl.c  |  35 ++-
 include/linux/sysctl.h |  64 ++++-
 kernel/sysctl-test.c   | 581 +++++++++++++++++++++++++++++++++++++++++
 kernel/sysctl.c        | 211 ++++++---------
 4 files changed, 739 insertions(+), 152 deletions(-)
Signature · 1 line
2.25.1