From patchwork Fri Sep 15 20:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 140755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1375237vqi; Fri, 15 Sep 2023 16:17:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsB7FCKRett8tBnERHxqpfgVSZLGPhSkKKIn54L4rmpBkb3Df4FYk/B99t0HfIsitBqVSY X-Received: by 2002:a17:90a:6f82:b0:271:8195:8 with SMTP id e2-20020a17090a6f8200b0027181950008mr2845451pjk.36.1694819870045; Fri, 15 Sep 2023 16:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694819870; cv=none; d=google.com; s=arc-20160816; b=OmYbibiNRSKjmtjWZNAPX7dOmtDzrNW88EZrB/B/mp5NlIPNgEFzzFE5nLuNI2zqBA 7dJUXDsRWeWgnErCyXRwNjQ+unnISmEH7dr2udpEoi4TxQLBmwj3ntUk6ohHS7qZ71J7 3Jogqhy8F00FXzA6aSiWm+bq7cNC4b3Yv63F0Vt/FJKojNlGSU8qa98bm6GqHRLFs/WS lZJ4ERKGzncEupcboWj0ZkOlQdGbiaxOtAwUGi4z7cdCQZjVJ1uE+rUqMzOz8meTZxPz 0KqiUJPnV2elPTDMhP9ReG4h6hAcM5HA0aQn8W+PDycP5bFg134+ghyMVNB7gpg+0yFR hhRQ== 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=PsjobygTJTSQG68McAspsAEHf2Z4NWVTVTdDWk+Khno=; fh=8usbhTyLEs+UqinFzzonmw/C95jphrrnd4BsKDJ2VSc=; b=jFZmEsM/PTzNjJWbT6ESr/psaamB+Ks7MzTYHWM3L7d0t/70w8QXWzk+DxAU4/5fVD shs5MaL16CSaFoVklVNVd4Mk4bP13nVyh9K+TzbnTRzuVehbZ8KLcMuTjx3Xqzo51IhF 5ESb/iqXWbn3Ia1c065bBAFAvtogwx0JeWBXPuotw/hTqb/8BqrDs9WwW75jJR3kQOuc o0Ol9o8Xg8yOO5Lw77BXiHkGAeEVBgUDv/I/27TmQJIQS5X+ctERoLM8cbsYm+DAmbo8 kMOn28VwNZEDp/whC+bwmGxkRqRR9MAXj+cUhz6Y+JUjHlnYfxTKkM+trqJ9sidvBDdZ 7X/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KoTE1quK; 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 lx16-20020a17090b4b1000b00271ae22eea7si6792525pjb.117.2023.09.15.16.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:17:50 -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=KoTE1quK; 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 6B641858F7A4; Fri, 15 Sep 2023 13:04:59 -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 S237143AbjIOUEd (ORCPT + 29 others); Fri, 15 Sep 2023 16:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjIOUEO (ORCPT ); Fri, 15 Sep 2023 16:04:14 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2762A211E for ; Fri, 15 Sep 2023 13:04:10 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-68fb2e9ebcdso2112185b3a.2 for ; Fri, 15 Sep 2023 13:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694808249; x=1695413049; 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=PsjobygTJTSQG68McAspsAEHf2Z4NWVTVTdDWk+Khno=; b=KoTE1quKYXTxUzzR2DMXFf/VWipLYTTHWXcfGX80N2k/ae/kNjorndOs6pxEim+F03 Mfjz/qpjjsfeZjgmLxFAFz94ZxHf6hJVvLaSMZIcmD1+lmIuKVx4vRssWYVySNmtRYd8 1l/kZ12MEperk6cF9QP0NWNVma1kccQE6q2WM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694808249; x=1695413049; 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=PsjobygTJTSQG68McAspsAEHf2Z4NWVTVTdDWk+Khno=; b=RfRUKWMd8PmlUw3C8W7uyVRf7jdtR8fUfliIiHvIsjmZ4CcopuClumMS4xrAkw3Bcg fMQPBXyAnMq5gc0FUQA0DWPs6usmIXQjDoe3K4oRp5ZSuyRBZvlykVUrt8ciNiPt0nGM BapCGlO6Gm0JsgbAIDk1U4OQ1mpvGYBE19BvE9KSvhd5bSKHV8m+z4/apavh76HG6Kw4 9HX96zuGTc149Bc4O4h5NRQM99XG47zvwIViE1Z0VVnN0lbSHis6iqYPC+a1uqgMLK92 oGPbVuTAOrAPAC8/UpcN/FH6dpjo1eCx9yiLASzbLWkFsWvWS4kzii9RfZw9mcfiGAUj egeg== X-Gm-Message-State: AOJu0YwaV4YJp1NCt5UZk9pe8RSCZi7jX6NK0hyiZaAyH5tWP53P3MvD xxmO5/8cy4FhU23zr68ru776WQ== X-Received: by 2002:a05:6a00:1882:b0:68b:f3a4:ff6b with SMTP id x2-20020a056a00188200b0068bf3a4ff6bmr3034695pfh.9.1694808249669; Fri, 15 Sep 2023 13:04:09 -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 b5-20020aa78705000000b0067b643b814csm3342707pfo.6.2023.09.15.13.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:04:09 -0700 (PDT) From: Kees Cook To: Alasdair Kergon Cc: Kees Cook , Mike Snitzer , dm-devel@redhat.com, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH] dm: Annotate struct dm_bio_prison with __counted_by Date: Fri, 15 Sep 2023 13:04:08 -0700 Message-Id: <20230915200407.never.611-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1191; i=keescook@chromium.org; h=from:subject:message-id; bh=VvKOCdO6PY/NRn1of9dfjjBTN1ZCPOIIRKyzCXPi3Xs=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlBLi3mSrPQ2k1ngorCbl4cZDSbvlJ0xPRobTs8 GueuwSV7kWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQS4twAKCRCJcvTf3G3A JtYGEACyVAHf3GVlw2Xkm6VuFB0xT82MYq4INcuJ+itoZaCrenWb3tCwhY+fkcq72HKGx/1b+Pv OErce1wHcbokBfk0DlDKQjpwTDQ30Gf5+HVA0pmgtzw+RCZpIaLZJlOwEEQCpEPlny0qSUK0yaI a1yOASH1d+H1/d9KHywGNJM163u97BQe/p66EQPbo3zI5lr9hfB3USLebN3whqkMloLEf/C/YKx mQhVgPhBYsk4XQDWg2qaUl/tPWEreLsObc5Ph5PPVD6lGYBAthn5H4yEqa5aL1Oi1Dcd+k0lmPm /otgAB97W1ZqTCSLxt53qsC/0r7xDwRZjAvSAkr9syY7RXz/3ALTkIhufMhLlhyrhWO/GyqE1QT lb1UTLNeBeXKoaEkiUartdD4xgOObsF3xCEyX5gIvcSVORT+kGYdd7JcsReF/6zy6db+bj22DwY 2BEEgGV673w8FiKlgNdKvDLTeSO7JXALYRZAXEA9acesISfNFIXsG0nVje0xKQddBijW1EvXBdG H3BJrXpWLA6sppNr8YNdgcYczeF1AsmcHZbr1bjN/p4XGobHkFcsET0KbH1xxp2g2FQfJB0Bfvp xT8heKvTGaxyjqe3dVxh3q0znd6p8eHowg2vMIMMimkErAmjMwbC/7t3mSopit/jjHuI7TiZG1g iseMwLp rJU4WzBg== 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=ham 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]); Fri, 15 Sep 2023 13:04:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777147440043649660 X-GMAIL-MSGID: 1777147440043649660 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 checking 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 dm_bio_prison. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Alasdair Kergon Cc: Mike Snitzer Cc: dm-devel@redhat.com Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva --- drivers/md/dm-bio-prison-v1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-bio-prison-v1.c b/drivers/md/dm-bio-prison-v1.c index 92afdca760ae..9ab32abe5ed4 100644 --- a/drivers/md/dm-bio-prison-v1.c +++ b/drivers/md/dm-bio-prison-v1.c @@ -26,7 +26,7 @@ struct prison_region { struct dm_bio_prison { mempool_t cell_pool; unsigned int num_locks; - struct prison_region regions[]; + struct prison_region regions[] __counted_by(num_locks); }; static struct kmem_cache *_cell_cache;