From patchwork Fri Sep 22 17:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 725660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E26B2CD484A for ; Fri, 22 Sep 2023 17:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233558AbjIVRu7 (ORCPT ); Fri, 22 Sep 2023 13:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233449AbjIVRuk (ORCPT ); Fri, 22 Sep 2023 13:50:40 -0400 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C61D1CEB for ; Fri, 22 Sep 2023 10:50:30 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6bd0a0a6766so1469660a34.2 for ; Fri, 22 Sep 2023 10:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695405030; x=1696009830; 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=xrtz1QFozDlH3/nit7ZF/0eGtthYpeLrLWIW05kvAAU=; b=IMXDEBxnsaoQverSML88+YIa9U0dITWZMpQV6p926fsOeKkYDacRG2xvvE8WznPdtf T07tmv4/5XQQWMy27COlE73HHXenLBz3kw9/effXmqybZC20Y3dlPHyzGJ6aPo2sj/oX XeqT0Sy2jQe1p534FTUKFiXzzRnQUk9xfum4k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695405030; x=1696009830; 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=xrtz1QFozDlH3/nit7ZF/0eGtthYpeLrLWIW05kvAAU=; b=cYDNrENpMONE3/P2CJy3kQAHmiu2N8vGsoAl+03F3/MukzWWr8ItXxzXbZinZOQ1X8 omWA3chvN/JxVJV84ZEpdyNjKF2Pxqo9WrlRSYZCXGwBDwdJhxA+CvwLjfwYMWTrRJIy eI0KdiZe/gjvmcfOxsZnmcVxwnXNMs/jeA+qoSmGPXIa+wi59TJNaUt31x+SGtaitLRn ViP/PCbVpO4mvnZNnCp9rstgMypfplWDPMBEIxyv30a+Zf4+N/3rlKLRgR0/c1+2ENXK ilYhzdXVpAOJNVUN+NHMGDV2t0iSu5uLwBZmLER7eCxaflig9mpoh6BAGGfAsruYkDN8 Mycw== X-Gm-Message-State: AOJu0YxBM8VZeQEQf49EUVU4AvzYFCoCV3fJxWS0cNqfYReEZsQnX+C1 nGlcgqIMoZyyBIVxJRZN2RKHYQ== X-Google-Smtp-Source: AGHT+IFJh95YQOZBveM2XcPw/CDPZ/6OICivEFtPWMcL1XwnDyu10HsC/gAgnWiCOFnG1qMx0vCAUw== X-Received: by 2002:a05:6358:27aa:b0:143:8f7f:9150 with SMTP id l42-20020a05635827aa00b001438f7f9150mr360342rwb.13.1695405029982; Fri, 22 Sep 2023 10:50:29 -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 a8-20020a637f08000000b0057d86bb613esm1259916pgd.45.2023.09.22.10.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:50:29 -0700 (PDT) From: Kees Cook To: Dmitry Torokhov Cc: Kees Cook , linux-input@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH] input: Annotate struct evdev_client with __counted_by Date: Fri, 22 Sep 2023 10:50:28 -0700 Message-Id: <20230922175027.work.563-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1135; i=keescook@chromium.org; h=from:subject:message-id; bh=F0Z7qk8WbE9IhwsU20RzqLTm540D9AV3CzIu9FIos2Y=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDdPjfCweOYJ24fK5QO6nd0/ZcLHSx0EiqUyvr m1XcXMHLxKJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3T4wAKCRCJcvTf3G3A JuesEACmgZ7LJ7hzGTmPk4sjXyOwzvRHjPW7AZ5lnEZqS5CAf9LyiS/rXgpw4uGU0ZlR9/CYbEC CoG8fsG7pB7gqgEu+NyGT9wlhpWFp6gEr6LfIQoq5h5QG/BygRUsRAPA/SWjJD3/Ph7SOLMAthq YzsNXZCD0QXwzCICFZ3BnDqiEzau7j3WjNxIARgkVUr2kY0JPd8lBQIvE6GqVClHP01tLiqgbj2 5ZnsuWA2Yb1kkZwfTi3En34dulyGlkwl3NtYmcmSdo8iAbUpkdXL8QnJGhQHlGXh88gYummzjLi ebj7or4i8/Fwsq95c43QxcBdyguuKr/+HubKfvjT8V07aVfNhZdeuodMDCGre8CW2Qpb8r3UjH8 zHemjDdNd16/u6fth2UHJlUt9kF8FoEeiJl+1J11VoqdmPPsfuuuwRCbwB8hK5djmvGay2y5AYi unBmV/C0AKdGP6XZgGhB6mXao3Y6KX6DtdXL0PG0VH1Ukl3iNSBzwRz1IpRmxf0q2ACOq0ZWGO6 BSgRbAWiyvuc+ZG+Sw3zFqBiGE4bc+HoxW5XYUQe+GLkuiTipuB7Xwj8RVc2O45B+6KS4qKgWgg wt1WodmF7XKHVB615egh8bmJrV/8mlbZ16PU0UmnL2BmHymc/BqC7MEHjM9RTvqdMwnmkTFn2/G bT1zU6M 23OjgTHg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 evdev_client. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Dmitry Torokhov Cc: linux-input@vger.kernel.org Signed-off-by: Kees Cook --- drivers/input/evdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 95f90699d2b1..51e0c4954600 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -50,7 +50,7 @@ struct evdev_client { bool revoked; unsigned long *evmasks[EV_CNT]; unsigned int bufsize; - struct input_event buffer[]; + struct input_event buffer[] __counted_by(bufsize); }; static size_t evdev_get_mask_cnt(unsigned int type)