From patchwork Thu Mar 2 23:44:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 63668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp129133wrd; Thu, 2 Mar 2023 15:51:18 -0800 (PST) X-Google-Smtp-Source: AK7set9aiTqFdOz6VwQ7Xl1xJJmMSV1XL0FVpDt1/jN5LQaQkqLHZLS3SR0a0aBcwU1qvFVWf62I X-Received: by 2002:a62:1dc8:0:b0:5e0:316a:39ce with SMTP id d191-20020a621dc8000000b005e0316a39cemr194968pfd.27.1677801078130; Thu, 02 Mar 2023 15:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677801078; cv=none; d=google.com; s=arc-20160816; b=YATzHuBMwhJEF9Vn/4t6Gm6OY2vqUeF6zMorE//AdvNu7EG/fgep/5dpV2XFdtnjyF LByXgYw/10AlEzp75jeexaMF+xOuVLCarTptWR9BuDoSeY3Nz1Araf63EPVrvNVQ9ssf dBaqj9FwDMZTqjRzDn+BdHrm/Yi9uSLNNVmKpiwg0L2IFckYX/KPIk63tLyGEn2Ga5hl JvtTWs1zDnEhfPSdHywsbN6cb1gZ3w0K5tFdpu02na46cMav8HaFY1lk63VB6JqDPJ/E c1dEfSKPhjINS7XnkQVNtOWBelAS1jG0Gonqm8T+jPitBEL2ynnR/OxhH5mLJBbEw4I4 lkBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:mime-version :dkim-signature; bh=xv4aqNzW0df9Tu93QQQ99zBiZ6fJ3oheaLW9ritN8+4=; b=sswww6VcODNhMvXOV0kKcDgEKDCdGv8v4/TNncTIhGITu6c/0cED6I3btIyqFQFucq RC/W6bfTJ5duveO+9G5ENmjV9dC1+tscd8in+1nNC1omxjS19gGDzG4D3yxFacmmNe/4 uhIVNCcsiFhxEA4KxTowIzgsD2weh+hWGIySORQH7Q2W+JBsRNrWhH6pdPcNQprKDJEN KgioX0grIUCi4PSXg06wafGaQ70ZcJ4ksNZJeBFgk4aYUuPjjtKt5K7oig9sQ++xaR3n 4LwQsSlghNVMgV/+fkFDVLpI3PeMHyFGLT86sLdoc6kGusVk1D0V9ikR/ogZemX5Ut9z sJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=XYgo+sPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020aa7984f000000b0058623296e77si582647pfq.327.2023.03.02.15.51.04; Thu, 02 Mar 2023 15:51:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=XYgo+sPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjCBXoq (ORCPT + 99 others); Thu, 2 Mar 2023 18:44:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjCBXok (ORCPT ); Thu, 2 Mar 2023 18:44:40 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 761753B86E for ; Thu, 2 Mar 2023 15:44:37 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id da10so3734621edb.3 for ; Thu, 02 Mar 2023 15:44:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1677800675; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=xv4aqNzW0df9Tu93QQQ99zBiZ6fJ3oheaLW9ritN8+4=; b=XYgo+sPbad0eHGrhvt3u05kDPYyOJ0tftxcXfDzT+UsAul90T3tTtf8jf4DS3z1+OX HGSH2tD6pvo5+FDtL2nP7rbAts9BBUsSJnikGCc+1TtNKic1YXoUPnHC1VGU0sXkmvzI B31VRHN34iIdOrKpsWvplj7WRQRyoinfDQJQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677800675; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xv4aqNzW0df9Tu93QQQ99zBiZ6fJ3oheaLW9ritN8+4=; b=yNHRI5RkFQ0ZZerVW2vkUA6ezVKJmapH5wj6U+BN52mZLLjhNoZDT2CPg7Q2o5qUKe +KPrOP9rP++2cZvvEv4eJ7inkjrPV/bYSmO5RXpQjBLXTTvZdMkHyvH47+sG9nJH18mo YNK7PMik6JCg2t6fjDfUezP/2ojtqkxfQTNsPMsVM1npatpgoqGRTZ2U8aI/Wnp82w9O 0x29aDM+VVysEZrekS/t4gDJmPBpBMXULUDmnZoqA7frwW0pwOOHh1EI30htyV1798l+ DD2oMpjezM6SHuB7WXciinVgUknSfLOCNB8+bQbtFKriRfqeXeSSZlP7BnF2PDly8UZh N5iA== X-Gm-Message-State: AO0yUKXmsoo4wf/jLQu18/smWBUuSpimFOtLhdo08TbOsnv17ZtnNcoZ 4O0pIHkLSGG22RzrS5sto/c/bXQ3eIGziIkVSOsyuQ== X-Received: by 2002:a17:906:c792:b0:7c4:fa17:7203 with SMTP id cw18-20020a170906c79200b007c4fa177203mr12963965ejb.63.1677800675668; Thu, 02 Mar 2023 15:44:35 -0800 (PST) Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com. [209.85.208.42]) by smtp.gmail.com with ESMTPSA id bi23-20020a170906a25700b008d356cafaedsm260261ejb.40.2023.03.02.15.44.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Mar 2023 15:44:34 -0800 (PST) Received: by mail-ed1-f42.google.com with SMTP id f13so3669721edz.6 for ; Thu, 02 Mar 2023 15:44:34 -0800 (PST) X-Received: by 2002:a50:9f47:0:b0:4bc:13f5:68a5 with SMTP id b65-20020a509f47000000b004bc13f568a5mr39784edf.5.1677800674102; Thu, 02 Mar 2023 15:44:34 -0800 (PST) MIME-Version: 1.0 From: Linus Torvalds Date: Thu, 2 Mar 2023 15:44:17 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: usermode-helper code oddity query.. To: Luis Chamberlain , "Eric W. Biederman" , Peter Zijlstra , Christoph Hellwig , Kees Cook , Iurii Zaikin Cc: Linux Kernel Mailing List X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759301943323176401?= X-GMAIL-MSGID: =?utf-8?q?1759301943323176401?= So this is a bit out of the blue, but I cleaned up some really old legacy capability code in commit f122a08b197d ("capability: just use a 'u64' instead of a 'u32[2]' array") and in the process I became the last person to touch kernel/umh.c. Tag, I'm clearly it. Not that I want to take that glory away from PeterZ, who was the previous last person to touch that code. In fact, I'm just cc'ing everybody who has been touching that file at all in the last years, and a few /proc sysctl maintainers too. Anyway, I wanted to try to keep the capability code cleanups clear, and really only touched the data structure conversion, but I'm just left staring at that code and wondering why we have those odd CAP_BSET / CAP_PI dummy pointers. They've been there since the whole /proc interface was introduced, but they seem strangely pointless. It would _seem_ like it would be a lot simpler and more straightforward to just put the actual pointer to the usermodehelper capability in there instead, and not have that odd fake pointer enumeration at all. IOW, I'm wondering what's wrong with a patch like the attached. I might be missing something. I also would have like that array to be an array of "u32" rather than "unsigned long" (because that is, sadly, the interface we have, like it or not), but we don't seem to have a proc_dou32vec_minmax(). I guess "uint" is the same thing, but it's not pretty. Anyway, that's a separate and independent issue from this. And no, none of this is important. Just random cleanup of code I happened to look at for other reasons. Linus Reviewed-by: Luis Chamberlain kernel/umh.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/kernel/umh.c b/kernel/umh.c index 2a4708277335..60aa9e764a38 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -32,9 +32,6 @@ #include -#define CAP_BSET (void *)1 -#define CAP_PI (void *)2 - static kernel_cap_t usermodehelper_bset = CAP_FULL_SET; static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET; static DEFINE_SPINLOCK(umh_sysctl_lock); @@ -512,16 +509,11 @@ static int proc_cap_handler(struct ctl_table *table, int write, /* * convert from the global kernel_cap_t to the ulong array to print to * userspace if this is a read. + * + * Legacy format: capabilities are exposed as two 32-bit values */ + cap = table->data; spin_lock(&umh_sysctl_lock); - if (table->data == CAP_BSET) - cap = &usermodehelper_bset; - else if (table->data == CAP_PI) - cap = &usermodehelper_inheritable; - else - BUG(); - - /* Legacy format: capabilities are exposed as two 32-bit values */ cap_array[0] = (u32) cap->val; cap_array[1] = cap->val >> 32; spin_unlock(&umh_sysctl_lock); @@ -555,14 +547,14 @@ static int proc_cap_handler(struct ctl_table *table, int write, struct ctl_table usermodehelper_table[] = { { .procname = "bset", - .data = CAP_BSET, + .data = &usermodehelper_bset, .maxlen = 2 * sizeof(unsigned long), .mode = 0600, .proc_handler = proc_cap_handler, }, { .procname = "inheritable", - .data = CAP_PI, + .data = &usermodehelper_inheritable, .maxlen = 2 * sizeof(unsigned long), .mode = 0600, .proc_handler = proc_cap_handler,