Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp351282rdh; Sat, 23 Sep 2023 13:22:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBroF/yWqXV8/LcbUXljT3oKb0o0bGMu34Zp6d9SSns7VOXLm9WsCBC/l0r1MH4hT8Fb7l X-Received: by 2002:a05:6871:72a:b0:1d6:5c40:11b6 with SMTP id f42-20020a056871072a00b001d65c4011b6mr4209407oap.14.1695500523101; Sat, 23 Sep 2023 13:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695500523; cv=none; d=google.com; s=arc-20160816; b=F3XkO4acuTmSREV1ENMZQdrLXe9MeA8BQSBtc/DIBJGUCdb+njBUFi50Ua7BirwGbU uctrGndWEkqEi2eYGZBzzAgAOjAhN+gDHLn0+Ui9wgBz+WgxPj/OOFW9qhjzLAF/Pr9U l7npVJeWa/TbfBcuaUiYVxyqpdaclHXUmpa6rXBU/LIAkSrPJY2QR+ToTCDdMS+oKzZZ 5gtVoddStu3Xp9QkWc9jdFVoPvkKArpLcpfhATZJUHlaBoU2viQOuDZSEAuRorxKjufW 8bj1MPKf4CrmaCniGj0nrSfim808LO1FUzrFsfOfrvfHcJVkmqerwrX1ndM0KyfJIafq AxFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=95dquq9h2fN9ttOm7akqcNo5sL0dJDCKRHu0Vev7ugY=; fh=4PXVvEQ8LSu7dLCrrQ05edLeBrL4APWpKh0jLupKJgM=; b=LHH41BGoX9Ch5wk606JJD8u0btaB45AyA795ar8aWtbOMgRq5qKlLkNuEc5zrymMVi GHytrasFtHxLzB8RVZ21cFEuA63AMDzI3aLXfRV++jWpyweD0R521VNDprNSkKpW1H5J /PTEXrH///NtGSPWUSgD8VV9cmwhCSX/hAxAGNSSq5r28WpCDA0B9nHoqOc/Th1IIcLP X29y9E+g3CpMuJnbv0MbhY5wzLL7WIKE4g94tz/Bcw130ele+Fc1dUjjMC0+9Ab3nq4X tb0ay5YCVuHz7iC70DkxPM0XFASdJ5ESRAI8lka/7+Aa+m7d2taQivurZAOLEEs+Ntjg WrwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=yULlmJmg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q22-20020a056a00151600b0068fbac77dd0si6791888pfu.226.2023.09.23.13.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 13:22:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=yULlmJmg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D350B81A9ED1; Sat, 23 Sep 2023 13:21:59 -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 S229618AbjIWUVt (ORCPT + 99 others); Sat, 23 Sep 2023 16:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbjIWUVs (ORCPT ); Sat, 23 Sep 2023 16:21:48 -0400 Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFD65113; Sat, 23 Sep 2023 13:21:41 -0700 (PDT) Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTP id k7QFqca4rDKaKk98GqKDwv; Sat, 23 Sep 2023 20:21:41 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id k98GqBLo1TrtRk98GqJM3Z; Sat, 23 Sep 2023 20:21:40 +0000 X-Authority-Analysis: v=2.4 cv=Yucc+qUX c=1 sm=1 tr=0 ts=650f48d4 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=P7XfKmiOJ4/qXqHZrN7ymg==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=zNV7Rl7Rt7sA:10 a=wYkD_t78qR0A:10 a=NEAV23lmAAAA:8 a=KKAkSRfTAAAA:8 a=VwQbUJbxAAAA:8 a=cm27Pg_UAAAA:8 a=qjWHau5h7Oqj65Zv8QkA:9 a=QEXdDO2ut3YA:10 a=cvBusfyB2V15izCimMoJ:22 a=AjGcO6oz07-iQ99wixmX:22 a=xmb-EsYY8bH0VWELuYED:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=95dquq9h2fN9ttOm7akqcNo5sL0dJDCKRHu0Vev7ugY=; b=yULlmJmgkB+IxpSPQpy3qXxdhz dyiFkumbRtx2AUY/ANfZXCOI5MWyrQEPKMdJNSIATkhcknr0EaGLPGaL+EloWXqE0h+xY6KP9roRK CF3tYyyTudvGcSL30NPHWD6QRW0SaMzMDrMD7nHNPaSXT9eg6MznAJN8A93MPXbbtCDAEpPHBkDk1 cUdiNOqbiGVttZfV41cgPNBMvA7GoOT4VfnsOHMGzCB08sYTQ0WIwxfeYfP5jzP4iTVkjq1o3rKG5 rvdUXGRRFdTZtqAIvBVK32dXTisrbYLbrJ7uoNR2A80eACWCjT45nJHMEY+UuZ+mqwZ8kwhRhn5Yt WvW+jXUA==; Received: from [94.239.20.48] (port=52998 helo=[192.168.1.98]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1qjy55-003czm-1R; Sat, 23 Sep 2023 03:33:39 -0500 Message-ID: Date: Sat, 23 Sep 2023 10:34:44 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] gpiolib: cdev: Annotate struct linereq with __counted_by Content-Language: en-US To: Kees Cook , Linus Walleij Cc: Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org References: <20230922175203.work.760-kees@kernel.org> From: "Gustavo A. R. Silva" In-Reply-To: <20230922175203.work.760-kees@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 94.239.20.48 X-Source-L: No X-Exim-ID: 1qjy55-003czm-1R X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.98]) [94.239.20.48]:52998 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 0 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfAZ1ITLoOpQAUiPweuVFExqrmbpzyNOuMc55pWHHPbsvPsFM2aYMTFNed9avpToUiBmpzoL+VGrJmOt4ae2D93ZapPxrjlugh455P9YM1dHo0mMupNEP wdyzenrEEISL5I7bbymxJiAcV7VpCaWakrl0DY0W8jDpY0+bUcOQrH4362Su4+wD0mRU3Kyh6++dCf9sRoCxJjY2EX7KC5pDSYQubcxJmfP7ehOhzsXbZdnV FfJc8zZV5UWHN0wL2zwDjCIiVB3Bwq1h6mkueyD888lvL4cxzl6YMAdrrEk+Xdcrmq9uAR97FsdM/+E3bKwe6w== X-Spam-Status: No, score=-0.9 required=5.0 tests=DATE_IN_PAST_03_06, DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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]); Sat, 23 Sep 2023 13:22:00 -0700 (PDT) On 9/22/23 11:52, Kees Cook wrote: > 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 linereq. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Linus Walleij > Cc: Bartosz Golaszewski > Cc: Andy Shevchenko > Cc: linux-gpio@vger.kernel.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/gpio/gpiolib-cdev.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c > index e39d344feb28..31fc71a612c2 100644 > --- a/drivers/gpio/gpiolib-cdev.c > +++ b/drivers/gpio/gpiolib-cdev.c > @@ -572,7 +572,7 @@ struct linereq { > DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event); > atomic_t seqno; > struct mutex config_mutex; > - struct line lines[]; > + struct line lines[] __counted_by(num_lines); > }; > > #define GPIO_V2_LINE_BIAS_FLAGS \ > @@ -1656,6 +1656,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) > lr = kzalloc(struct_size(lr, lines, ulr.num_lines), GFP_KERNEL); > if (!lr) > return -ENOMEM; > + lr->num_lines = ulr.num_lines; > > lr->gdev = gpio_device_get(gdev); > > @@ -1684,7 +1685,6 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) > lr->event_buffer_size = GPIO_V2_LINES_MAX * 16; > > atomic_set(&lr->seqno, 0); > - lr->num_lines = ulr.num_lines; > > /* Request each GPIO */ > for (i = 0; i < ulr.num_lines; i++) {