From patchwork Fri Sep 15 20:03:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 140660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1291948vqi; Fri, 15 Sep 2023 13:07:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPYwNeJJqffvtIFRcUUSwTHG0HPmW5sJvNwwZS1fowhH9i7lk/wk2q2xG1e0IHsVTZEIse X-Received: by 2002:a17:90b:1481:b0:26b:1364:e784 with SMTP id js1-20020a17090b148100b0026b1364e784mr2474887pjb.0.1694808465214; Fri, 15 Sep 2023 13:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694808465; cv=none; d=google.com; s=arc-20160816; b=oF0k3U+JpUnNeXWtoP39KNvbkIw47z9adE8e7hOLksZwNDEkOMdQTP+OpkA3IFQVPR GmPSi7zvtHjKO0XZKFHypSUD2Nk6ivHJheFoSbZvD8I9VH7wxvPTSbBslFYMQfP+qfR6 G3kzt65SJwcGU1XSauvNZqjARiagMpkxbhExSnNrySnqa6Aym4ZbDHDN2cA34+KJKJZF 4sB98qRrV3rARyMT/wcInU441d+x697EuddrNNKhSU4tQXOnnRhAq+jWhISdQuxeBhGi kZyWzr1Y6Z8muNiu/dfn9oZ+1FEPqvg9NMDnUXP+jDOn4DIMzEzuGYYtFRt74IUZiSxL NZww== 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=3EcXc4p/OZvjhpZjniZGrlHnagHBjkD/G1KmRx4RQEY=; fh=8usbhTyLEs+UqinFzzonmw/C95jphrrnd4BsKDJ2VSc=; b=EfS58M7kJzvruNALgjY4VLyp/Zm+UOXWZjAsE5mr3YOR24xG1b639lavBnM6gbwRGr BhYMU9j4zWd9LuUxzMYBJJvE4U2fqvxgPbeX8IPhXDV8zAIXpqUQ5CNk3D3Mw6mp19mE hBX2S4s7zvq14iC2e26/+CHFYlLaYR9wRMXgwjjiz1DrRMlgGBAmVVAY5VYHGVVnp9Ok hFk9hqnhnebyGVmnGl+5DBUoMAj/mxX7M6VPH2lqhXXOPssrXayxEdN+fIVLE3z18/t4 KemVr6/nMflQrN+Nx3CSc7oY/lBaPgM0f6XbQEoirthC5VnJ+kdbNH1Em+DqSMDpuPPA MskA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jT8lZjJC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id k14-20020a17090a3cce00b002682c370e32si3758556pjd.188.2023.09.15.13.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jT8lZjJC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id DEC618037A89; Fri, 15 Sep 2023 13:04:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237082AbjIOUD5 (ORCPT + 29 others); Fri, 15 Sep 2023 16:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237041AbjIOUDn (ORCPT ); Fri, 15 Sep 2023 16:03:43 -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 7BAA1210A for ; Fri, 15 Sep 2023 13:03:38 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6903a452dfaso1633265b3a.2 for ; Fri, 15 Sep 2023 13:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694808218; x=1695413018; 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=3EcXc4p/OZvjhpZjniZGrlHnagHBjkD/G1KmRx4RQEY=; b=jT8lZjJCcZqVhHUwizdtyoVnVc78HbfOU9IVFwERDHo5TXyehvzwP7RJaSGox5v+eE d4FiIH+hc+uml8FJ5B056JSEv6oCg0ph0qV8cjjnHWl5BE5+bmWGbGLBIesYITE3mzaQ 1w0D0btWIfx/+JorE7BAawMZK//2uwXUkVvWM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694808218; x=1695413018; 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=3EcXc4p/OZvjhpZjniZGrlHnagHBjkD/G1KmRx4RQEY=; b=J77EeoA3/sIn/ShiFTROe8h/gc5l7MzAUDHrfkyQTQZFKXOPWT259YqqnUxF7SfqE1 5v4xLPQDeHWIeNkc/xkz/EXGgVa9syLq2zvN0/wXgtC8QKKDAv6c0G+ckKEr6x3vBhC5 l4qOaXhlzkaOqVqkS2eMAhfr4FGp2zc1rhMrT9WMywaRzV0v/sVenK+6cY+1D6LPNAaG oFXVsgcsrIh1RpZBXAACLjVyWKf5dUSLO++38NJWx3TXpTCZLt7Kmm51XmnRyNTbwGfu 0FzgEQjxvi8Ry7RIc3ynv4St85L+oI9q5WAF2QEyjslqqwrc8TdVFfnAzXXKr9V0F/e2 gv8g== X-Gm-Message-State: AOJu0YxAGrZ7RhKaQ6DOiEm8sYh2JRKi0agRFlXEMR5mzIz59J+1UvjE KCgpVGLerqRpQ8bw7cXswqoe6w== X-Received: by 2002:a05:6a00:c90:b0:68f:e0f0:85f4 with SMTP id a16-20020a056a000c9000b0068fe0f085f4mr2391932pfv.25.1694808218030; Fri, 15 Sep 2023 13:03:38 -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 q15-20020a62e10f000000b00682c1db7551sm3307074pfh.49.2023.09.15.13.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:03:37 -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 raid: Annotate struct raid_set with __counted_by Date: Fri, 15 Sep 2023 13:03:36 -0700 Message-Id: <20230915200335.never.098-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1112; i=keescook@chromium.org; h=from:subject:message-id; bh=3ZvYiEsZZa56aKWu6y0PnTbRMpo38Aw/L94IEjhb4Tc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlBLiYTyy1xh5VON0ySJo9kFErTAbQFWQI95vz1 9vW2hZ7e5yJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQS4mAAKCRCJcvTf3G3A JplJD/9wyOg+Xy09KCd38SWSRoERMIlg+91bNOk9bfpY2aBh3lv91ulrX53nyRunUA02GCG0EfT KAEZKI/2vR7K3DBBGzndXE8/eZki/GOdVUVAeIotscDIQCswSFeVrPWcOV3gTKNHmwDOJNqOhae PXNwG5Fgv7FNEY68jEyyJq4BJdATKz4lEL2woZ62IGNRNGGyUT3Q6evSPpB9naGIxdq7i7gJLHa gmgONPB6bRaS7U+Q5O3fAbI/UjYhNV6MUMaAZ/6yxpkewG6Hb5yTuQ2/YXGsq+XrBOs39PS5vNe CQHDFiZIzLg+vEWzFlW91THnSxrlYY2q6TLb0Me7nkxnaPKsKFuFzwL9rq25nET6JP8hINETJqP sKfWeuhy321LLzTGS0XNBrP4VFsDkLPcCtHrp7CfWyeiXBKQrr42xZF+wKEuBTjbW0PEgo7bQjl bT6fQJjM95fDf2EJQOHoz5ttA5z/PHK5QF973oyfgK6eq7AzwKyj9oFFf4Y4GF9wu+Z/PNq04hS D2n58sWCRuH4/7eJMNIl5O5bAZATtf3lObXLRtL5OJXZq58zG/uMp1o40da7W/RtbTMPq3Hc2uT XGJPSvkjpqXA3X/A86g6vAHjsFuoJZce8yvX4diqSLCWDA+NivlRwzcXDgEyaPnbMxxonfsAsaT K5u/Ioo p9oiGWzQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 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 lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:04:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777135481146181084 X-GMAIL-MSGID: 1777135481146181084 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 raid_set. [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-raid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index 5f9991765f27..9755788e8b78 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -254,7 +254,7 @@ struct raid_set { int mode; } journal_dev; - struct raid_dev dev[]; + struct raid_dev dev[] __counted_by(raid_disks); }; static void rs_config_backup(struct raid_set *rs, struct rs_layout *l)