From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC78CC10F15 for ; Thu, 25 Apr 2024 20:34:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 447976B0085; Thu, 25 Apr 2024 16:34:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7D46B0088; Thu, 25 Apr 2024 16:34:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E64F6B0089; Thu, 25 Apr 2024 16:34:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 100DD6B0085 for ; Thu, 25 Apr 2024 16:34:58 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8DFFF1A0679 for ; Thu, 25 Apr 2024 20:34:57 +0000 (UTC) X-FDA: 82049208234.20.35FB3B4 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by imf20.hostedemail.com (Postfix) with ESMTP id 519121C0011 for ; Thu, 25 Apr 2024 20:34:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=weissschuh.net header.s=mail header.b=Z+gqGa8P; spf=pass (imf20.hostedemail.com: domain of linux@weissschuh.net designates 159.69.126.157 as permitted sender) smtp.mailfrom=linux@weissschuh.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714077296; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bXmBmoexXh/2yVAgqRJ8tCSfghoxPnO4y7dsDa+jef8=; b=tWbxTY8dKzQRIlKWlTSPwLzyV8g3quZ8VTm8LCx1TtZUpBwxNnFp3GPP/B1IbbR0o0enrl G4CqxpD5KLlDtyUjTZSCDM1xM5qsMAdsSTSIWk8n3Sdx7IQ65yixgGTz3eLBoMMjVo15Ve SmTf7POGzBhM4OiudJ9lIigrqQlH8Iw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714077296; a=rsa-sha256; cv=none; b=O041DaFYKkA8xEuLpeyta0mj0X4OksiR8V9eXDnACFdxCTqKmnKUgyT/q40scl/NxFlS8d VKFNMf8eY5Gr2UsxSlnRC+spxG3FcbtDiIZV7nL/A8tvf1Tt7X126QTd1fe9k+tB+iSNVh 7lhgrXdG5unyY2DbwtFEYebk00o12mM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=weissschuh.net header.s=mail header.b=Z+gqGa8P; spf=pass (imf20.hostedemail.com: domain of linux@weissschuh.net designates 159.69.126.157 as permitted sender) smtp.mailfrom=linux@weissschuh.net; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714077293; bh=bZqtcMhFx7TDPaIgrLqyfpl0/OfmMPAKopBgZDQprIg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Z+gqGa8PD+3BrRxF+Exe+s/+n1FrcsSYPFeQUrvoT2UUvEiGsEXMDYuXjYQJDYiRJ 9/0fJxtI2lDBLEHhkegO15rObvRhgIuWQMhE+D085PPIsVKHmI/z9Zz6qr7xUxUgOg gdOVIytSYg1zquf83mxdxD8VyvGj7mHBMGjmlG8k= Date: Thu, 25 Apr 2024 22:34:52 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Joel Granados Cc: Jakub Kicinski , Luis Chamberlain , Kees Cook , Eric Dumazet , Dave Chinner , linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-xfs@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-hardening@vger.kernel.org, bridge@lists.linux.dev, lvs-devel@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-sctp@vger.kernel.org, linux-nfs@vger.kernel.org, apparmor@lists.ubuntu.com Subject: Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers Message-ID: References: <20240423-sysctl-const-handler-v3-0-e0beccb836e2@weissschuh.net> <20240424201234.3cc2b509@kernel.org> <20240425110412.2n5d27smecfncsfa@joelS2.panther.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240425110412.2n5d27smecfncsfa@joelS2.panther.com> X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 519121C0011 X-Stat-Signature: koszizbcispj8rs4ke67righosbko439 X-HE-Tag: 1714077295-970766 X-HE-Meta: U2FsdGVkX18Pd5OoPIxNKT3B54PWAjJJblgssUHY4Zk1RTkt3cSP6a0vjzBrEtqr0qbbBZ2auUagzonmRHjN6/YaJJKJnJW1XdpxF3ez5Bsq7LwDj4UQdL+069Jc6TpZa+k23iLFh1nDCMf32DkKEhlcbO7effnLL802hTRmCG/pEh3dARFFpRJU2rWEYnX4Pq9bC3/z1fQ1aLLDxinxwUJMYuAuP1dtHNGuSSVaKkTfohNa/dzYpCvrW9JVIm1inS7xsn3eP3U2WhVVKxwc9ijETxe/d+VKnM9kvPXguWMTkCrHxElhCWuhpqV5WxQ2kVl2kv+10cunsfITKkQag6TVk8dmFT6PplzC7NJFv/hXvl9x0SsRPvVFZM5B2KidbeGrEwe0vyqZicIWes7yxkL/V/MdGbFmyOkjcSMmMcGLdGv6PS2S2cizPyTyGVF+zI2PazpjND7PUQrPBrtPR7Xe73Kvvw/2vDhdLQd/4+Codc2Cz8q5MB972CjiX+LQK4d74Ql00JU70CZTWN+5Dl2QvUFIm7UhAqbYf3UfVXs89VM63YiYFVao16ec40ahazTg4K5Y/cqO1eIXFxanuZtwwa2AfVOO4dFfT+OMXe7ISZ9+n1i6US4C7agpeAvjmo/cot/cCWsj6ZJp+BTtRPkoem1Vh9SfVhE8el4cgpZoRhrEa7Vgq2lvR+z7o2AP3pOAsDUdwEJ9wNw/u8eah8uhI+gZ4NGdX1U1eX+TX5iLtH+79j8sRUXaqFRVnYDP9OT/KC84rsAvZcsBj8O/J5aYCRZhKCDCyebJv9ttok3rdHtzG7THPlnLoBuTxWEpiyIN4ZuVvU/YmgE7y1y06S20irptTOVuBkMTznNQMJa8Aanb0MKg7PjzTINoFR81eH9a80mWog4O/xZGMub84mW2r0XXsNJxNoKVZZ7oKv/HIVhlLA9dDH9BupVXOenWPOXPXpabJE4h7X9RdHT IJg2DDl9 qNdqxn51veHjRHq+U0grGIkQM7qqg22rger+/gr8UTJG87mj6PbH/j+nUzdOKkkvGW58wXZM0XngGwTwMdmUJk60LkHyTKoVl1qoX5DG8iiDsmXWO4iFUeHz2U8Akq+am79jhbFJlCM39SD2eJnIuj0h8aVYa/1eYvn3txaX2HG/BrhE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Joel, On 2024-04-25 13:04:12+0000, Joel Granados wrote: > On Wed, Apr 24, 2024 at 08:12:34PM -0700, Jakub Kicinski wrote: > > On Tue, 23 Apr 2024 09:54:35 +0200 Thomas Weißschuh wrote: > > > The series was split from my larger series sysctl-const series [0]. > > > It only focusses on the proc_handlers but is an important step to be > > > able to move all static definitions of ctl_table into .rodata. > > > > Split this per subsystem, please. > It is tricky to do that because it changes the first argument (ctl*) to > const in the proc_handler function type defined in sysclt.h: > " > -typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer, > +typedef int proc_handler(const struct ctl_table *ctl, int write, void *buffer, > size_t *lenp, loff_t *ppos); > " > This means that all the proc_handlers need to change at the same time. > > However, there is an alternative way to do this that allows chunking. We > first define the proc_handler as a void pointer (casting it where it is > being used) [1]. Then we could do the constification by subsystem (like > Jakub proposes). Finally we can "revert the void pointer change so we > don't have one size fit all pointer as our proc_handler [2]. > > Here are some comments about the alternative: > 1. We would need to make the first argument const in all the derived > proc_handlers [3] > 2. There would be no undefined behavior for two reasons: > 2.1. There is no case where we change the first argument. We know > this because there are no compile errors after we make it const. > 2.2. We would always go from non-const to const. This is the case > because all the stuff that is unchanged in non-const. > 3. If the idea sticks, it should go into mainline as one patchset. I > would not like to have a void* proc_handler in a kernel release. > 4. I think this is a "win/win" solution were the constification goes > through and it is divided in such a way that it is reviewable. > > I would really like to hear what ppl think about this "heretic" > alternative. @Thomas, @Luis, @Kees @Jakub? Thanks for that alternative, I'm not a big fan though. Besides the wonky syntax, Control Flow Integrity should trap on this construct. Functions are called through different pointers than their actual types which is exactly what CFI is meant to prevent. Maybe people find it easier to review when using "--word-diff" and/or "-U0" with git diff/show. There is really nothing going an besides adding a few "const"s. But if the consensus prefers this solution, I'll be happy to adopt it. > [1] https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative&id=4a383503b1ea650d4e12c1f5838974e879f5aa6f > [2] https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative&id=a3be65973d27ec2933b9e81e1bec60be3a9b460d > [3] proc_dostring, proc_dobool, proc_dointvec.... Thomas