From patchwork Tue Oct 3 23:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 148097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp2411927vqb; Tue, 3 Oct 2023 16:25:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWVaobCy1MALrQKDwUqDpe9zMEyh2w4ZWcwriBpLdeBtNMMWXRoftQEjXxdVvVSXKzK9pV X-Received: by 2002:a17:902:bb84:b0:1c7:4334:6540 with SMTP id m4-20020a170902bb8400b001c743346540mr763827pls.63.1696375529082; Tue, 03 Oct 2023 16:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696375529; cv=none; d=google.com; s=arc-20160816; b=OlRODkkuWW/Xc8olL46gL4TDBYdPuc0iGjHrHXW+/5aLBWLUe+HhvwKqSXICnGQuIy 9YSpPiH6zqt8gP+9cQR/Ztf7uxrq3wRYvVoDHigxVfF3mikP0LNkJ4YEzMjS8RJevniT geMbegciLMqQBrVfTggaD2oo6ml//TGNzrvdrWaDY9EHbi5BhAjtzCtqK15orL6HbZ4l s3WqUAzDPFrwYBCxVXv0lcxwKuN50PPTxneGVmo8RRY2JtFfzwNLhFIhzmay9Lb9DJF4 vxSWvvi0VAElOlEEEXWCtfeDRpL37QiarLTLp+/H0KajdPO2qD1kN2No/wxiQmo+Cbl/ ai5w== 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=WklzNBegPgB5uEE+/qy7qfvk7e8XBByJu1huJ3exKM8=; fh=wwXwrWfB/Z9V4A55807K+Da2PDiZgr/hJdfzSSU4SPo=; b=Aa45QazTn0EjQm1ztVb7tml/kN4Rm+eHUlXQ3THALCPCeKrbmo6ovZgBM1OukDl3E1 7MZ5mlRnvBCM8ZLI9yy2harocfpO0DQv8i/stGK4Nv46Y2vPxnpsr3g6Qov9ctdfqPFG 00aMDcdSv8ucLWwz7Zq83uA1WYZkFdlxCwR+IDj4uqJoqLnsTka9CB9LYMCxCaQPYuJq 0iWEo6+J0QVgB8xps0gi4+oUDvyOJsN3PaP0hANhmhfh1ojgc8qgNu/S9Xy9siCoMj53 nORnW7C5ERI/Wa6td/exS9bLD7Fdrl9v+jrQrx3YQ+AISmCNtCbayNCUTrRIDJwaCl77 cKxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ktHr7mrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p20-20020a170902f09400b001c20db25108si2277743pla.41.2023.10.03.16.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:25:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ktHr7mrB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 7532E8313006; Tue, 3 Oct 2023 16:25:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234460AbjJCXZW (ORCPT + 17 others); Tue, 3 Oct 2023 19:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231855AbjJCXZV (ORCPT ); Tue, 3 Oct 2023 19:25:21 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37A1AA6 for ; Tue, 3 Oct 2023 16:25:17 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-692c02adeefso1114597b3a.3 for ; Tue, 03 Oct 2023 16:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696375516; x=1696980316; 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=WklzNBegPgB5uEE+/qy7qfvk7e8XBByJu1huJ3exKM8=; b=ktHr7mrBoOPg3ka7pz2js6pvB4rAKVf1iaLj+EGNax3ASTc8p6stvVbNKPcFPdi+Sx zNjLEIZuQniYAjuyicNUknDkeY8uqicSGDwAs+tBtdn3ihqzWDcV5cS8vBiHBH6sDTs5 ahz2Ven8cFUKH0orHCrAUTILjNaGbySNCHAm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696375516; x=1696980316; 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=WklzNBegPgB5uEE+/qy7qfvk7e8XBByJu1huJ3exKM8=; b=M1GE3X+AlmRZ4Yg264w4D+lObZaXg5ktHv7DIojoZzDR4qizuN0sG1HTlFmLs3FMaJ h+y9MajXrx8W1FsgEKcOoWTHmySjjl6CJDTu1bCTTcz+FRnhCmS9RoZO2P14T7oTR/jN 2isTaWtpAUoJQtAtkgNb6qWDGHM4r7dxPvDW9gVriGeOuhA39uco6SESlSHkPdW0qjmV wUrK8GjHr5/LQm7pYe6XLjpMlJOKbyRFQDLzecUbigdo4dGkRzr32ONojzsuxZZcugLI hDe3X9y6SCS0JqBnxoP/9/iHWZkTFrblr1kE+4iJEns/qEK2OyBZQg7uYojMuwQllvhZ NHAQ== X-Gm-Message-State: AOJu0YyKBqm4G+OmgaPE0kFMdQxBP53pOR9C0SZMba5WrWDWtZ2ymIow vMZPURdwt61aaLuWsWxlPJlgWg== X-Received: by 2002:a05:6a00:1592:b0:68f:cf6f:e212 with SMTP id u18-20020a056a00159200b0068fcf6fe212mr945019pfk.20.1696375516672; Tue, 03 Oct 2023 16:25:16 -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 d8-20020aa78688000000b0068fece22469sm1911902pfo.4.2023.10.03.16.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:25:16 -0700 (PDT) From: Kees Cook To: James Smart Cc: Kees Cook , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , linux-nvme@lists.infradead.org, "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] nvmet-fc: Annotate struct nvmet_fc_tgt_queue with __counted_by Date: Tue, 3 Oct 2023 16:25:11 -0700 Message-Id: <20231003232511.work.459-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1347; i=keescook@chromium.org; h=from:subject:message-id; bh=ByABuAYNlIfLs+7c20JDBpw/8yvTeM5CPvmgxbAXfYw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlHKLXpRHdUq+lFLSfO9gJWqiFNgTu8fSB9J2BJ zZ8tvEohwaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRyi1wAKCRCJcvTf3G3A JgoeEACsVLmbCD8bMb+riXBw2TqwsW891pJ49jgwyOXsxUB/C3ZZ7ENjEQN6LGSkaLdqYzfmWwi YDaW6EbTBn5KcSU1Hw4F1S2hC/yfbryopBQFy7UUPJ1h97vHG1WklXODb15HTcpXnqdzPEExmFI 2XHy7Ynrdw038ZEWiX437eAzH5XQ6D+7IiuBD6qIBDzeXsD6/bfd+vuujGpp7IhVhhhDuEKxeW8 xte4TTr+fKEK5gpyPsViXn0Om67AzEfyUzWP9jm56AzQ44uFSs/BaIvbDhk4pCkaExfdjsLn1hr TnQLubChT6GFHgF1ibh3aQbAWU8JvDFhf0hfOjFO3HaLF0QpoAzjTyfC0LJjZq90mWYCsbujmT2 fB2KG03D9y3Zx8RiEvhC51j18hMf+2VF7qoFhtccckeg48gvmFTFgwUtuXwiM1xQB1YfThnFj+o DH71gvobUcMNBsnE3QIGtog5q6ctnfm3DnLqskdz/HRisn521b6p8EHKrt2f7Ue1x5XfYDQc5dG bog1lOJ/LORrJEZs/cd6yndXzT6vd7boBB5i51/cwGXbSlSA/qTBo4c1Qlhv0U8pJPplNY5ZSx2 jyZXfX8030a4B+JGxqoaiUJjYqySNBjwHDUPVdQA0BmeUkDgeQ3HHlTErvAlLJMwAf9s3Sk+VXC d4vCaB3 AqjDvhAw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 16:25:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778778666809070035 X-GMAIL-MSGID: 1778778666809070035 Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct nvmet_fc_tgt_queue. Cc: James Smart Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Reviewed-by: Chaitanya Kulkarni --- drivers/nvme/target/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 1ab6601fdd5c..0fa2d658cdeb 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -146,7 +146,7 @@ struct nvmet_fc_tgt_queue { struct workqueue_struct *work_q; struct kref ref; struct rcu_head rcu; - struct nvmet_fc_fcp_iod fod[]; /* array of fcp_iods */ + struct nvmet_fc_fcp_iod fod[] __counted_by(sqsize); /* array of fcp_iods */ } __aligned(sizeof(unsigned long long)); struct nvmet_fc_hostport {