From patchwork Sun Feb 25 04:05:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 205984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1424825dyb; Sat, 24 Feb 2024 20:06:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYT7U1CjCfUgJAMENAQxvC2EavquBDmB4fLqX9Kbq8XIHvLiPBSjciAyZLW5DAb3sFZ3ILVoBjb1UL4AJQOVw3VW8peg== X-Google-Smtp-Source: AGHT+IH+nAIo0L2UUjU6RO97kan55lp/NIplaZn6ljmIuydlnYkw+PcaQlsFoFQyU8ZboEof10gl X-Received: by 2002:a05:6808:3094:b0:3c1:66f9:f991 with SMTP id bl20-20020a056808309400b003c166f9f991mr4936836oib.10.1708834005260; Sat, 24 Feb 2024 20:06:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708834005; cv=pass; d=google.com; s=arc-20160816; b=dxqqNbnaZEBgejIdZLmsi9X80e6ikEoS1T0zeo+hToqKOYVriMMbu9g5FMSlPKjtkf zk9HWi6aEWRf+zS5lUgtpacaF5u5XSn0hfFSgFYdeYKRHCUhaT9Vyk0sL9c54qZGxEsa dj29Yffh6kALLDDF6KfmflRoM9hmZ//y03GxBwY3cZEOl7p4wsM46Vnsd5SnpAALJQtV UvaiXIdZs0w6bDSpojedz0dim2txMgpYrRoup4Z98eIjau+f9UNKMz9xwtLe7k7XDtmY +zl3rVozhiDNkVZXydwFjEMbbne/7/93M9kSuJBf0E/eZ5GAbt9x2job+MCxn8eZtxuB v8mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:date :subject:cc:to:from:message-id:dkim-signature; bh=eeuZJq6Fxo2cYyc6x11JY0tSqm747i90EQ3x4JLdDpA=; fh=gRLC4gLca4bkLA88sgL24ADNdiHmN1pE9ZWkE4mfeIg=; b=THS8VOkBaNzKvQqNGCDdc9NMaUPYW0OqI5Mz8Y9SoPZQcDAKKwdKGtN9sWPDtQh5oa 0YAhwuLHiNDEHmaPWAeAZNX2zyr1n/BPuh2JloAuz6LNXT0TiNmwkNu2dC542XEbj9wi wXDSYVts7c03watZhGlxHL4awr8qAe8GHzviHQzpSNZTY4Xvd3xJW3bxKeyHda0rH0CV KTg8ZbXBHBFmJCc8b1srpgXV0S2b1rnbogsHAtqn8rygOjzjw31lMzI33Z5nOcOhT8Z4 XgqNoXseC+Pl5NZFrJzSTWrVKNggljJ2bU4pG2lzOoDdOaB2d9wIuuJNs73F176HSou0 msOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=MWg1CTzB; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79967-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79967-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o17-20020ac85551000000b0042e66404858si2278653qtr.667.2024.02.24.20.06.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 20:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79967-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=MWg1CTzB; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79967-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79967-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0FE941C20E3D for ; Sun, 25 Feb 2024 04:06:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE1328C10; Sun, 25 Feb 2024 04:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="MWg1CTzB" Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) (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 6835233E1 for ; Sun, 25 Feb 2024 04:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708833992; cv=none; b=R/amVBWB5z0xudoyUSD7/Q/tUAd25BSYfAwRQcSYulbFFGwB+KjqaIgZwlAMPHPPo3WxR0xDU6T0judC/XZE0dGX2EVNZbjqas7kDJbBmUBFQ0jgY0Sgm8d5Ld799TUt6p5ewTPFvrgB2Ne6S7Luj5QM/0neqGYxs0NoZaWaQxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708833992; c=relaxed/simple; bh=v0u0UY6IZLeK7m5DJpMpA2gcsbr5QD2SeoS8vKGYb4s=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=j7mLz8t595u7dPQ3Olj5yqwYIRlyW7L1rxa0U+PB+vnSCYj1QQNW5B8TgF/I30c0S3LoLPSKm0aefA7EXeHOfCxEDyiEJ856REXSE7C5JVJvBDLNN+6iSgh9YjyifQGpctbbwdnRdx/gwRYZ1kpSPT9pBdXnXkOXGkAVKOqtmmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b=MWg1CTzB; arc=none smtp.client-ip=203.205.221.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1708833981; bh=eeuZJq6Fxo2cYyc6x11JY0tSqm747i90EQ3x4JLdDpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MWg1CTzBCcYkNXIeWTckng8BjAbOVlYgk158ElE+Vt8ArDpGlcViwMkRMQpqthccZ W/nncZjO8yhbo3iNSutc8OuH6kXRRJUyYaH5MHSLMOK577r/6+f/e5Pe3YfJg0ZF6h 3POEwVzul5tPfpwvaH7ZpO6zkLH0CE8AOwfejP00= Received: from localhost.localdomain ([2409:8a60:2a61:ef40:480f:5c56:cca3:1b20]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 18993038; Sun, 25 Feb 2024 12:06:09 +0800 X-QQ-mid: xmsmtpt1708833973tqo6zfhr6 Message-ID: X-QQ-XMAILINFO: OQ59tfF64tJLisGDfjHLssboL2wrAS+OJRngdWOM2ugGCB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PRBwq3WW+NvGbIU= From: wenyang.linux@foxmail.com To: Luis Chamberlain , Kees Cook , Joel Granados , Christian Brauner , davem@davemloft.net, David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Wen Yang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] sysctl: introduce sysctl SYSCTL_U8_MAX and SYSCTL_LONG_S32_MAX Date: Sun, 25 Feb 2024 12:05:31 +0800 X-OQ-MSGID: <20240225040538.845899-2-wenyang.linux@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225040538.845899-1-wenyang.linux@foxmail.com> References: <20240225040538.845899-1-wenyang.linux@foxmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791842326055602622 X-GMAIL-MSGID: 1791842326055602622 From: Wen Yang The boundary check of multiple modules uses these static variables (such as two_five_five, n_65535, ue_int_max, etc), and they are also not changed. Therefore, add them to the shared sysctl_vals and sysctl_long_vals to avoid duplication. Also rearranged sysctl_vals and sysctl_long_vals in numerical order. Signed-off-by: Wen Yang Cc: Luis Chamberlain Cc: Kees Cook Cc: Joel Granados Cc: Christian Brauner Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- include/linux/sysctl.h | 15 +++++++++------ kernel/sysctl.c | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index ee7d33b89e9e..b7a13e4c411c 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -45,19 +45,22 @@ struct ctl_dir; #define SYSCTL_FOUR ((void *)&sysctl_vals[4]) #define SYSCTL_ONE_HUNDRED ((void *)&sysctl_vals[5]) #define SYSCTL_TWO_HUNDRED ((void *)&sysctl_vals[6]) -#define SYSCTL_ONE_THOUSAND ((void *)&sysctl_vals[7]) -#define SYSCTL_THREE_THOUSAND ((void *)&sysctl_vals[8]) -#define SYSCTL_INT_MAX ((void *)&sysctl_vals[9]) +#define SYSCTL_U8_MAX ((void *)&sysctl_vals[7]) +#define SYSCTL_ONE_THOUSAND ((void *)&sysctl_vals[8]) +#define SYSCTL_THREE_THOUSAND ((void *)&sysctl_vals[9]) +#define SYSCTL_U16_MAX ((void *)&sysctl_vals[10]) +#define SYSCTL_INT_MAX ((void *)&sysctl_vals[11]) +#define SYSCTL_NEG_ONE ((void *)&sysctl_vals[12]) /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ -#define SYSCTL_MAXOLDUID ((void *)&sysctl_vals[10]) -#define SYSCTL_NEG_ONE ((void *)&sysctl_vals[11]) +#define SYSCTL_MAXOLDUID SYSCTL_U16_MAX extern const int sysctl_vals[]; #define SYSCTL_LONG_ZERO ((void *)&sysctl_long_vals[0]) #define SYSCTL_LONG_ONE ((void *)&sysctl_long_vals[1]) -#define SYSCTL_LONG_MAX ((void *)&sysctl_long_vals[2]) +#define SYSCTL_LONG_S32_MAX ((void *)&sysctl_long_vals[2]) +#define SYSCTL_LONG_MAX ((void *)&sysctl_long_vals[3]) extern const unsigned long sysctl_long_vals[]; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 157f7ce2942d..e1e00937cb29 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -82,10 +82,10 @@ #endif /* shared constants to be used in various sysctls */ -const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 }; +const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, U8_MAX, 1000, 3000, 65535, INT_MAX, -1, }; EXPORT_SYMBOL(sysctl_vals); -const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX }; +const unsigned long sysctl_long_vals[] = { 0, 1, S32_MAX, LONG_MAX, }; EXPORT_SYMBOL_GPL(sysctl_long_vals); #if defined(CONFIG_SYSCTL)