From: Joel Granados <joel.granados@kernel.org>
To: Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: Jianlin Shi <shijianlin11@foxmail.com>,
akpm@linux-foundation.org, vbabka@kernel.org,
hannes@cmpxchg.org, surenb@google.com, mhocko@suse.com,
jackmanb@google.com, ziy@nvidia.com,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
Joel Granados <joel.granados@kernel.org>
Subject: [PATCH v2 2/4] sysctl: Reject uint arrays before calling the general proc_vec
Date: Fri, 14 Aug 2026 12:41:13 +0200 [thread overview]
Message-ID: <20260814-lklm-partial_ctlvec-v2-2-9df50d26e477@kernel.org> (raw)
In-Reply-To: <20260814-lklm-partial_ctlvec-v2-0-9df50d26e477@kernel.org>
Move the UINT vector size check to proc_douintvec_conv; the function
that routes UINT types only. Route all the UINT calls (including
proc_dou8vec_minmax) through proc_douintvec_conv.
UINT proc handlers that incorrectly define maxlen will now return
-EINVAL instead of 0 in the cases where data is missing, lenp is 0 or
ppos is 0. Note that maxlen == 0 is not considered as miss-defined.
Signed-off-by: Joel Granados <joel.granados@kernel.org>
---
kernel/sysctl.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 47a92cbbcb69cd361a18dba6606ae6ae8f86b5e2..7e9024899be6d5971752dd5639ab4b806a899081 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -748,10 +748,6 @@ static int proc_vec(const struct ctl_table *table, int dir, void *buffer,
return 0;
}
- /* uint arrays are not supported, *Do not* add support for them. */
- if (type == PROC_VEC_UINT && (table->maxlen / data_size) != 1)
- return -EINVAL;
-
if (SYSCTL_USER_TO_KERN(dir)) {
if (proc_first_pos_non_zero_ignore(ppos, table))
goto out;
@@ -797,6 +793,9 @@ int proc_douintvec_conv(const struct ctl_table *table, int dir, void *buffer,
int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr,
int dir, const struct ctl_table *table))
{
+ /* uint arrays are not supported, *Do not* add support for them. */
+ if (table->maxlen && (table->maxlen / sizeof(uint)) != 1)
+ return -EINVAL;
if (!conv)
conv = do_proc_uint_conv;
@@ -881,8 +880,7 @@ int proc_dointvec(const struct ctl_table *table, int dir, void *buffer,
int proc_douintvec(const struct ctl_table *table, int dir, void *buffer,
size_t *lenp, loff_t *ppos)
{
- return proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_UINT,
- (union proc_vec_conv){ .uint_conv = do_proc_uint_conv });
+ return proc_douintvec_conv(table, dir, buffer, lenp, ppos, do_proc_uint_conv);
}
/**
@@ -932,8 +930,8 @@ int proc_dointvec_minmax(const struct ctl_table *table, int dir,
int proc_douintvec_minmax(const struct ctl_table *table, int dir,
void *buffer, size_t *lenp, loff_t *ppos)
{
- return proc_vec(table, dir, buffer, lenp, ppos, PROC_VEC_UINT,
- (union proc_vec_conv){ .uint_conv = do_proc_uint_conv_minmax });
+ return proc_douintvec_conv(table, dir, buffer, lenp, ppos,
+ do_proc_uint_conv_minmax);
}
/**
@@ -976,8 +974,7 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int dir,
tmp.extra2 = (unsigned int *) &max;
val = READ_ONCE(*data);
- res = proc_vec(&tmp, dir, buffer, lenp, ppos, PROC_VEC_UINT,
- (union proc_vec_conv){ .uint_conv = do_proc_uint_conv_minmax });
+ res = proc_douintvec_minmax(&tmp, dir, buffer, lenp, ppos);
if (res)
return res;
if (SYSCTL_USER_TO_KERN(dir))
--
2.50.1
next prev parent reply other threads:[~2026-08-14 10:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 10:41 [PATCH v2 0/4] sysctl: Disallow partial updates of miss-formatted sysctl vectors Joel Granados
2026-08-14 10:41 ` [PATCH v2 1/4] sysctl: Split data conversion and file position handling Joel Granados
2026-08-14 10:41 ` Joel Granados [this message]
2026-08-14 10:41 ` [PATCH v2 3/4] sysctl: Disallow partial updates for erroneous sysctl vectors Joel Granados
2026-08-14 10:41 ` [PATCH v2 4/4] sysctl: Add 0013 to test partially updated vectors Joel Granados
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260814-lklm-partial_ctlvec-v2-2-9df50d26e477@kernel.org \
--to=joel.granados@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=shijianlin11@foxmail.com \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.