From patchwork Wed Sep 13 23:54:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 139200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp38728vqi; Wed, 13 Sep 2023 18:12:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCyoQqy0L7LNUFrpOkB0cFDtW9+U8OoUO9zPRnPtwzMvKOXqOMGTxXyZsUtYAaf9I33+pB X-Received: by 2002:a05:6a00:2d0c:b0:68e:385b:bb47 with SMTP id fa12-20020a056a002d0c00b0068e385bbb47mr4461924pfb.2.1694653921796; Wed, 13 Sep 2023 18:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694653921; cv=none; d=google.com; s=arc-20160816; b=U35OEG2DvIjphdsl0gJoy9dvXf3neH2AVitQ9JHlyj6CyNCQIxi42+yKjx5qzzVd6j nCcGoPlAGpQdYx3NfuRwrm97ceyLgD6QjfOay7yi1YB4hm1j7o1tT1l0m+6A6rEF27XX fOHkiSpJfq7vmwbqzXQxyYNglkiAPUnIHO4Qwv4gK5l+uHXEjeaU6mvugNGQB1Zch4db sGozQw8ubhR0tZqN7pQugYtRR5RDcx6oA26WKDzYUGwG5HJ3Kqd7mFO49MSRM+EHmKNO 8toKtYl+gvInyEarQLpMlJJMig1wDyIUv8q4ftuiNZzQAInWbF6Enl8XrVDCHmk+1UIh ACrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=TmQ1vlrBfUMvjYgfJYVMsqlQZ4GMxfIJbcG1jqAE/6c=; fh=ehPi16xIvqzHBU8s8FbAbJwG7wFf7t+xzyKOwrdLKbU=; b=oklXVZuvJ5bW9asw3J4IV62sXLGMj4eIQp1RRUCfAeswUbVnhNahVro/3uugU6fiMl hvE+1MxC3Hv83I3gFyUTVZ64hzpI6rktYXO/NfNLXUNq1uqSFQeWjss5r1j+DUkC0EBj AuTS8s4BgMzwNTsw9KvfATVrxkfJIBaCoGZULSyKa7yOzejDmxG1e2lr8h92FdGBkdhG lsLqgYnQeqXzluElFangZubMPdrkORe9707c20oBb9ARYZNJPcLsQufXzLOnKXpEni8g aY7QIjdWoFIjlU1NsnU9SWUZCwKd7rYRuHeT7VYaKtno9kVtCdGj8ahaZsOVCGt2u7un txaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KYGwYidm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id a19-20020a62e213000000b0068e3fe95d4fsi403543pfi.273.2023.09.13.18.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 18:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KYGwYidm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3A0E582696C7; Wed, 13 Sep 2023 16:54:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233145AbjIMXyX (ORCPT + 35 others); Wed, 13 Sep 2023 19:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233157AbjIMXyW (ORCPT ); Wed, 13 Sep 2023 19:54:22 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D94BE69 for ; Wed, 13 Sep 2023 16:54:18 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1bd9b4f8e0eso2682745ad.1 for ; Wed, 13 Sep 2023 16:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694649257; x=1695254057; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TmQ1vlrBfUMvjYgfJYVMsqlQZ4GMxfIJbcG1jqAE/6c=; b=KYGwYidmtfdn/dlj8oYuvfxjws2xHrEMd1iOLoC73SvwTPuBPVk/NAVOoZucY9ON2W pVP7B0D8lORNTfDupoplEYpU+aNS0d75NfcbJHeVO7n7ViWQgLVu2W2Dvp0ioDx2MUw4 zUS+XOy3nJ0xTf+v3jtCiX2uAuA2VX1mgIIsE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694649257; x=1695254057; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TmQ1vlrBfUMvjYgfJYVMsqlQZ4GMxfIJbcG1jqAE/6c=; b=hoVU/K/CRsQqSB+PGw7XXXtBKFR7upsbKZKgL9BQXBlFvu70OeGpErReQOcX/twoLt m+Ozy82fsCkdjREirwTZE/TBTUbr6QPAGDTSTEwJOdEv1OPPk3us2qFXVTLQaVsGvfir mgnmu7GLnDkxtTYhMUbOnz1xMKmeSKQo47a0fD/vXnacO458Pmrl+ZOl5qkkcSax9a0Z IsODDuc3T/OfNbOLPp+oTz8Ew+BpUvrcWb3khxxg6aevKb6ZA8TwtlnmNF0mjA5K19pi /whJoB0Iw2r1xUp24K66oxDi3Eu9Suqr7XX48wSxVVo+IH1mEqp/ZzHmMZihuDnIZLZs 9g9w== X-Gm-Message-State: AOJu0YxPV0RczbtF1PPCZxc+iJIymYzCVCtLSpurpo1roKAmgqzs9OoI W3tmjik8ZKffeeOIS07cR3b3Ag== X-Received: by 2002:a17:903:32cf:b0:1bc:6c00:a2cf with SMTP id i15-20020a17090332cf00b001bc6c00a2cfmr5268838plr.53.1694649257342; Wed, 13 Sep 2023 16:54:17 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id 19-20020a170902c11300b001b9d7c8f44dsm175831pli.182.2023.09.13.16.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 16:54:16 -0700 (PDT) From: Kees Cook To: Luis Chamberlain Cc: Kees Cook , Johan Hovold , Jessica Yu , Sagi Grimberg , Nick Desaulniers , Miguel Ojeda , Joe Perches , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2] module: Clarify documentation of module_param_call() Date: Wed, 13 Sep 2023 16:54:14 -0700 Message-Id: <20230913235407.gonna.817-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2680; i=keescook@chromium.org; h=from:subject:message-id; bh=pNcngmHYrvDvUxoczJLnyZVd+nVJiePsfxEYP+mQ0xQ=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlAkuma27fQb+IVRynpM5+rd9HXGa5bQURQdPIS Wt4kC4XqSeJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQJLpgAKCRCJcvTf3G3A JqnbD/42vpNafZEmP4ggRIZjSYnTNljv/5iB7eQ3O5HsbD5EckktJlskTx4nh5U8W6Aq19QK2ud cpUdzg+pXwtgB6Cc8dE/tSxo48uWZInMrTT2ImA75OAgvHUoTukoDigzVuGNfNSrj8wwOCRNOgp 5Z9CVTPYynY4j4HAk0gix5Vb7hKvTofXGIvDZxeKISf6PHd9GQaF+u90y3eC5GXv7jbXG2nUWMd 4NXLlFB0iZ5C+DHn4YK8I3agbJcRGR8AQlUunhBMMCJxeU3HUju5BiP3kEbx4DBIYjBrSA/QU1O 8/tjv6OGGs3fYvAQ3xMFWvy2TbCupCo1lfgi3O6BiRNEv50X+1mcQkXNI54EXvhubFgNuxReHZH 2fm2UDFT/B5IPWfve0GeE0NEa0xOIb917g8ValpzTBbn1wwa4Cb37YnEqKyRG22SBqa0NqTjB0S iHnXFAqAXLpyx//pUD7Ks9PGgleLZaU8eJRa/nFsbK56NHu5jc7aUphIaQMXjJqqPskKe0Nh2cp a9nfclOGfgol2VuYRRce2AEQ7ntXiAMeFWHx2QThOLBUaiUJmwsZgGsG00gYWZtg80rEv3BEcAB Wn7nkaHEBmeBdG64VcXqh1BpeLkTj3RmG8xmxghATmcI4X+1ERuTGdwGWV+cPvnJFVQAOrI4S6w a+qnLUI SM27XxvQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Sep 2023 16:54:27 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776973430307661176 X-GMAIL-MSGID: 1776973430307661176 Commit 9bbb9e5a3310 ("param: use ops in struct kernel_param, rather than get and set fns directly") added the comment that module_param_call() was deprecated, during a large scale refactoring to bring sanity to type casting back then. In 2017 following more cleanups, it became useful again as it wraps a common pattern of creating an ops struct for a given get/set pair: b2f270e87473 ("module: Prepare to convert all module_param_call() prototypes") ece1996a21ee ("module: Do not paper over type mismatches in module_param_call()") static const struct kernel_param_ops __param_ops_##name = \ { .flags = 0, .set = _set, .get = _get }; \ __module_param_call(MODULE_PARAM_PREFIX, \ name, &__param_ops_##name, arg, perm, -1, 0) __module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0) Many users of module_param_cb() appear to be almost universally open-coding the same thing that module_param_call() does now. Don't discourage[1] people from using module_param_call(): clarify the comment to show that module_param_cb() is useful if you repeatedly use the same pair of get/set functions. [1] https://lore.kernel.org/lkml/202308301546.5C789E5EC@keescook/ Cc: Luis Chamberlain Cc: Johan Hovold Cc: Jessica Yu Cc: Sagi Grimberg Cc: Nick Desaulniers Cc: Miguel Ojeda Cc: Joe Perches Cc: linux-modules@vger.kernel.org Reviewed-by: Miguel Ojeda Signed-off-by: Kees Cook --- Luis, I note that include/linux/moduleparam.h isn't in the MAINTAINERS file pattern. Perhaps you want to use include/linux/module*.h? --- include/linux/moduleparam.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index 962cd41a2cb5..d4452f93d060 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h @@ -293,7 +293,11 @@ struct kparam_array = { __param_str_##name, THIS_MODULE, ops, \ VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } } -/* Obsolete - use module_param_cb() */ +/* + * Useful for describing a set/get pair used only once (i.e. for this + * parameter). For repeated set/get pairs (i.e. the same struct + * kernel_param_ops), use module_param_cb() instead. + */ #define module_param_call(name, _set, _get, arg, perm) \ static const struct kernel_param_ops __param_ops_##name = \ { .flags = 0, .set = _set, .get = _get }; \