From patchwork Fri Sep 15 20:14:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 140728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1350499vqi; Fri, 15 Sep 2023 15:16:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlZF2zHDEEy52Q/zlmW3n3Tf3TGNWUWIcZL78NU+mGij+wxCPQbg8TuXI3UtLloC2Xd8I7 X-Received: by 2002:a05:6a21:3b48:b0:155:bff3:ea1a with SMTP id zy8-20020a056a213b4800b00155bff3ea1amr3426048pzb.33.1694816174241; Fri, 15 Sep 2023 15:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694816174; cv=none; d=google.com; s=arc-20160816; b=H8aBsp4AICElGUUz0V3SiKZTXvDW775fF0D603wSfQxawU1qPXSj9upMDP+5yDzmp0 7RUSXrpOePL47e2NQYZfmaXP3fIOGf5UtaRJxg6cmlUVsd/IhLZO7nBDWYeFQJ5kaiPN UUyNQmN4EVuI7MtqjWPdccoCHxIlLzJiyBzHYGGUK3eqyxpjxvdJpTM73cR7iX+J6he5 Hy0lsTG7f4F6yvzp1iK6HCVY+CGKXA8Y9Y6R6BEWcR3CdbYMgbHKHH/owFheXzm5Ajeg ENtuDoRGK1+ui743PnOkM4jlOsmbtxuwtHhUToWRJPrMw8QXoS8ks593h00Lu34SCXme jf9g== 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=2adzcEiFT17X0tMOdRHOC+4xSYu7V9ABPtDWz0mCD/0=; fh=qj4kMxQX3K/pw92ApNdYfKDtWuFw5gVsGoXB01KcsUI=; b=VbGLUtHL+kfIiISzlf2kq19PP4m/QvdiYEZehzcR47rp4wqrwHHyzrJKcofK2keblR yTUjqm0tUIxJfHmCpuTi+qLQXmzlx/i8ewo2PUCp2z7PUB8PTcke0uVvSZ6UiJAvIHZe 7vAJ83q3nPYFkMjiLCfStXJx5OfAk/xJVt/u+FgeOuqC7zEBSS0WZmLVK+0ZpoIMnwmU iO/fOV2v8pjtM7vy9eyx2f0bBK0T8y/uyAZOIbbzwZr5oXuckCEwWHUh3ir+UEfRIrA8 aakES5Ld7mqZPc7fUIu+1d/v+zpaozvnxgjNZpyUWx4vYy6rAcWC9dmxkOudL5224w00 L8PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=J+2qPFbR; 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 bu15-20020a63294f000000b00574166b7d34si3851261pgb.881.2023.09.15.15.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:16:14 -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=J+2qPFbR; 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 8CBDD8293C9A; Fri, 15 Sep 2023 13:18:22 -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 S237176AbjIOURu (ORCPT + 29 others); Fri, 15 Sep 2023 16:17:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237292AbjIOURZ (ORCPT ); Fri, 15 Sep 2023 16:17:25 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA173A89 for ; Fri, 15 Sep 2023 13:14:58 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c3cbfa40d6so22852155ad.1 for ; Fri, 15 Sep 2023 13:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694808898; x=1695413698; 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=2adzcEiFT17X0tMOdRHOC+4xSYu7V9ABPtDWz0mCD/0=; b=J+2qPFbR6NPi/lK36YaaEC2g7PZyp9zwCLefboI4JRP0GTtDspwegZ299UymSfEEdx VTHlzOOOtOfXoj6QW6He9icCoRrS6Ln/09oAgHTFyIqNxUIWu+M4gIdgddj+iIzMdf5x Hm7ZAVdXwNz1FhWIfw2ZTfpDx/QYeunL3e1Uo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694808898; x=1695413698; 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=2adzcEiFT17X0tMOdRHOC+4xSYu7V9ABPtDWz0mCD/0=; b=HaOPSB4En8aruEM4T5JEPw6CpIw7tPCKzbGmv4tfguqhpfmsDTmUmeW1wDw8TzBOIF R8D3KpVYKGA0Z/blqdKnf6692Vea0daueGSvIi0bOI05mlgCJATw3fKkyD9HhrVQKrQP zcx1VfFArp9zKOM4+Osvhs5FHIW8N97wTWclt+7lLW3SKIPvpdpsYASSeSamlC094LPA vaoacuw7sW7Y2bKU8azIhvSlPbogVLONzb0HXabjBXZmVZWtITaE7iiIE+kdh0WXW9nI zn8Z2QQmNEJILuW4kbiwdsWGaHAUQRJ/rHFlg0iVWxrnz9Vy3UNKSwhm6SsmKwj8N/Tp Cz/Q== X-Gm-Message-State: AOJu0Yzzznq5YK3uFU0tjcdBHPRihXKf4K2gfGNJX+YY9nELrtO/KH1Z 468JHk0UzBTQEYp1bIy+X1gpEA== X-Received: by 2002:a17:902:e882:b0:1bf:11ce:c6ae with SMTP id w2-20020a170902e88200b001bf11cec6aemr3250482plg.18.1694808898073; Fri, 15 Sep 2023 13:14:58 -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 d2-20020a170902654200b001c43307f87asm1837631pln.91.2023.09.15.13.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:14:57 -0700 (PDT) From: Kees Cook To: David Howells Cc: Kees Cook , Marc Dionne , linux-afs@lists.infradead.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH] afs: Annotate struct afs_permits with __counted_by Date: Fri, 15 Sep 2023 13:14:56 -0700 Message-Id: <20230915201456.never.529-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1254; i=keescook@chromium.org; h=from:subject:message-id; bh=C30Tpce9LuvDnPhShi9VewRUfa54HHSLTSiinU7ab60=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlBLtASGYM643odAtTW+2uVzG0JxIaa//Ye+Bts GG3+SOU75WJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQS7QAAKCRCJcvTf3G3A JmQ5D/939BFdVcrl8LsWHb25cdDVwqzcQu0ePiQa21qI3gkIx7d/C8DZ2qrX3QrHPyxnky+ufgQ 9Zl9fn6bdqHc6imsnBAAkRegAyTuYMtUmp6zi8w2Bzf9dT8r/xuT8GtAkMlo336a7xveH3luRbO MTr9lMWq4ZJ3GCh0FTdJmckVsF1hybn6tpSNZL4Y/I+pDLjDduYV0/VAwzRB5SWlre0mug2WBNk XgGKTUWr6zml7tQhaxlp2r8rgMuLcQTuwTty++KM6qyaDw4HNfJ5wfSF9UDjeJHS489LFQbaKMf JD0csUlqzQK9Azl1Fqed6jTMZL4924e8MnjWmZD7SgMa2mzDlFzDMenajpdoBypMvFqQwQKAXwo X4BSZvbaAg22gLUsQHDBNNqKLkhjYfvhE7AvGLCXu+f1m7P0zrjNKuX2YoEnYrj1M+n3+AJCO3j ix5OuhOhpXAJNFqJsHsVoS62xM2i4ui5ZpF9HMLGUNANCkwQeTKYk69PXhuZIu0M4aEfDKphuBt KMJdwM3G8URutOHI00MxVT7g14ZllYBBq5BmjfNgn8YKUPI+iARkBV+anvIM3LIKGKsU48jFCH9 2y3kY1IkkyCqw+M212bqRFmBVg18HbLa4Q0zv7sPzuZUf2DdSubfdtYc/RRjRx3oKgnwxo90i8o ZlTc3RO ZPK5Fl1w== 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:18:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777139094426128769 X-GMAIL-MSGID: 1777143564639875290 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 afs_permits. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: David Howells Cc: Marc Dionne Cc: linux-afs@lists.infradead.org Signed-off-by: Kees Cook --- fs/afs/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 07433a5349ca..469a717467a4 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -705,7 +705,7 @@ struct afs_permits { refcount_t usage; unsigned short nr_permits; /* Number of records */ bool invalidated; /* Invalidated due to key change */ - struct afs_permit permits[]; /* List of permits sorted by key pointer */ + struct afs_permit permits[] __counted_by(nr_permits); /* List of permits sorted by key pointer */ }; /*