Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3771101rdb; Thu, 14 Sep 2023 01:58:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvQhnLckPUcv8UjT8kS4iXm4a/S14ohfvQ8nBQa9ubxIF9yetnEjdFlBRBMnhvsd6sCQwZ X-Received: by 2002:a05:620a:459f:b0:76e:601d:a724 with SMTP id bp31-20020a05620a459f00b0076e601da724mr5524121qkb.34.1694681907678; Thu, 14 Sep 2023 01:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694681907; cv=none; d=google.com; s=arc-20160816; b=YkZTOa5XhL7vs7utrJeBGuN9ElcTkxTJd7RB4y7COcr6v4KxGl5ASl5eyg/jxHO/kp LkAS28JCf4/c8Nr2G5rL0MDl9fOrfQYk/xfBCFlfv0IU67KzblBOUNOaJ0LZrxGHBiNj h1WrH8jHP6uOXowKNPKFicrWgrc02zqgHFM1dZlFzOkYyk54ggeJ+vQHK1rwvuqMFHVU BDTZ+fIVv9cKBWj4kDJgWGgZh1WVTc4HWAP3XgYbWXLB3utwU8CAE4jahOn0+5RFUOvt E7eildo0Xp6+TFshgo+ATQPd3iMumIcaFwIZbS8UuSPw1fE8XT3Hf0Kt1NmrykUHPEeT LZ7A== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id l1-20020a632501000000b0056c403cd154si1042683pgl.595.2023.09.14.01.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:58:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; 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:6 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 pete.vger.email (Postfix) with ESMTP id 0F1CC835A6AB; Wed, 13 Sep 2023 16:54:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjIMXyX (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 16:54:39 -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 pete.vger.email 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 }; \ -- 2.34.1