From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64A4421D3CC; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=IfSJX6qDu8BmP1N3OWkjfLxCnxnE/Gc+kS9m769YqYvRybcbaBTYoGlqxczN2bUTcadYW7MZLHfE4ilbDCIGtxE31qjDP5qIoTQefzpC/5DGqBjvsQqhbvISp9xy3tA6TGk8DzNI/q+7Z/2YZN4TXbTdXE1sOLRkzL4yTfCMl4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=BttYzFF+xjDCiXPSwOn5xmsY105yRYbvY3nWA/ZGsJo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pIk8RoWAkXIciF7jjO+o3+WPC3G3HBabBOPo0RB1AlA8f49usegbG+3VWGn8NXrmauFjfgy5W25mB8EiNJU2pOdt1cD8puP2LbbkkItM4X0zTCzPz7D+N640GAOkpc9ooZZXhoLgoWJ2xj9s6LOe33pzbRyEx7wPCoMu878Juq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ktwUgJWW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ktwUgJWW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 11FF7C19421; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=BttYzFF+xjDCiXPSwOn5xmsY105yRYbvY3nWA/ZGsJo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ktwUgJWWL25+fFa7Br3ubgCx8jyngNlwvZrkcycu31IK25hAkKzDxq1o8CDy/q8LH Oeadh6aB05lvSD/g3BgZbg6fGMF7BM2iK2EO5PfkKmIqEOhl8UedT2yUDBu/q+8Yy3 cxaIwGj1HjNXSOnxjWGe2fz2hbzlBnXlwwJik0sONrlwDQ3+F8nArzlqTHVoP0OUSZ jbfBXYl1C92sZ5DgtayxauaoE6r4HoOvqDfMVnDOqZf4CJm78VUFaTaRqHNVnGmBez TSu9D1W2Lsp0uzbavQixoFa/majQLknm+VkPFiddmnPEyDaxne/j6Ok6+7NXHoy3MQ qE0kpl3hVI+Iw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F03B1EEB599; Thu, 1 Jan 2026 12:57:21 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:05 +0100 Subject: [PATCH v2 1/9] sysctl: Move default converter assignment out of do_proc_dointvec Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-1-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1599; i=joel.granados@kernel.org; h=from:subject:message-id; bh=BttYzFF+xjDCiXPSwOn5xmsY105yRYbvY3nWA/ZGsJo=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWbyopSbpjacVeuho9vpVpKianahjMT25EN y0uNhNJdmNEj4kBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8qAAoJELqXzVK3 lkFPBUML/0D4SkMtKjl6Dt82vq7nvCRL7oKLZjkRsAuqCeOgUNgWjCV2IdQsp/4Lwa1Mw8LZSfq 9lO/4624pX9vJeQ9xDtxl3ZmYFLP8wQU+BtyV6+mM+647Exdvaoof2qt7bg5vtF5YmQ7bStBMPu udREwH3xwKWttbRbHDuNlsQb4OX+ILbRKn3gXgROmpqOErid/8cmYsZwZAXR9ioJbgXevY79MSW 7S6xc72zaHU5k2vaSUFvXuTPByEpfYbTsCVRAbfmcAIwqDMqNc7JtP+xUWrLsu8B4P+NXOxqTKm sMME7pe1zCM5X0Lub2wtqf55OqFlan1tEMKvQM8rqq3usIV18zQxLIk3v98gaIjvtZhZPnF/BLC hSV1/pbu151ObTOFCaLLjjHtL7G1XcrcCoi7LE77LSs570Vh6ZFYVsAsSOGzJkn2VFWTtCy7cM1 n1tb7Z6f/gSMLH+xiKgG3j4FxzQIjukVYQe5I8Z1+ELsRwt1u/qSPS7oZ/WRYb2LFDRlMiKaDS6 Vo= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Move the converter assignment out of do_proc_dointvec into the caller. Both the test for NULL and the assignment are meant to stay within the sysctl.c context. This is in preparation of using a typed macro to for the integer proc vector function. Signed-off-by: Joel Granados --- kernel/sysctl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index caee1bd8b2afc0927e0dcdd33c0db41c87518bfb..284ad6c277e8b52177cca3153ac= f02ff39de17f0 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -591,9 +591,6 @@ static int do_proc_dointvec(const struct ctl_table *tab= le, int dir, vleft =3D table->maxlen / sizeof(*i); left =3D *lenp; =20 - if (!conv) - conv =3D do_proc_int_conv; - if (SYSCTL_USER_TO_KERN(dir)) { if (proc_first_pos_non_zero_ignore(ppos, table)) goto out; @@ -840,7 +837,7 @@ int proc_dobool(const struct ctl_table *table, int dir,= void *buffer, int proc_dointvec(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_dointvec(table, dir, buffer, lenp, ppos, NULL); + return do_proc_dointvec(table, dir, buffer, lenp, ppos, do_proc_int_conv); } =20 /** @@ -1074,6 +1071,8 @@ int proc_dointvec_conv(const struct ctl_table *table,= int dir, void *buffer, int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr, int dir, const struct ctl_table *table)) { + if (!conv) + conv =3D do_proc_int_conv; return do_proc_dointvec(table, dir, buffer, lenp, ppos, conv); } =20 --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7269A21D596; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=a6/ftBnLuZQqBSVFC8e70/zioTxMk9q6S3QiFst0zfBh4/z1GYSP+W3jiEIB/pRTLYLPfX3JMTF14+zlg0Q6UV+H33O5o1qudgUT3TvkQORGvXRShxBTpvD0mvvaN03IuqB+F/KooYemQZ8XkERdpJvVLlXkW49wUqON6UvHt3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=MfwFhvcQgwESGWC+Nu+uixcRT1E0Tgwr+3WslGED45k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q0piL8nG47f9wgnMsL40uWIro+MTQdRggxAzi2sn5/MMbSKLkzV27PrZ3WsWJHt226AyhiSdpuR8Gyb48lu3ewa4YhTTaeLuefuPvVUfahwmHPht1Y/WwlPLBqJX/sYfK0UIL1g5FKfuXihvoA51jsy3bGeYEEXCvd5wvlCAXoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TB2mBn6v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TB2mBn6v" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1B2E4C19422; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=MfwFhvcQgwESGWC+Nu+uixcRT1E0Tgwr+3WslGED45k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TB2mBn6vdnOVbdLwA0UFzaSNygOoME6uDZ/3D7d2k8ZEHIduHgi923pKuYFclKc9v dbun6LMAJ/V9tvdi2Uz3LovlnGScVIMhwVMBM16NlUdMTHoFxtsIAx59ruunb0HeN6 5hjy8PLuvIROZRBxInluivA8mUIK3ALGbi3UYPWw2pebCxQC0aIS3hWKScd0GUXQcH E/MQyuZcCh/y11HGRM9PqgwR7SIIwmunGU7wUwqQwOiZQ+8txJhlXRckdtwswc9lN9 I/uO61dtrWzmd7C3PQKCdUx7xzgSyYvZnHF1rxmuOyUW9S44Wka+uqZGIAfHDGKnaz ZugUVNF4zIShQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 094CDEED600; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:06 +0100 Subject: [PATCH v2 2/9] sysctl: Replace do_proc_dointvec with a type-generic macro Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-2-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5259; i=joel.granados@kernel.org; h=from:subject:message-id; bh=MfwFhvcQgwESGWC+Nu+uixcRT1E0Tgwr+3WslGED45k=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWbyrp75EOe+2gLc2hPbD6r35ilHbCeY305 7A3vWgCgWfm+IkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8qAAoJELqXzVK3 lkFPV7ML+wUy9hbbmovESRDRANlhSfcLGSUSbrrClGNULVc88aA8ObOYM25i1dTkZlEFp+1pbJ2 nXOOx9rTpzKXQy0X+hRuWUW1i60n8pnfnkdV5NmfZwpCO0N7Hf9XvNig5JwdIRa7SORyYidvZvB kNtlLZvvHx2B+37pkFdB1whl20f7mAX3uNkKNidxZjTEKgW4GwO1BfCbCHdW6TrxX2LkXL/FcX/ DebV5BtE76uhgaggC4rKNdl5pVCIDHKE5sGtIvFWo0+Q2jEW2FtB8cRuTVfiRzBTM0HLOw83cL+ mfPci+ln3YvAOslGAOmVNebFq5bm2WgGx57cfub7yai/Z6RtRZh6qVa0Dg2v8v/Mv17PZdwjdHN Gtoan23y6s9N/5OWj9L/FELaVj8pe/Mizdf6d7q2sk2EIf0PnqgGbb7pdVoAB1mVbShTfigSZ7P o3AN4vuuU5RtZERn8Q7hA6/2QpycVZyouwxbrWoA/xwkgNtv1SF3Tfi01RBRPm5SVcDeUl/Iua9 nw= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Replaces do_proc_dointvec with do_proc_dotypevec macro. For now, it only generates the integer function, but it will bring together the logic for int, uint and ulong proc vector functions. It is parametrized on the kernel pointer type being processed and generates a "do_proc_do##T##vec" (where T is the type) function. The parametrization is needed for advancing the for loop with "++" and affects the type of the k_ptr argument in the converter call back function. Initialize the neg variable to false to ensure that unsigned types do not inadvertently assign negative values to user space. Return an -EINVAL when user space tries to assign a negative value to an unsigned variable. Add a comment to clarify that the macro is **not** designed to be exported outside of sysctl.c. Signed-off-by: Joel Granados --- kernel/sysctl.c | 144 ++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 77 insertions(+), 67 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 284ad6c277e8b52177cca3153acf02ff39de17f0..64f88c0338987ac9568713dd15d= b99f14553e82b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -572,75 +572,85 @@ static int do_proc_int_conv_minmax(bool *negp, unsign= ed long *u_ptr, int *k_ptr, =20 static const char proc_wspace_sep[] =3D { ' ', '\t', '\n' }; =20 -static int do_proc_dointvec(const struct ctl_table *table, int dir, - void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr, - int dir, const struct ctl_table *table)) -{ - int *i, vleft, first =3D 1, err =3D 0; - size_t left; - char *p; - - if (!table->data || !table->maxlen || !*lenp || - (*ppos && SYSCTL_KERN_TO_USER(dir))) { - *lenp =3D 0; - return 0; - } - - i =3D (int *) table->data; - vleft =3D table->maxlen / sizeof(*i); - left =3D *lenp; - - if (SYSCTL_USER_TO_KERN(dir)) { - if (proc_first_pos_non_zero_ignore(ppos, table)) - goto out; - - if (left > PAGE_SIZE - 1) - left =3D PAGE_SIZE - 1; - p =3D buffer; - } - - for (; left && vleft--; i++, first=3D0) { - unsigned long lval; - bool neg; - - if (SYSCTL_USER_TO_KERN(dir)) { - proc_skip_spaces(&p, &left); - - if (!left) - break; - err =3D proc_get_long(&p, &left, &lval, &neg, - proc_wspace_sep, - sizeof(proc_wspace_sep), NULL); - if (err) - break; - if (conv(&neg, &lval, i, 1, table)) { - err =3D -EINVAL; - break; - } - } else { - if (conv(&neg, &lval, i, 0, table)) { - err =3D -EINVAL; - break; - } - if (!first) - proc_put_char(&buffer, &left, '\t'); - proc_put_long(&buffer, &left, lval, neg); - } - } - - if (SYSCTL_KERN_TO_USER(dir) && !first && left && !err) - proc_put_char(&buffer, &left, '\n'); - if (SYSCTL_USER_TO_KERN(dir) && !err && left) - proc_skip_spaces(&p, &left); - if (SYSCTL_USER_TO_KERN(dir) && first) - return err ? : -EINVAL; - *lenp -=3D left; -out: - *ppos +=3D *lenp; - return err; +/* + * Do not export this macro outside the sysctl subsys. + * It is meant to generate static functions only + */ +#define do_proc_dotypevec(T) \ +static int do_proc_do##T##vec(const struct ctl_table *table, int dir, \ + void *buffer, size_t *lenp, loff_t *ppos, \ + int (*conv)(bool *negp, ulong *u_ptr, T *k_ptr, \ + int dir, const struct ctl_table *table)) \ +{ \ + T *i; \ + int vleft, first =3D 1, err =3D 0; \ + size_t left; \ + char *p; \ +\ + if (!table->data || !table->maxlen || !*lenp || \ + (*ppos && SYSCTL_KERN_TO_USER(dir))) { \ + *lenp =3D 0; \ + return 0; \ + } \ +\ + i =3D (typeof(i)) table->data; \ + vleft =3D table->maxlen / sizeof(*i); \ + left =3D *lenp; \ +\ + if (SYSCTL_USER_TO_KERN(dir)) { \ + if (proc_first_pos_non_zero_ignore(ppos, table)) \ + goto out; \ +\ + if (left > PAGE_SIZE - 1) \ + left =3D PAGE_SIZE - 1; \ + p =3D buffer; \ + } \ +\ + for (; left && vleft--; i++, first =3D 0) { \ + unsigned long lval; \ + bool neg =3D false; \ +\ + if (SYSCTL_USER_TO_KERN(dir)) { \ + proc_skip_spaces(&p, &left); \ +\ + if (!left) \ + break; \ + err =3D proc_get_long(&p, &left, &lval, &neg, \ + proc_wspace_sep, \ + sizeof(proc_wspace_sep), NULL); \ + if (!err && neg && is_unsigned_type(T)) \ + err =3D -EINVAL; \ + if (err) \ + break; \ + if (conv(&neg, &lval, i, dir, table)) { \ + err =3D -EINVAL; \ + break; \ + } \ + } else { \ + if (conv(&neg, &lval, i, dir, table)) { \ + err =3D -EINVAL; \ + break; \ + } \ + if (!first) \ + proc_put_char(&buffer, &left, '\t'); \ + proc_put_long(&buffer, &left, lval, neg); \ + } \ + } \ +\ + if (SYSCTL_KERN_TO_USER(dir) && !first && left && !err) \ + proc_put_char(&buffer, &left, '\n'); \ + if (SYSCTL_USER_TO_KERN(dir) && !err && left) \ + proc_skip_spaces(&p, &left); \ + if (SYSCTL_USER_TO_KERN(dir) && first) \ + return err ? : -EINVAL; \ + *lenp -=3D left; \ +out: \ + *ppos +=3D *lenp; \ + return err; \ } =20 +do_proc_dotypevec(int) + static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer, size_t *lenp, loff_t *ppos, int (*conv)(unsigned long *u_ptr, --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86F5420F067; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=jHQ6T2UiNJLsO5+jwlWc8Ie2vnZ1RlfTEeH5mvji6921rmP28x/eia+V0YptRcfITDZ6FsQ/g2k9rKK0v/fDi8DM4w3aRBgEQAC4nyuEwihJFbdDheUQG/c4GUIMMEnq0P2d+l0ZowUzCwcm5ylBt/C/B19KY/hRzCa6WZXDcIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=AS+0+hi2/RnLpQAf0P3Ce+cd66SedZRdJi+05mh0ssw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UKrzyqEpu17zgKWVm8lm8yu3eMexpK4vFfZIYSZVHGTPG7ok1lQWKl8GedTQIChnCT8TCc7nXQVRNVawj2Qf5SndqzKu/70f8jx1DAguGA8W0MVdSMVrci8CkWUX2ehBN6MslKGIJTUiMInLdIm1b0g7vUsG00CUw2+CYZ+ZHSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=byq9l3f9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="byq9l3f9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2686DC19423; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=AS+0+hi2/RnLpQAf0P3Ce+cd66SedZRdJi+05mh0ssw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=byq9l3f9lZAPogKndUZTQlcIX1tBiscxpUVajQyHbcw6AqeJ/8eo0uVJ5rXev9Va9 11ors+5FMFrMzCGd35tK3Kqp8HVrYkeuGUWUoLyFHWwLj637Oj5gLXmdufJaAVd/Jq ffGZvoOyP2EXpY7ZjouukKouTMmg/nOLDbQ9+7w4de9gc/ovHiZXg4+7Eh2cysKmr4 LU7NIPzJm8bAby/WG6fgbVGn+C9VeLeXTUAMv8/gXBr9EZvc5b/Tou/uutJ0FF3zCc 9pe43FHr3zpN8jNXr4LWIGxA5ULS2xksD/GGB2WWxhT6NBkP98exrqYDipN93Hejk+ XhEbC905s0lLg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1582DEED602; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:07 +0100 Subject: [PATCH v2 3/9] sysctl: Generate do_proc_doulongvec_minmax with do_proc_dotypevec macro Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-3-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12050; i=joel.granados@kernel.org; h=from:subject:message-id; bh=AS+0+hi2/RnLpQAf0P3Ce+cd66SedZRdJi+05mh0ssw=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWbyu2V5VcKuZ8imOqnzOhwCm68yMhCo1MS Djm/lcQA+WGJIkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8rAAoJELqXzVK3 lkFP55cL/RRdx6d8bbN2wwDMr/+zbqqsgGxTrF3p3DSGWRRF1ioWN68a7wYPT/DSO63/MM6CzGO ZbTFpkH+CmsY+AJj71EyfYmDU2WlKSVJCiHVcJHFdo8bvLwO0m29cGiYPIQbykIzmNaiI9Au9Wy 0o6Z+t7ACBGW7b/EbkAYO+lIr3gxw4IlpCoJVZ+3piSY1hZrqLcPAGlo7r/a2Wj9TjZPNDDqAJ1 zssLJaUGSMSacy9HdlUEY6TCaLpMCCVGQJ6dtUMh31iwq3v3/Shs1W0zqNvncuafgwLr+MRL+la mmZM0uy5uPZZSpf7z2KOvLmxV2FduUbciv1qCYB61J1JEPds2W5AwaXgPxhMZhbS2/EVvAlY4pL ToAhWxxAzkSdAJTxRkcd9uG+e7K2/OLKouxGHZq4vWfO5Eg6LOTpiqEqYYoZrb3McdBexA6ciWU 78lptGkv0bxr1nPAXYVIwXJ2nCMHMlFL0TWFC/yxSkr8R/Re15SQ/DN2K0Pa6P7hUWUVuwM+zj5 Eg= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 The existing do_proc_doulongvec_minmax conversions (based on conv{mul,div}) are replaced with a call to a converter callback that is passed by the caller. Replace the values (HZ, 1000l) passed to proc_doulongvec_minmax_conv in jiffies.c with a new callback containing millisecond to jiffie conversion (do_proc_ulong_conv_ms_jiffies). This effectively changes the simple calculation based on HZ and 1000l to a more robust conversion based on {_,}_msecs_to_jiffies. Change specifics =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * sysctl.h API - Implement new ulong uni & bi-directional converters (proc_ulong_*); export them so they can be used in proc_doulongvec_ms_jiffies_minmax (jiffies.c). - Replace two arguments (conv{mul,div}) in proc_doulongvec_minmax_conv with a general converter callback function that will be forwarded to do_proc_doulongvec. * do_proc_doulongvec - Replace the hardcoded uni-directional converters with a call to the call back converter function - Generate do_proc_doulongvec with do_proc_dotypevec macro - Rename do_proc_doulongvec_minmax to do_proc_doulongvec * jiffies - Create uni and bi-directional converters for milliseconds to jiffies (sysctl_{u2k,k2u}_ulong_conv_ms, do_proc_ulong_conv_ms_jiffies) - Pass the new bi-directional converter to proc_doulongvec_minmax_conv. Signed-off-by: Joel Granados --- include/linux/sysctl.h | 11 ++- kernel/sysctl.c | 182 ++++++++++++++++++++++++++++++---------------= ---- kernel/time/jiffies.c | 26 ++++++- 3 files changed, 148 insertions(+), 71 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 2886fbceb5d635fc7e0282c7467dcf82708919fe..5c8c17f98513983a459c54eae99= d1cc8bd63b011 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -117,11 +117,20 @@ int proc_dou8vec_minmax(const struct ctl_table *table= , int write, void *buffer, int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *= , loff_t *); int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, - unsigned long convmul, unsigned long convdiv); + int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, + int dir, const struct ctl_table *table)); int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, = loff_t *); int proc_do_static_key(const struct ctl_table *table, int write, void *buf= fer, size_t *lenp, loff_t *ppos); =20 +int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr, + ulong (*u_ptr_op)(const ulong)); +int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr, + ulong (*k_ptr_op)(const ulong)); +int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir, + const struct ctl_table *tbl, bool k_ptr_range_check, + int (*user_to_kern)(const ulong *u_ptr, ulong *k_ptr), + int (*kern_to_user)(ulong *u_ptr, const ulong *k_ptr)); /* * Register a set of sysctl names by calling register_sysctl * with an initialised array of struct ctl_table's. diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 64f88c0338987ac9568713dd15db99f14553e82b..53babebd65f401244d15dc53a8b= 7e7b2f73473b3 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -650,6 +650,7 @@ out: \ } =20 do_proc_dotypevec(int) +do_proc_dotypevec(ulong) =20 static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer, size_t *lenp, loff_t *ppos, @@ -971,87 +972,128 @@ int proc_dou8vec_minmax(const struct ctl_table *tabl= e, int dir, } EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); =20 -static int do_proc_doulongvec_minmax(const struct ctl_table *table, int di= r, - void *buffer, size_t *lenp, loff_t *ppos, - unsigned long convmul, - unsigned long convdiv) +/** + * proc_ulong_conv - Change user or kernel pointer based on direction + * + * @u_ptr: pointer to user variable + * @k_ptr: pointer to kernel variable + * @dir: %TRUE if this is a write to the sysctl file + * @tbl: the sysctl table + * @k_ptr_range_check: Check range for k_ptr when %TRUE + * @user_to_kern: Callback used to assign value from user to kernel var + * @kern_to_user: Callback used to assign value from kernel to user var + * + * When direction is kernel to user, then the u_ptr is modified. + * When direction is user to kernel, then the k_ptr is modified. + * + * Returns: 0 on success + */ +int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir, + const struct ctl_table *tbl, bool k_ptr_range_check, + int (*user_to_kern)(const ulong *u_ptr, ulong *k_ptr), + int (*kern_to_user)(ulong *u_ptr, const ulong *k_ptr)) { - unsigned long *i, *min, *max; - int vleft, first =3D 1, err =3D 0; - size_t left; - char *p; + if (SYSCTL_KERN_TO_USER(dir)) + return kern_to_user(u_ptr, k_ptr); =20 - if (!table->data || !table->maxlen || !*lenp || - (*ppos && SYSCTL_KERN_TO_USER(dir))) { - *lenp =3D 0; - return 0; - } + if (k_ptr_range_check) { + ulong tmp_k; + int ret; =20 - i =3D table->data; - min =3D table->extra1; - max =3D table->extra2; - vleft =3D table->maxlen / sizeof(unsigned long); - left =3D *lenp; - - if (SYSCTL_USER_TO_KERN(dir)) { - if (proc_first_pos_non_zero_ignore(ppos, table)) - goto out; - - if (left > PAGE_SIZE - 1) - left =3D PAGE_SIZE - 1; - p =3D buffer; - } + if (!tbl) + return -EINVAL; + ret =3D user_to_kern(u_ptr, &tmp_k); + if (ret) + return ret; + if ((tbl->extra1 && *(ulong *)tbl->extra1 > tmp_k) || + (tbl->extra2 && *(ulong *)tbl->extra2 < tmp_k)) + return -ERANGE; + WRITE_ONCE(*k_ptr, tmp_k); + } else + return user_to_kern(u_ptr, k_ptr); + return 0; +} =20 - for (; left && vleft--; i++, first =3D 0) { - unsigned long val; +/** + * proc_ulong_u2k_conv_uop - Assign user value to a kernel pointer + * + * @u_ptr: pointer to user space variable + * @k_ptr: pointer to kernel variable + * @u_ptr_op: execute this function before assigning to k_ptr + * + * Uses WRITE_ONCE to assign value to k_ptr. Executes u_ptr_op if + * not NULL. + * + * returns: 0 on success. + */ +int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr, + ulong (*u_ptr_op)(const ulong)) +{ + ulong u =3D u_ptr_op ? u_ptr_op(*u_ptr) : *u_ptr; =20 - if (SYSCTL_USER_TO_KERN(dir)) { - bool neg; + WRITE_ONCE(*k_ptr, u); + return 0; +} =20 - proc_skip_spaces(&p, &left); - if (!left) - break; +static int proc_ulong_u2k_conv(const ulong *u_ptr, ulong *k_ptr) +{ + return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, NULL); +} =20 - err =3D proc_get_long(&p, &left, &val, &neg, - proc_wspace_sep, - sizeof(proc_wspace_sep), NULL); - if (err || neg) { - err =3D -EINVAL; - break; - } +/** + * proc_ulong_k2u_conv_kop - Assign kernel value to a user space pointer + * + * @u_ptr: pointer to user space variable + * @k_ptr: pointer to kernel variable + * @k_ptr_op: Operation applied to k_ptr before assignment + * + * Uses READ_ONCE to assign value to u_ptr. Executes k_ptr_op if + * not NULL. + * + * returns: 0 on success. + */ +int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr, + ulong (*k_ptr_op)(const ulong)) +{ + ulong val =3D k_ptr_op ? k_ptr_op(READ_ONCE(*k_ptr)) : READ_ONCE(*k_ptr); + *u_ptr =3D (ulong)val; + return 0; +} =20 - val =3D convmul * val / convdiv; - if ((min && val < *min) || (max && val > *max)) { - err =3D -EINVAL; - break; - } - WRITE_ONCE(*i, val); - } else { - val =3D convdiv * READ_ONCE(*i) / convmul; - if (!first) - proc_put_char(&buffer, &left, '\t'); - proc_put_long(&buffer, &left, val, false); - } - } +static int proc_ulong_k2u_conv(ulong *u_ptr, const ulong *k_ptr) +{ + return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, NULL); +} =20 - if (SYSCTL_KERN_TO_USER(dir) && !first && left && !err) - proc_put_char(&buffer, &left, '\n'); - if (SYSCTL_USER_TO_KERN(dir) && !err) - proc_skip_spaces(&p, &left); - if (SYSCTL_USER_TO_KERN(dir) && first) - return err ? : -EINVAL; - *lenp -=3D left; -out: - *ppos +=3D *lenp; - return err; +static int do_proc_ulong_conv(bool *negp, ulong *u_ptr, ulong *k_ptr, int = dir, + const struct ctl_table *tbl) +{ + return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, true, + proc_ulong_u2k_conv, proc_ulong_k2u_conv); } =20 +/** + * proc_doulongvec_minmax_conv - read a vector of unsigned longs with a cu= stom converter + * + * @table: the sysctl table + * @dir: %TRUE if this is a write to the sysctl file + * @buffer: the user buffer + * @lenp: the size of the user buffer + * @ppos: file position + * @conv: Custom converter call back + * + * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long + * values from/to the user buffer, treated as an ASCII string. Negative + * strings are not allowed. + * + * Returns: 0 on success + */ int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, - unsigned long convmul, unsigned long convdiv) + int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, + int dir, const struct ctl_table *table)) { - return do_proc_doulongvec_minmax(table, dir, buffer, lenp, ppos, - convmul, convdiv); + return do_proc_doulongvec(table, dir, buffer, lenp, ppos, conv); } =20 /** @@ -1073,7 +1115,8 @@ int proc_doulongvec_minmax_conv(const struct ctl_tabl= e *table, int dir, int proc_doulongvec_minmax(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos, 1l, 1l= ); + return do_proc_doulongvec(table, dir, buffer, lenp, ppos, + do_proc_ulong_conv); } =20 int proc_dointvec_conv(const struct ctl_table *table, int dir, void *buffe= r, @@ -1312,7 +1355,8 @@ int proc_doulongvec_minmax(const struct ctl_table *ta= ble, int dir, =20 int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, - unsigned long convmul, unsigned long convdiv) + int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, + int dir, const struct ctl_table *table)) { return -ENOSYS; } diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index a5c7d15fce72fd2c8c8a0e0b9e40901534152124..57ed5f363f94bd566aa53c061f2= 0d3f4f2a05944 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c @@ -187,6 +187,24 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *ne= gp, ulong *u_ptr, sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms); } =20 +static int sysctl_u2k_ulong_conv_ms(const ulong *u_ptr, ulong *k_ptr) +{ + return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, sysctl_msecs_to_jiffies); +} + +static int sysctl_k2u_ulong_conv_ms(ulong *u_ptr, const ulong *k_ptr) +{ + return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, sysctl_jiffies_to_msecs); +} + +static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *= k_ptr, + int dir, const struct ctl_table *tbl) +{ + return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, false, + sysctl_u2k_ulong_conv_ms, sysctl_k2u_ulong_conv_ms); +} + + #else // CONFIG_PROC_SYSCTL static int do_proc_int_conv_jiffies(bool *negp, ulong *u_ptr, int *k_ptr, int dir, const struct ctl_table *tbl) @@ -213,6 +231,12 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *ne= gp, ulong *u_ptr, { return -ENOSYS; } + +static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *= k_ptr, + int dir, const struct ctl_table *tbl) +{ + return -ENOSYS; +} #endif =20 /** @@ -314,7 +338,7 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_= table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos, - HZ, 1000l); + do_proc_ulong_conv_ms_jiffies); } EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); =20 --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90027220F3E; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=PTmVcv1qjyf74PiVkf+3j+RkFR+C9fo5fJ27/mgGF6DCwxjJHVxfRxv1spwfiflLLu3JKTc7R7X2waQcdeagU9MQxXRGgAie5xRW/R+N6j0YOmKd5Dz3RuHiTVFsDqQoscZ70l3W+4PLbm9wzsnnZIlWG5XXx6R1BqB9eGl+LKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=gGY7DWYnYmsF86+DmOH72RVF1PosapGq/aYwNvDGIFs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K8+eOzKXkb7LU5B02PnTqdQyNkU7abOHDoRuBenJUkMcEEuzHrplxEtm0CIshuPfFdLQuLhcVhIAaDcCP7TpiJbxxWqwIBIsNOmVFr97Btwqr8kCGx/QvLggZvhcnu0mSwesRuIKoRXVr/95bY4PYw9M+6UGemki5q3AHzjLEhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QTC9dWze; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QTC9dWze" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3558EC2BC87; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=gGY7DWYnYmsF86+DmOH72RVF1PosapGq/aYwNvDGIFs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QTC9dWzeHrdDLRC/a35fzS0uD8DvZAt6kYoztR5iJkyqMydzBa69VFdsAhEKDyJvK qHOPqC8wdz+wnPnLYRotV3MDXbtBw/2XAlH0aFV72ZiO5XPqmd8FVunNZMVBtIaG26 tdFSmyySDBvI+yXjVGQNyFvbCytdRJbZOmYAWZRkxejRnQBZznfSA0mKk66ZLORQ6g ZDeHmpQ30ESUeE8KdMpbWq+0gW3UsCNv2MoZ40w+izsxAbxWvlrA+EHo9j+hGlhnZv NEmgQeXdjYprKS6mhDsaxw8gBPOuPG69DPcw0A+Bi2fGC02TKwon0Eue09w1XHmAry ztWOmM7vZae2A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22F4AEED603; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:08 +0100 Subject: [PATCH v2 4/9] sysctl: Add negp parameter to douintvec converter functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-4-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5249; i=joel.granados@kernel.org; h=from:subject:message-id; bh=gGY7DWYnYmsF86+DmOH72RVF1PosapGq/aYwNvDGIFs=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWbywPg9aGF/T8cCrGZo+yLl5cW6IwCELE3 0SPDgWLmLz0e4kBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8sAAoJELqXzVK3 lkFP3OYMAJPu4Q9nxsg0WyyLR5s58tGaIK5HhUKFIkrqvO3zGrhAooUkPFvnAs4fx1OWn2YoKSD VSDwduhQeLxIji3SUXwsYq9/3HA88L/QNNRfHpmKfivzIUGl4KiaddHrraUS6XS3Rj5/xC/4pKN rrx2I8VclLEiAMR9gMI/iF8BSeBwaFixhtlBs0VKClPhGgeF0FIK4AQpcoxqVaUYPke1rVdehzZ gmHVwPBaj4Rlcyqf7H7ZAwt3FP4n3Z8o/2pPmI0sC0HhX4w2I0OGEMx9BYqTCiTq0rRtGTKB7j1 EosPTqYb0FdzT9jQEZAYVhk4jwS0wzUIyLwiBh9WgjjMWi0viyR1UMnBNDNlDQNPhW9fG6v+F8S G9bIGm0hRIYm/8rr+84TfbZYzf7zf/20lJ646HT6v0PdEkvdPqxJ4lx0YoztFejWLkMqUw/blno xUm9bc8mthtt8l4o+ygmB2XTJSaRRBsNOkOSWERJAJ++hBVuskryNaWV8h2q55BupP0zSpOYk72 Qk= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Updates all douintvec converter function signatures to include a bool *negp parameter. This is a preparation commit required to eventually generate do_proc_douintvec with a macro. The negp argument will be ignored as it is not relevant for the uint type. Note that do_proc_uint_conv_pipe_maxsz in pipe.c is also modified. Signed-off-by: Joel Granados --- fs/pipe.c | 2 +- include/linux/sysctl.h | 2 +- kernel/sysctl.c | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 22647f50b286d3bca024ee4c6de51b100ddc5402..e4a8b6d43bee873ceb1928afab9= 909e6cd6e4418 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1492,7 +1492,7 @@ static int u2k_pipe_maxsz(const ulong *u_ptr, uint *k= _ptr) return proc_uint_u2k_conv_uop(u_ptr, k_ptr, round_pipe_size_ul); } =20 -static int do_proc_uint_conv_pipe_maxsz(ulong *u_ptr, uint *k_ptr, +static int do_proc_uint_conv_pipe_maxsz(bool *negp, ulong *u_ptr, uint *k_= ptr, int dir, const struct ctl_table *table) { return proc_uint_conv(u_ptr, k_ptr, dir, table, true, diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 5c8c17f98513983a459c54eae99d1cc8bd63b011..8f8e357b1f4d377a0891fbc85d3= 4073cd30469b1 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -102,7 +102,7 @@ int proc_douintvec_minmax(const struct ctl_table *table= , int write, void *buffer size_t *lenp, loff_t *ppos); int proc_douintvec_conv(const struct ctl_table *table, int write, void *bu= ffer, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *lvalp, unsigned int *valp, + int (*conv)(bool *negp, ulong *lvalp, uint *valp, int write, const struct ctl_table *table)); int proc_uint_k2u_conv(ulong *u_ptr, const uint *k_ptr); int proc_uint_u2k_conv_uop(const ulong *u_ptr, uint *k_ptr, diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 53babebd65f401244d15dc53a8b7e7b2f73473b3..8c0bbb82cfcbc8830a0f3a68326= c002ac51d41a6 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -444,7 +444,7 @@ static int proc_uint_u2k_conv(const ulong *u_ptr, uint = *k_ptr) return proc_uint_u2k_conv_uop(u_ptr, k_ptr, NULL); } =20 -static int do_proc_uint_conv(ulong *u_ptr, uint *k_ptr, int dir, +static int do_proc_uint_conv(bool *negp, ulong *u_ptr, uint *k_ptr, int di= r, const struct ctl_table *tbl) { return proc_uint_conv(u_ptr, k_ptr, dir, tbl, false, @@ -654,7 +654,7 @@ do_proc_dotypevec(ulong) =20 static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *u_ptr, + int (*conv)(bool *negp, unsigned long *u_ptr, unsigned int *k_ptr, int dir, const struct ctl_table *table)) { @@ -707,17 +707,18 @@ static int do_proc_douintvec_w(const struct ctl_table= *table, void *buffer, =20 static int do_proc_douintvec_r(const struct ctl_table *table, void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *u_ptr, + int (*conv)(bool *negp, unsigned long *u_ptr, unsigned int *k_ptr, int dir, const struct ctl_table *table)) { unsigned long lval; int err =3D 0; size_t left; + bool negp; =20 left =3D *lenp; =20 - if (conv(&lval, (unsigned int *) table->data, 0, table)) { + if (conv(&negp, &lval, (unsigned int *) table->data, 0, table)) { err =3D -EINVAL; goto out; } @@ -737,9 +738,8 @@ static int do_proc_douintvec_r(const struct ctl_table *= table, void *buffer, =20 static int do_proc_douintvec(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *u_ptr, - unsigned int *k_ptr, int dir, - const struct ctl_table *table)) + int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr, + int dir, const struct ctl_table *table)) { unsigned int vleft; =20 @@ -760,9 +760,6 @@ static int do_proc_douintvec(const struct ctl_table *ta= ble, int dir, return -EINVAL; } =20 - if (!conv) - conv =3D do_proc_uint_conv; - if (SYSCTL_USER_TO_KERN(dir)) return do_proc_douintvec_w(table, buffer, lenp, ppos, conv); return do_proc_douintvec_r(table, buffer, lenp, ppos, conv); @@ -786,9 +783,13 @@ static int do_proc_douintvec(const struct ctl_table *t= able, int dir, */ int proc_douintvec_conv(const struct ctl_table *table, int dir, void *buff= er, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *u_ptr, unsigned int *k_ptr, + int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr, int dir, const struct ctl_table *table)) { + + if (!conv) + conv =3D do_proc_uint_conv; + return do_proc_douintvec(table, dir, buffer, lenp, ppos, conv); } =20 @@ -1316,7 +1317,7 @@ int proc_douintvec_minmax(const struct ctl_table *tab= le, int dir, =20 int proc_douintvec_conv(const struct ctl_table *table, int write, void *bu= ffer, size_t *lenp, loff_t *ppos, - int (*conv)(unsigned long *lvalp, unsigned int *valp, + int (*conv)(bool *negp, ulong *lvalp, uint *valp, int write, const struct ctl_table *table)) { return -ENOSYS; --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 947C3221FA0; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=NDxve96uMy7b0wE5Qzri1wr//VKT8MvBQOXB6O3oegKI2DyZ45Rbc+0MtLzoUnXSs1GyVQp2mIOKCtJ5x6vD7Tfd8Rni13SHy6t/3NSlcXIsTzpwWlr459Mx9V3bYKkGxlOCcYiteA2K6kHaRt8YYoQuaiAZ0x8nN5P0BrPjrgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=DoeOUcfzBiDemYNQ6HSUnBzBoU1D+S+RU5qQ3unL1OE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FN6Q1y6s/dHGXIucgL65edGj1kf5D46ajACSJiNJZ9Z4b2lscFRCKvLpkT6ICD9KpmEakWd8cFazypX+Y3cRiJ0jQn6DPNpjBmIrhEyyx+QgLeGHDJp3/jocEeYjYv7pv42fp8HJmSEWHeefZ3/qJfdfmEIcL6LoDFblEBgDVYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ifn4pcIE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ifn4pcIE" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3BFD5C2BCB1; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=DoeOUcfzBiDemYNQ6HSUnBzBoU1D+S+RU5qQ3unL1OE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ifn4pcIE/GIPyDgTSioM1+bdaFedZPhmA+wyzJ7hOGRv0Wo1/JUJ1TcBZzoYJeoTp kmbp7AuXKut25metyouCuYOM6cmOXl2x56USfm63Ip2ddXns035krc7PMkQcb9KQep dAXc4wYMDHIC040DBiHOqaATj3QpbCFfRflYjwLixn/0JLMoUSXVg1G2jI1Ug32Xz3 BCfX7oWvQXb/i0pLOdjVtEqaZ7bt86EsSLuatAyyJ+H5a74asQL8jBNZ4FhtuK+sdp VklKzH1LkCSgIkYZW5Ua91y0lV/YxGyCN2E8S7orz665vDCWnbRFlLVuqel9dbGcdB WmEXcS4TIRmvQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE84EED601; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:09 +0100 Subject: [PATCH v2 5/9] sysctl: Generate do_proc_douintvec with a type-generic macro Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-5-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3960; i=joel.granados@kernel.org; h=from:subject:message-id; bh=DoeOUcfzBiDemYNQ6HSUnBzBoU1D+S+RU5qQ3unL1OE=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWbyyE/WewKrBIth60d6n12M+u4EPc/LR75 B2+D4kcqkE2HokBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8sAAoJELqXzVK3 lkFP3a8L/0C/D4LGj2mVPk0AbEsW6y30apYmMJKNFpm3EHkwLZ+52I4siB6o9XjhWP6wJft+P/F GoL2ZqVkI1IQ3712BJDhpjOpSGtlN8uXgwF3aGG8k6f1qHJvowrXxKwoxYBpfWdj1dCrwSSAud2 qII6NkL0xhSXCOBmg4ihljummrYghwezSDt19DxXw9GwVTkDZkCmOucuJ+06F5eBWaE67kMBmns zZeFCszDMUX2XFhZd5ddo+t1gkL3d0QrUqkFBnFTpz9A6v6OXR8iDCA2YwKOH7BClBGoS/9MyrV eHJhePRCZ57fKfl6oIEbv0OPDnmAhEyeNPc/8uPb/fFamc3PELHRaqMXXkpnkfPlAr9CJVrkiUf vffqXAWm5cBK0Jcjt8cPs3Pvz+ZJoYd08hTDpmHI3/Odpnq5+qHndXt10xUCcWV+MS7K7YRDXSK usGRtcm8faSwqWonxSIH5NeYcNiGe9/6AMI/ROJxEA6RLTcQ3J75DfZtuosh/4/HHfHy+1OxIU6 Nc= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Generate the behavior in do_proc_douintvec{,_w,_r} functions with do_proc_dotypevec(uint). The originals (do_proc_douintvec{,_w,_r}) where created in the same way as do_proc_dotypevec but for individual values (no vectors). In this commit we use the existing macro implementation to extend do_proc_douintvec to include vectors of values. Signed-off-by: Joel Granados --- kernel/sysctl.c | 118 ++--------------------------------------------------= ---- 1 file changed, 3 insertions(+), 115 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8c0bbb82cfcbc8830a0f3a68326c002ac51d41a6..5bc1bd3d415be2552f085111852= f63ddefb05894 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -451,8 +451,8 @@ static int do_proc_uint_conv(bool *negp, ulong *u_ptr, = uint *k_ptr, int dir, proc_uint_u2k_conv, proc_uint_k2u_conv); } =20 -static int do_proc_uint_conv_minmax(ulong *u_ptr, uint *k_ptr, int dir, - const struct ctl_table *tbl) +static int do_proc_uint_conv_minmax(bool *negp, ulong *u_ptr, uint *k_ptr, + int dir, const struct ctl_table *tbl) { return proc_uint_conv(u_ptr, k_ptr, dir, tbl, true, proc_uint_u2k_conv, proc_uint_k2u_conv); @@ -651,119 +651,7 @@ out: \ =20 do_proc_dotypevec(int) do_proc_dotypevec(ulong) - -static int do_proc_douintvec_w(const struct ctl_table *table, void *buffer, - size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, unsigned long *u_ptr, - unsigned int *k_ptr, int dir, - const struct ctl_table *table)) -{ - unsigned long lval; - int err =3D 0; - size_t left; - bool neg; - char *p =3D buffer; - - left =3D *lenp; - - if (proc_first_pos_non_zero_ignore(ppos, table)) - goto bail_early; - - if (left > PAGE_SIZE - 1) - left =3D PAGE_SIZE - 1; - - proc_skip_spaces(&p, &left); - if (!left) { - err =3D -EINVAL; - goto out_free; - } - - err =3D proc_get_long(&p, &left, &lval, &neg, - proc_wspace_sep, - sizeof(proc_wspace_sep), NULL); - if (err || neg) { - err =3D -EINVAL; - goto out_free; - } - - if (conv(&lval, (unsigned int *) table->data, 1, table)) { - err =3D -EINVAL; - goto out_free; - } - - if (!err && left) - proc_skip_spaces(&p, &left); - -out_free: - if (err) - return -EINVAL; - - return 0; - -bail_early: - *ppos +=3D *lenp; - return err; -} - -static int do_proc_douintvec_r(const struct ctl_table *table, void *buffer, - size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, unsigned long *u_ptr, - unsigned int *k_ptr, int dir, - const struct ctl_table *table)) -{ - unsigned long lval; - int err =3D 0; - size_t left; - bool negp; - - left =3D *lenp; - - if (conv(&negp, &lval, (unsigned int *) table->data, 0, table)) { - err =3D -EINVAL; - goto out; - } - - proc_put_long(&buffer, &left, lval, false); - if (!left) - goto out; - - proc_put_char(&buffer, &left, '\n'); - -out: - *lenp -=3D left; - *ppos +=3D *lenp; - - return err; -} - -static int do_proc_douintvec(const struct ctl_table *table, int dir, - void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr, - int dir, const struct ctl_table *table)) -{ - unsigned int vleft; - - if (!table->data || !table->maxlen || !*lenp || - (*ppos && SYSCTL_KERN_TO_USER(dir))) { - *lenp =3D 0; - return 0; - } - - vleft =3D table->maxlen / sizeof(unsigned int); - - /* - * Arrays are not supported, keep this simple. *Do not* add - * support for them. - */ - if (vleft !=3D 1) { - *lenp =3D 0; - return -EINVAL; - } - - if (SYSCTL_USER_TO_KERN(dir)) - return do_proc_douintvec_w(table, buffer, lenp, ppos, conv); - return do_proc_douintvec_r(table, buffer, lenp, ppos, conv); -} +do_proc_dotypevec(uint) =20 /** * proc_douintvec_conv - read a vector of unsigned ints with a custom conv= erter --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC6BF2264BB; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=ndjwa9DFWUAdqqZOpv/su5RHEsH1I444197bECkGpRJp9cfFIHQS1ehzyqPUJaMpBGoRLoyNnXYQJ4JP1VeCW/20e2TChFry5umcVhxWi0h54pBZ0h9Vp9zXEMTgxqsJpPGQIxoOgv4PMLP8jHwYyiqcseGujkeaxvI+YCmkqus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=EfuZhzyOMaVV5FDyRZb2ekLBnEai3Frd1m0Nc1g3+zI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gy8afTxbH2/SorObHNDhxTu3K4DqBCp7enh/tJLXch18TB+gISSOLpSQ79j6nH5kYhRQFpw8ZS572SntPOJQuEoIRuQIN/WDKZztGpejd1OyPSftWc16Ty8FvuOcbahYagIbUx3tBwRsixq0wFpylQw3fj8LPC1w2koJ6Yk3IYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vFmMq4Jh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vFmMq4Jh" Received: by smtp.kernel.org (Postfix) with ESMTPS id 43DD2C2BCB4; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=EfuZhzyOMaVV5FDyRZb2ekLBnEai3Frd1m0Nc1g3+zI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vFmMq4JhK41hP2oAP33aKfl/0ZvL+OhULgwua5nlS6KLh2GGCzVN2gFEsoszBgLst hor6oxfe5WpzeK+10xG42E2se7iD5qo9+c+nom8RHhGPiDZcsFJXzlEFcR4y63Wwxs NF1m/mhxFDkgESDS7y5ClYpd4HVAFlVQZywrx7tYcG8xW9rYnVxgP9ycGCrsrLgcvX 99H4IUJ4T5LCLo2h4oz8y7b0IrgLlx3seObFXzKd1CCi9MnvRUoO2sZRF1b5Re5+fR 2ne2qyr9xNXtQDqTFl3/jy3N4qqJmhbodC2B5b2W/U8066P/wHUUXM16oidsRjL8Cs Pjo/2Nkx8/tBA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39463E9410C; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:10 +0100 Subject: [PATCH v2 6/9] sysctl: Rename do_proc_dotypevec macro to do_proc_typevec Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-6-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4776; i=joel.granados@kernel.org; h=from:subject:message-id; bh=EfuZhzyOMaVV5FDyRZb2ekLBnEai3Frd1m0Nc1g3+zI=; b=kA0DAAoBupfNUreWQU8ByyZiAGlWby2heWf9jcxP2vhvsBmV3lAISfBPXvVhNCg19pyfxIy/M 4kBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8tAAoJELqXzVK3lkFP4/0L/A/v hGEofZz9w7ZA4yvb3Ml02P3+3enPRIQm0uZVE3j9K0wmjx4Zx8vwwbDU9Gb66iJ5VtDAEnMP6K7 cmwQ1e1lueC/v/JELJkHBihtSaVw+ou6CUGd7z+S72hjg5LHAdYoLfJHAfj6zOIb/tBjgjXYk4t Dc2sg02m/TnuCChNlUUU2cwfu3DeG6tahk5c346iKI3XRWSEoabHP+Xpogn9o0pg3k1RA0EXhAi on2KVcbbhNi8pfZrrCevWeXzesx1T6N8uYUSwkepJ0OjZZqfHaHGA271tPKUwjzGJ0t9q/o0moV +GlxvgnuXEvTAFapkhfxSBdLUH2Mn8G8smlsTFSdTcU03/IrtMsBYRB3Eb3FahsvpyGh4ymVqqH FnPV1l4FBcoPhhRqxgXhyfuoLx3g1ftKIeUY4hckbYGs/iTcC8iN4FR7vrmZdMm26qz836SyOXs U0Dai1pPIx3NVgMpmaXiS8URzNdMN7IxrvTxzrlr+SDsB6tUxRjLnnnq1tTA== X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Remove the do..do from the proc vector functions. The redundant "do" only adds confusion to the already large amount of functions in sysctl.c Signed-off-by: Joel Granados --- kernel/sysctl.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 5bc1bd3d415be2552f085111852f63ddefb05894..b90924944ad52bcd3347cf5ca7c= 87ac9455eb70d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -576,8 +576,8 @@ static const char proc_wspace_sep[] =3D { ' ', '\t', '\= n' }; * Do not export this macro outside the sysctl subsys. * It is meant to generate static functions only */ -#define do_proc_dotypevec(T) \ -static int do_proc_do##T##vec(const struct ctl_table *table, int dir, \ +#define do_proc_typevec(T) \ +static int do_proc_##T##vec(const struct ctl_table *table, int dir, \ void *buffer, size_t *lenp, loff_t *ppos, \ int (*conv)(bool *negp, ulong *u_ptr, T *k_ptr, \ int dir, const struct ctl_table *table)) \ @@ -649,9 +649,9 @@ out: \ return err; \ } =20 -do_proc_dotypevec(int) -do_proc_dotypevec(ulong) -do_proc_dotypevec(uint) +do_proc_typevec(int) +do_proc_typevec(ulong) +do_proc_typevec(uint) =20 /** * proc_douintvec_conv - read a vector of unsigned ints with a custom conv= erter @@ -678,7 +678,7 @@ int proc_douintvec_conv(const struct ctl_table *table, = int dir, void *buffer, if (!conv) conv =3D do_proc_uint_conv; =20 - return do_proc_douintvec(table, dir, buffer, lenp, ppos, conv); + return do_proc_uintvec(table, dir, buffer, lenp, ppos, conv); } =20 /** @@ -737,7 +737,7 @@ int proc_dobool(const struct ctl_table *table, int dir,= void *buffer, int proc_dointvec(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_dointvec(table, dir, buffer, lenp, ppos, do_proc_int_conv); + return do_proc_intvec(table, dir, buffer, lenp, ppos, do_proc_int_conv); } =20 /** @@ -756,8 +756,7 @@ int proc_dointvec(const struct ctl_table *table, int di= r, void *buffer, int proc_douintvec(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_douintvec(table, dir, buffer, lenp, ppos, - do_proc_uint_conv); + return do_proc_uintvec(table, dir, buffer, lenp, ppos, do_proc_uint_conv); } =20 /** @@ -780,8 +779,8 @@ int proc_douintvec(const struct ctl_table *table, int d= ir, void *buffer, int proc_dointvec_minmax(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_dointvec(table, dir, buffer, lenp, ppos, - do_proc_int_conv_minmax); + return do_proc_intvec(table, dir, buffer, lenp, ppos, + do_proc_int_conv_minmax); } =20 /** @@ -807,8 +806,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 do_proc_douintvec(table, dir, buffer, lenp, ppos, - do_proc_uint_conv_minmax); + return do_proc_uintvec(table, dir, buffer, lenp, ppos, + do_proc_uint_conv_minmax); } =20 /** @@ -851,8 +850,8 @@ int proc_dou8vec_minmax(const struct ctl_table *table, = int dir, tmp.extra2 =3D (unsigned int *) &max; =20 val =3D READ_ONCE(*data); - res =3D do_proc_douintvec(&tmp, dir, buffer, lenp, ppos, - do_proc_uint_conv_minmax); + res =3D do_proc_uintvec(&tmp, dir, buffer, lenp, ppos, + do_proc_uint_conv_minmax); if (res) return res; if (SYSCTL_USER_TO_KERN(dir)) @@ -982,7 +981,7 @@ int proc_doulongvec_minmax_conv(const struct ctl_table = *table, int dir, int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, int dir, const struct ctl_table *table)) { - return do_proc_doulongvec(table, dir, buffer, lenp, ppos, conv); + return do_proc_ulongvec(table, dir, buffer, lenp, ppos, conv); } =20 /** @@ -1004,8 +1003,8 @@ int proc_doulongvec_minmax_conv(const struct ctl_tabl= e *table, int dir, int proc_doulongvec_minmax(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_doulongvec(table, dir, buffer, lenp, ppos, - do_proc_ulong_conv); + return do_proc_ulongvec(table, dir, buffer, lenp, ppos, + do_proc_ulong_conv); } =20 int proc_dointvec_conv(const struct ctl_table *table, int dir, void *buffe= r, @@ -1015,7 +1014,7 @@ int proc_dointvec_conv(const struct ctl_table *table,= int dir, void *buffer, { if (!conv) conv =3D do_proc_int_conv; - return do_proc_dointvec(table, dir, buffer, lenp, ppos, conv); + return do_proc_intvec(table, dir, buffer, lenp, ppos, conv); } =20 /** --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE18A2264C9; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=pFVnqsxss+qsS951FyGbcBZgXlFBmaSedosMCnBYywJwcQBMfNOlfCy82MY6hlGF8+DTFWkmuztNDGaHRYOsAWWGIE8Bs7Ke4zst7asLO4PMU2kDKXhz/FiAMJNFSDuBWhu2pcfVUodWvfl2hyavztZp5C6+YmDEkTAn6DkVNOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=PIAQtecICUqPpS+GwLLx44WXYsf3diE+/qtx8X2p5C0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OOpRtrpzz63fxSoP4VbAlNBPAE6R2cAiSKlnEhI5QhCchsXHyiAJpkq6aLkcPVSI9Sg12xSTU2m1LUYETwq7ZfW2gTAt5RxgDu8hQYAcSDu0kmvg/83aucDVEpo4yD+ZDLjwMZadoOIieZjzDxM0ndzJDs1amBypMqmUi4Nz3hA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fpYfOt+x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fpYfOt+x" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4C980C2BC9E; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=PIAQtecICUqPpS+GwLLx44WXYsf3diE+/qtx8X2p5C0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fpYfOt+xzl1hYIZz5NQGsuSDLEP2raHrfupPMUQf7snK+IU3dXGBh9++lHAJ6cHV/ o/8AHY7K+M9LZ+6UU4ahXLOATbxYrOeZD6F1zivt4jxJdfx4GZ0Umb0PRkwE9/k5C1 b0LfFcxUp7bDuhtPvCeNXBXYxx9BJWjsApTm5V+q/vd7mjcU0kCyFDW6E/rT4mhm+V Mx8A03xJgJu+rr4BdCvhdmvE4dPXzzxsDcq6cWNNtHEaWbLSZVDZdnBOrCepymnOYt DBVfgWkGE6RzwxgHcaQ7MKjLwIrfR56IE7ezWkf3vn1wbiFkzYDfbJKL20kbxdyMHP urdvxxZazN+hQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45CCEEEB599; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:11 +0100 Subject: [PATCH v2 7/9] sysctl: Group proc_handler declarations and document Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-7-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8609; i=joel.granados@kernel.org; h=from:subject:message-id; bh=PIAQtecICUqPpS+GwLLx44WXYsf3diE+/qtx8X2p5C0=; b=owJ4nAHsARP+kA0DAAoBupfNUreWQU8ByyZiAGlWby4Vi5lAIxZP6HujaWUboPTqyKETi6mYN rVvVmiYApOxpIkBsgQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8uAAoJELqXzVK3 lkFPMBoL+ORiK+iFJAXM+evKOGujOUeFh5FzGL07It6KCm5eN2apg8w8EFSkVzn2ipOOSk53HLj ezKCPADMz8FBuGd//+XlXmBtgzfyggqvl10/v/L1dzhqUYw8CfqHppda9vSF3WQn1+3bWnOarF/ MsN0GQrtQB4neUSzJYIh3sqQsTRwK8lq4bg5mz9x+QGjJCwilEfRdjIisk8hozkfalgslWdsEuc ojU/uZJ7YdhjBDq7tSuPbT9uhkjAcZoM8Tf8sqR3naHBIUzSFDO4iFCYpJqt3UpjhteC4c5rd02 3Y8mPGIZJf2JeMd300iBwGY3x8f/Fn5mDA5hFQYOovKIIA+X3QSpq7sHB/ox4tBXm1QjykPWW7W ktj3meWyo03L6T1nYWepxLVPq6JBgD1W7/+EFLzmEPGovid8ZOEeHubb9rCygZLDF76vkX9Aem7 Cuzh3pcqom5MII3/bOSv61ytynbl8TDRZxpoGDymkfXZKwTyxLDazEACw+EcqaYjiHQ3MhvV7mL Q== X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Make four groups in the sysctl header and document each group with an example of how to use them. 1. proc_handler : All functions that can be passed to the proc_handler pointer in ctl_table 2. proc handler aggregators: Functions to create proc handlers with custom converters 3. bi-directional converters: Functions to create read/write custom converters. Can be passed to proc handler aggregators 4. uni-directional converters: Functions to create read or write custom converters. Can be passed as args to bi-directional converters Use just one naming convention in the declarations: 'write' becomes 'dir' and 'buffer' becomes 'buf'. Signed-off-by: Joel Granados --- include/linux/sysctl.h | 128 +++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 87 insertions(+), 41 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 8f8e357b1f4d377a0891fbc85d34073cd30469b1..ad268dfd9e79f5540a4a85a9a43= 9819fb3172640 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -74,63 +74,109 @@ extern const int sysctl_vals[]; =20 extern const unsigned long sysctl_long_vals[]; =20 -typedef int proc_handler(const struct ctl_table *ctl, int write, void *buf= fer, - size_t *lenp, loff_t *ppos); - -int proc_dostring(const struct ctl_table *, int, void *, size_t *, loff_t = *); -int proc_dobool(const struct ctl_table *table, int write, void *buffer, - size_t *lenp, loff_t *ppos); +typedef int proc_handler(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); =20 -int proc_dointvec(const struct ctl_table *, int, void *, size_t *, loff_t = *); -int proc_dointvec_minmax(const struct ctl_table *table, int dir, void *buf= fer, +/* proc_handler functions */ +int proc_dostring(const struct ctl_table *ctl, int dir, void *buf, size_t = *lenp, + loff_t *ppos); +int proc_dobool(const struct ctl_table *ctl, int dir, void *buf, size_t *l= enp, + loff_t *ppos); +int proc_dointvec(const struct ctl_table *ctl, int dir, void *buf, size_t = *lenp, + loff_t *ppos); +int proc_dointvec_minmax(const struct ctl_table *ctl, int dir, void *buf, size_t *lenp, loff_t *ppos); -int proc_dointvec_conv(const struct ctl_table *table, int dir, void *buffe= r, +int proc_douintvec(const struct ctl_table *ctl, int dir, void *buf, size_t= *lenp, + loff_t *ppos); +int proc_douintvec_minmax(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); +int proc_dou8vec_minmax(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); +int proc_doulongvec_minmax(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); +int proc_do_large_bitmap(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); +int proc_do_static_key(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos); + +/* + * proc_handler aggregators + * + * Create a proc_handler with a custom converter. Use when the user space + * value is a transformation of the kernel value. Cannot be passed as + * proc_handlers. + * + * Example of creating your custom proc handler: + * int custom_converter(bool *negp, ulong *u_ptr, uint *k_ptr, + * int dir, const struct ctl_table *ctl) {...} + * int custom_proc_handler(const struct ctl_table *ctl, int dir, + * void *buf, size_t *lenp, loff_t *ppos + * { return proc_dointvec_conv(ctl, dir, buf, lenp, ppos, custom_converter= ); } + */ +int proc_dointvec_conv(const struct ctl_table *ctl, int dir, void *buf, size_t *lenp, loff_t *ppos, int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr, - int dir, const struct ctl_table *table)); -int proc_int_k2u_conv_kop(ulong *u_ptr, const int *k_ptr, bool *negp, - ulong (*k_ptr_op)(const ulong)); -int proc_int_u2k_conv_uop(const ulong *u_ptr, int *k_ptr, const bool *negp, - ulong (*u_ptr_op)(const ulong)); + int dir, const struct ctl_table *ctl)); +int proc_douintvec_conv(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos, + int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr, + int dir, const struct ctl_table *ctl)); +int proc_doulongvec_minmax_conv(const struct ctl_table *ctl, int dir, void= *buf, + size_t *lenp, loff_t *ppos, + int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, + int dir, const struct ctl_table *ctl)); + +/* + * bi-directional converter functions + * + * Specify the converter function for both directions (user to kernel & ke= rnel + * to user). Use when you want to change the value of the variable before + * assignment. Used to create custom proc_handler aggregators. + * + * Example of creating your custom bi-directional converter: + * int custom_u2k(ulong *u_ptr, const uint *k_ptr) { ... } + * int custom_converter(bool *negp, ulong *u_ptr, uint *k_ptr, + * int dir, const struct ctl_table *ctl) + * { return proc_uint_conv(u_ptr, k_ptr, dir, ctl, true, + * custom_u2k, proc_uint_k2u_conv} + */ int proc_int_conv(bool *negp, ulong *u_ptr, int *k_ptr, int dir, const struct ctl_table *tbl, bool k_ptr_range_check, int (*user_to_kern)(const bool *negp, const ulong *u_ptr, int *k_ptr), int (*kern_to_user)(bool *negp, ulong *u_ptr, const int *k_ptr)); - -int proc_douintvec(const struct ctl_table *, int, void *, size_t *, loff_t= *); -int proc_douintvec_minmax(const struct ctl_table *table, int write, void *= buffer, - size_t *lenp, loff_t *ppos); -int proc_douintvec_conv(const struct ctl_table *table, int write, void *bu= ffer, - size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, ulong *lvalp, uint *valp, - int write, const struct ctl_table *table)); -int proc_uint_k2u_conv(ulong *u_ptr, const uint *k_ptr); -int proc_uint_u2k_conv_uop(const ulong *u_ptr, uint *k_ptr, - ulong (*u_ptr_op)(const ulong)); int proc_uint_conv(ulong *u_ptr, uint *k_ptr, int dir, const struct ctl_table *tbl, bool k_ptr_range_check, int (*user_to_kern)(const ulong *u_ptr, uint *k_ptr), int (*kern_to_user)(ulong *u_ptr, const uint *k_ptr)); - -int proc_dou8vec_minmax(const struct ctl_table *table, int write, void *bu= ffer, - size_t *lenp, loff_t *ppos); -int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *= , loff_t *); -int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, - void *buffer, size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, - int dir, const struct ctl_table *table)); -int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, = loff_t *); -int proc_do_static_key(const struct ctl_table *table, int write, void *buf= fer, - size_t *lenp, loff_t *ppos); - -int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr, - ulong (*u_ptr_op)(const ulong)); -int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr, - ulong (*k_ptr_op)(const ulong)); int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir, const struct ctl_table *tbl, bool k_ptr_range_check, int (*user_to_kern)(const ulong *u_ptr, ulong *k_ptr), int (*kern_to_user)(ulong *u_ptr, const ulong *k_ptr)); + +/* + * uni-directional converter functions + * + * Specify the converter function for one directions (user to kernel or + * kernel to user). Use to call the actual value conversion. Used to Create + * bi-directional converters. + * + * Example of creating a uni-directional converter: + * ulong op(const ulong val) { ... } + * int custom_unidir_conv(ulong *u_ptr, const uint *k_ptr) + * { return proc_uint_k2u_conv_kop(u_ptr, k_ptr, op); } + */ +int proc_int_k2u_conv_kop(ulong *u_ptr, const int *k_ptr, bool *negp, + ulong (*k_ptr_op)(const ulong)); +int proc_int_u2k_conv_uop(const ulong *u_ptr, int *k_ptr, const bool *negp, + ulong (*u_ptr_op)(const ulong)); +int proc_uint_k2u_conv(ulong *u_ptr, const uint *k_ptr); +int proc_uint_u2k_conv_uop(const ulong *u_ptr, uint *k_ptr, + ulong (*u_ptr_op)(const ulong)); +int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr, + ulong (*u_ptr_op)(const ulong)); +int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr, + ulong (*k_ptr_op)(const ulong)); + /* * Register a set of sysctl names by calling register_sysctl * with an initialised array of struct ctl_table's. --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92735221F2F; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=eTuKBwOm3NTDVfsGZlPFbg81XQNXceFsFv5vW00EZSI9mFAuhMiEvx25mqPgSLyWEfQIaiPuTvL9HCvLGzLcav5XeD0O0MogLw+bpvBI7X1WGeRFrVx+AHLRMD5ylSan+tOHsP5L7e7eT1DNy6qI/I7NTQ0gBh639N26b5Bb89E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=MzMUFtw28DFdEAcmgt575DTHAbUX+7Aak8PJgw2U3n4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tfrgrnyzMpgrXQhypVcqEQIMrwvOIs5SkGb/t/qwjFhU4Zp3ZELaiSD06JQs41+HxU7lQM7q/EZidEiOmJAEAsrmyt4pPT0K+Z4Lp23hfN8b4VHWpc19N6d3oKcbPlqvwfJXOB6FauHlWzlvB+A3JunLiuwVTmh801OWAjGZZT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SyndZou4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SyndZou4" Received: by smtp.kernel.org (Postfix) with ESMTPS id 57EFEC19425; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=MzMUFtw28DFdEAcmgt575DTHAbUX+7Aak8PJgw2U3n4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SyndZou4tbT1LasI5kmCc8zmclPPZ4hnE9urZrt294qyYPTaZVqhh3VL+Uoq76O/i h2hNlmzgMN8xgdZ7bvAOiXwRNRfYk+uQJV1Z5X7WMnMz0x9jhojqLkxhU8IvWps4NB 8j8DZxX3F1oRRHYBEJm1WBSH8n4xFhWAEQuzJryojoeUL7c2H9HLJ0a5LKWat47YtA Bbq0a0SGy8zBgQACEglCeGvvbUEfLloDuwBKAwiEpeKJxRobXm4N9cJXsHrk4Zwt/2 Wey3NMrxLbK08mXN8q2ifAgb3f8darZNpwHYxxAFkIoQHIAswZnKI0xQAcPQ2iEp1V D/B9Xx2MCeexg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 517B8EED605; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:12 +0100 Subject: [PATCH v2 8/9] sysctl: Rename proc_doulongvec_minmax_conv to proc_doulongvec_conv Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-8-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3589; i=joel.granados@kernel.org; h=from:subject:message-id; bh=MzMUFtw28DFdEAcmgt575DTHAbUX+7Aak8PJgw2U3n4=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWby6lDubJMgEskL1wDLPHDk5KSnhJZgPc4 vSgLbx0hQ4/34kBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8uAAoJELqXzVK3 lkFPxk4L/1bSJ0ctDiLoni3Tsfm2wdh+HwAQGuPZl6Gizt2Il9DMUGAfeQtyCrB9RhRhvJ4z1Ao 7WCoPBjFgxrkZrbU6rzIvE5k1Q+zza5bc4WHur6NeJc592IFEwOhU1U2D6hl/cp/ayqR358hN5P aCA915kXSEg37URh+V2XDb8t+VDFy5m2GMrcS2IBd2atxoDz9tC1BQQuc/x7anXdVBcHqvSC7ib UsweMJ3EDcO7sA36ZCCzDxuMtd90GgNZSw48PHh56mtHFTsbw7NR5jmjtsvJvRJNpLL1HTW5NJp lpZf/5UUF9J2smMgdZi2MsOfjPETxOZdg/WTZOMiiYrizH/klPTZMkkkYErf9PaOe5Xc2+volRC rkUg+F2N9GCZKVThtLfPmMzYChFgTzSRG4NPgINQnmsfYUYSQq3IwyForqZBCs/iOkIKWVu4dCN +Rc/z5lCErQ/69oO/W+Z1JGsKow6dtquAOBfNORkr3I3GgUX7H8xJw0+jFziYxT/IGEmv980Wr8 Eo= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Remove "_minmax" from proc_doulongvec_minmax_conv as it does not enforce min/max limits but serves as a generic converter for unsigned long vectors. Update function declaration in sysctl.h, definition in sysctl.c, and caller in jiffies.c accordingly. Signed-off-by: Joel Granados --- include/linux/sysctl.h | 8 ++++---- kernel/sysctl.c | 6 +++--- kernel/time/jiffies.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index ad268dfd9e79f5540a4a85a9a439819fb3172640..39cf1bf9703fc66a3c9c3360ca0= 81b5590339caa 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -121,10 +121,10 @@ int proc_douintvec_conv(const struct ctl_table *ctl, = int dir, void *buf, size_t *lenp, loff_t *ppos, int (*conv)(bool *negp, ulong *u_ptr, uint *k_ptr, int dir, const struct ctl_table *ctl)); -int proc_doulongvec_minmax_conv(const struct ctl_table *ctl, int dir, void= *buf, - size_t *lenp, loff_t *ppos, - int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, - int dir, const struct ctl_table *ctl)); +int proc_doulongvec_conv(const struct ctl_table *ctl, int dir, void *buf, + size_t *lenp, loff_t *ppos, + int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, + int dir, const struct ctl_table *ctl)); =20 /* * bi-directional converter functions diff --git a/kernel/sysctl.c b/kernel/sysctl.c index b90924944ad52bcd3347cf5ca7c87ac9455eb70d..09a5b2d86684cd09cbd6e9f074e= cdb71ea9bf218 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -961,7 +961,7 @@ static int do_proc_ulong_conv(bool *negp, ulong *u_ptr,= ulong *k_ptr, int dir, } =20 /** - * proc_doulongvec_minmax_conv - read a vector of unsigned longs with a cu= stom converter + * proc_doulongvec_conv - read a vector of unsigned longs with a custom co= nverter * * @table: the sysctl table * @dir: %TRUE if this is a write to the sysctl file @@ -976,7 +976,7 @@ static int do_proc_ulong_conv(bool *negp, ulong *u_ptr,= ulong *k_ptr, int dir, * * Returns: 0 on success */ -int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, +int proc_doulongvec_conv(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, int dir, const struct ctl_table *table)) @@ -1241,7 +1241,7 @@ int proc_doulongvec_minmax(const struct ctl_table *ta= ble, int dir, return -ENOSYS; } =20 -int proc_doulongvec_minmax_conv(const struct ctl_table *table, int dir, +int proc_doulongvec_conv(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos, int (*conv)(bool *negp, ulong *u_ptr, ulong *k_ptr, int dir, const struct ctl_table *table)) diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c index 57ed5f363f94bd566aa53c061f20d3f4f2a05944..38a654e79b731956748c5ff9b47= 6fb2adea58d7b 100644 --- a/kernel/time/jiffies.c +++ b/kernel/time/jiffies.c @@ -337,8 +337,8 @@ int proc_dointvec_ms_jiffies_minmax(const struct ctl_ta= ble *table, int dir, int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int d= ir, void *buffer, size_t *lenp, loff_t *ppos) { - return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos, - do_proc_ulong_conv_ms_jiffies); + return proc_doulongvec_conv(table, dir, buffer, lenp, ppos, + do_proc_ulong_conv_ms_jiffies); } EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); =20 --=20 2.50.1 From nobody Mon Feb 9 01:11:45 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0239222560; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; cv=none; b=n58Fr4tNWvwm4p/7pVuC64Zo3dL6SWFnu+q9aKNTunhuyVqladZYKFLScVEWT/EbYmH8nBzL4M2luX/hiigcmbE3bc0yKukZsAY41rbBsSl+LBLCyYqsYMW5QW/6mqSDcWq3pMJ38sYoY+f7hoMx+QYdtoec0RieYxyTyYPUlI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767272242; c=relaxed/simple; bh=MLmvW6uK36t+JJxfWBoWzf/bqBLohJaUDaY7ZHy7af8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U72nkrP/Mys8oooytD+2bYPX1mD7oXwvxBkKbyckLkSlA9VEmVIwzw5Q6bEbkQ0beDEXdT/MSP7T1o6c1Nw/CYttqsPE27xmJnnMzfAAaIq7e/EyWghuEqA1bpc/Q6QMLIK8qNec5wGPIHGnzmhwEJT+Supx8M8oH1n4Sw7EqCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ApUhpBQa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ApUhpBQa" Received: by smtp.kernel.org (Postfix) with ESMTPS id 63720C2BCC4; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767272242; bh=MLmvW6uK36t+JJxfWBoWzf/bqBLohJaUDaY7ZHy7af8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ApUhpBQaOq8YyCi7OMU3/qJR6UBKuT5bNcZUGlgN7+q8yJNWLSDWx02bm3GxIIDOR 3z1UwoMjUKexXd2h5f05A2LUFndXd5VdF9fTaAuCgNObvyTc59c97nCL8vk1wlGfU+ oRg4TEnRa3KnafEALt51Ubuu5vHvg4FL4F+PPvbbkIZQlXKog1k6FH8SFF50cE7Rjb v3It91cmyLaJpVS1a4TVXuBlpEEmQP/9CUX/5vOejsw+tqDYxbeSWZI5Nu0lSVmj8E qaUuV4ar+dVplxJox0GX2iOcmUXJBQjw6ItsrkCStlA3cw1mUIysXNL9DKjHy0rzBz Cnji/psFLmwsw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D7D9EED603; Thu, 1 Jan 2026 12:57:22 +0000 (UTC) From: Joel Granados Date: Thu, 01 Jan 2026 13:57:13 +0100 Subject: [PATCH v2 9/9] sysctl: Update API function documentation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260101-jag-dovec_consolidate-v2-9-ff918f753ba9@kernel.org> References: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> In-Reply-To: <20260101-jag-dovec_consolidate-v2-0-ff918f753ba9@kernel.org> To: Kees Cook , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Joel Granados X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5503; i=joel.granados@kernel.org; h=from:subject:message-id; bh=MLmvW6uK36t+JJxfWBoWzf/bqBLohJaUDaY7ZHy7af8=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGlWby/UXQzkiyGgh9B7trQiFm5F+QkfS5wJM M6D6j5PW81ZFYkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJpVm8vAAoJELqXzVK3 lkFPSYYL/jnWyufot+4/mnYJl8EGrk+gJldfGAx28qgTR4Ca+IaFZgjzkm88ShG3yrHr4m5F4cQ Emw0s3zI7yhKNih4yyGICMsBWdtSRCIwW7/qCeiCO3ucepX43imHvQO70MHaYGkcP8/zcVbfb8e mKAKJFNf17PTMZIKDD4sjhjffCKJcydwnmTzs76FNHntCQW+vSBtsJQHJhSjqu3cP6b2tOKEbfW a4cO5kXrztx0GjQnIBVSNPOT6LNOJRRZGENEniv4NhgEOBvfYAjNJnZph8Kfc0UpdjW6TcYArzS 3rvGnUDa35pF9OTqH11HrlR9AyJcAZqm3kCCf9BgULdPGXxZty3KowR1gDSH/ZMXI2mmD6/54Q1 bOp8l6/a4uEKO8X0Xp2iOccHE6V5z7zTpBOZ04yVkdIEY3bUFUuc/YIbpWpNSoG44C/XtnarWCd gqdGy+PFGzZJ3WxHIkqA7KK4kR7w09I/o9czgJK9lLYrCRIgRZYCmNwwBeAAiuoXmt1Gb8Ijjz5 O8= X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 Add colon ":" after argument name where it is missing Add doc for proc_int_conv and proc_dointvec_conv Signed-off-by: Joel Granados --- kernel/sysctl.c | 60 +++++++++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 09a5b2d86684cd09cbd6e9f074ecdb71ea9bf218..5ffa5c1bfdc929f16b59d178d0b= 253ebcac0f67b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -365,7 +365,7 @@ static void proc_put_char(void **buf, size_t *size, cha= r c) * not NULL. Check that the values are less than UINT_MAX to avoid * having to support wrap around from userspace. * - * returns 0 on success. + * Returns: 0 on success. */ int proc_uint_u2k_conv_uop(const ulong *u_ptr, uint *k_ptr, ulong (*u_ptr_op)(const ulong)) @@ -386,7 +386,7 @@ int proc_uint_u2k_conv_uop(const ulong *u_ptr, uint *k_= ptr, * * Uses READ_ONCE to assign value to u_ptr. * - * returns 0 on success. + * Returns: 0 on success. */ int proc_uint_k2u_conv(ulong *u_ptr, const uint *k_ptr) { @@ -460,16 +460,16 @@ static int do_proc_uint_conv_minmax(bool *negp, ulong= *u_ptr, uint *k_ptr, =20 /** * proc_int_k2u_conv_kop - Assign kernel value to a user space pointer - * @u_ptr - pointer to user space variable - * @k_ptr - pointer to kernel variable - * @negp - assigned %TRUE if the converted kernel value is negative; + * @u_ptr: pointer to user space variable + * @k_ptr: pointer to kernel variable + * @negp: assigned %TRUE if the converted kernel value is negative; * %FALSE otherweise - * @k_ptr_op - execute this function before assigning to u_ptr + * @k_ptr_op: execute this function before assigning to u_ptr * * Uses READ_ONCE to get value from k_ptr. Executes k_ptr_op before assign= ing * to u_ptr if not NULL. Does **not** check for overflow. * - * returns 0 on success. + * Returns: 0 on success. */ int proc_int_k2u_conv_kop(ulong *u_ptr, const int *k_ptr, bool *negp, ulong (*k_ptr_op)(const ulong)) @@ -488,15 +488,15 @@ int proc_int_k2u_conv_kop(ulong *u_ptr, const int *k_= ptr, bool *negp, =20 /** * proc_int_u2k_conv_uop - Assign user value to a kernel pointer - * @u_ptr - pointer to user space variable - * @k_ptr - pointer to kernel variable - * @negp - If %TRUE, the converted user value is made negative. - * @u_ptr_op - execute this function before assigning to k_ptr + * @u_ptr: pointer to user space variable + * @k_ptr: pointer to kernel variable + * @negp: If %TRUE, the converted user value is made negative. + * @u_ptr_op: execute this function before assigning to k_ptr * * Uses WRITE_ONCE to assign value to k_ptr. Executes u_ptr_op if * not NULL. Check for overflow with UINT_MAX. * - * returns 0 on success. + * Returns: 0 on success. */ int proc_int_u2k_conv_uop(const ulong *u_ptr, int *k_ptr, const bool *negp, ulong (*u_ptr_op)(const ulong)) @@ -515,6 +515,23 @@ int proc_int_u2k_conv_uop(const ulong *u_ptr, int *k_p= tr, const bool *negp, return 0; } =20 +/** + * proc_int_conv - Change user or kernel pointer based on direction + * + * @negp: will be passed to uni-directional converters + * @u_ptr: pointer to user variable + * @k_ptr: pointer to kernel variable + * @dir: %TRUE if this is a write to the sysctl file + * @tbl: the sysctl table + * @k_ptr_range_check: Check range for k_ptr when %TRUE + * @user_to_kern: Callback used to assign value from user to kernel var + * @kern_to_user: Callback used to assign value from kernel to user var + * + * When direction is kernel to user, then the u_ptr is modified. + * When direction is user to kernel, then the k_ptr is modified. + * + * Returns: 0 on success + */ int proc_int_conv(bool *negp, ulong *u_ptr, int *k_ptr, int dir, const struct ctl_table *tbl, bool k_ptr_range_check, int (*user_to_kern)(const bool *negp, const ulong *u_ptr, int *k_ptr), @@ -912,7 +929,7 @@ int proc_ulong_conv(ulong *u_ptr, ulong *k_ptr, int dir, * Uses WRITE_ONCE to assign value to k_ptr. Executes u_ptr_op if * not NULL. * - * returns: 0 on success. + * Returns: 0 on success. */ int proc_ulong_u2k_conv_uop(const ulong *u_ptr, ulong *k_ptr, ulong (*u_ptr_op)(const ulong)) @@ -938,7 +955,7 @@ static int proc_ulong_u2k_conv(const ulong *u_ptr, ulon= g *k_ptr) * Uses READ_ONCE to assign value to u_ptr. Executes k_ptr_op if * not NULL. * - * returns: 0 on success. + * Returns: 0 on success. */ int proc_ulong_k2u_conv_kop(ulong *u_ptr, const ulong *k_ptr, ulong (*k_ptr_op)(const ulong)) @@ -1007,6 +1024,21 @@ int proc_doulongvec_minmax(const struct ctl_table *t= able, int dir, do_proc_ulong_conv); } =20 +/** + * proc_dointvec_conv - read a vector of ints with a custom converter + * + * @table: the sysctl table + * @dir: %TRUE if this is a write to the sysctl file + * @buffer: the user buffer + * @lenp: the size of the user buffer + * @ppos: file position + * @conv: Custom converter call back. Defaults to do_proc_int_conv + * + * Reads/writes up to table->maxlen/sizeof(int) integer values from/to the + * user buffer, treated as an ASCII string. + * + * Returns: 0 on success + */ int proc_dointvec_conv(const struct ctl_table *table, int dir, void *buffe= r, size_t *lenp, loff_t *ppos, int (*conv)(bool *negp, unsigned long *u_ptr, int *k_ptr, --=20 2.50.1