Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp107904rdb; Thu, 16 Nov 2023 13:18:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzxGIV6jsnajaFeRlInnIAHZ0DbAT8WO1ibYa/zJvux8FMyVOtKzZPtmryPJxfdyb27EI3 X-Received: by 2002:a17:90b:33c3:b0:27f:bd9e:5a19 with SMTP id lk3-20020a17090b33c300b0027fbd9e5a19mr14540758pjb.25.1700169508061; Thu, 16 Nov 2023 13:18:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700169508; cv=none; d=google.com; s=arc-20160816; b=XPS6G5lpNuiWd7jUsASgNWriXN2mHrlCIdfUhtCsJkG/wcDQFDfFTE+pHL9ALB5CSX oaRYMd2QTurW2H40czoHejkSGycVNqtVltsYKfBROASOXSDwT9MhzKoFTk4VO2Z7BMJe TDxKfvwgWANyDzEykZfPY15qEwTA722PwRfvcVeS7KuAfla2Qn9EcQk9HjDuOpYBi6NS XHm4Wu9bEyb41Gm64EyBz7bJaKAFlCyPiSfEM0fTWp05Z4E4idKXlAA9Op4A9LNrcsH/ WMNNkAqt92kOxxTU+F7wk9Hwz0+guZZZFGO0f1SliYS6kUqrGzBFzM82B+Hd/WKvoAqt p35w== 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=z7VN5fe7q4a712jMshNesYxaBgFBwUjNIQyqspWv/5g=; fh=O8AtaQJw2m4DcvkybWOeKZJ2Jw86m/nCpoj1eQM/Ofg=; b=WWtP2vmjcxIs+wFCzZ+jE4tyjxAdPw/gxovoGhCC810BV4STo5UFHsyNmGteQbVUaF xX1aDnRSsqDRmBDYJsWtUq/2U753n8b2PyKG2J+NqLdPsGEmcGxSKXHF0qOJ9HUAaNLg VgcZHUL/wYtIDPGy1VZZRTLL05LHCSFWeXItaLnqHpua46RkY0oHr4+BuxVrc5RQih5M ogjIkCrTUmcCSRCTOP75JDloujCm7wn9lomtJidN5L1AEMo1/55sk5HEN2v+cFI7tTN4 KbiUO4gcRR5LDZQnBtyIJ7L0t63qK8DJt3vIS/zQV+bBYD6e+IBmEkXYKJDFjqxjh8Br GtCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=V2mSew9F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id s4-20020a17090aad8400b002774ecb2ecdsi368927pjq.19.2023.11.16.13.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 13:18:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=V2mSew9F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 8D24C8098400; Thu, 16 Nov 2023 13:18:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbjKPVSK (ORCPT + 99 others); Thu, 16 Nov 2023 16:18:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKPVSI (ORCPT ); Thu, 16 Nov 2023 16:18:08 -0500 Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0D96B9 for ; Thu, 16 Nov 2023 13:18:04 -0800 (PST) Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id 3iLLrNqTFhqFd3jkSr5nKw; Thu, 16 Nov 2023 21:18:04 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id 3jkQrgEipqmEo3jkRrG6YD; Thu, 16 Nov 2023 21:18:03 +0000 X-Authority-Analysis: v=2.4 cv=P+8pOwMu c=1 sm=1 tr=0 ts=6556870b a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=WzbPXH4gqzPVN0x6HrNMNA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=cm27Pg_UAAAA:8 a=CB8ylYM2jayAzffc3msA:9 a=QEXdDO2ut3YA:10 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=z7VN5fe7q4a712jMshNesYxaBgFBwUjNIQyqspWv/5g=; b=V2mSew9FN/FY6qQBitJwrrvBWx egEJQgRKNQ7oQeoB7qzWxi8d7kDHxlcUi0laaO2uapZQn1kqX2BBhTuOi5F4Tm1aVGZ///ZTEBIao Zh/9FlQMbAc5oKvjMx5lRbCAdB+GQfj+t/RPy7NAAdcTj65yoaW+AQZux7QGhiM2s/ucnU+mF+3z+ JTPf+oMEbE+dSkC9/CC7yC60ER+wwtRdBh5f5C6GiCKEL9ShkfsLWGLLDvIDu7UZEueYdMMjrGHMV iUzAPggDiCKVY9wEC7EZT+XUCLgALD3ao9CrAMpXLZ8Ozkouxq5sF5oqVWqvDaES2kJK2fHq/02iM H5a+KsZQ==; Received: from 187-162-21-192.static.axtel.net ([187.162.21.192]:48450 helo=[192.168.15.10]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1r3jkQ-00371x-0t; Thu, 16 Nov 2023 15:18:02 -0600 Message-ID: <43bf5965-84c4-420e-91fc-7a0973c27d76@embeddedor.com> Date: Thu, 16 Nov 2023 15:18:00 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by Content-Language: en-US To: Kees Cook , "Gustavo A. R. Silva" Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <202311161307.9422E1896B@keescook> From: "Gustavo A. R. Silva" In-Reply-To: <202311161307.9422E1896B@keescook> 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: 187.162.21.192 X-Source-L: No X-Exim-ID: 1r3jkQ-00371x-0t X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-21-192.static.axtel.net ([192.168.15.10]) [187.162.21.192]:48450 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfAcLnDMmgxzRLU4mh3fQdQxBQ3YekV4tEcRdA0IBDtPlUnZ/tRwC3W375iLwMX/SSSri99O8TIZFdh9zLz2HbPCDfw1qWjGElFCq2lv3peQJiG84c1sO WUdsrB5lS6xLGAmjasxzvPvvUHOcRDT4x6dNW8ATxLRfAEejzVhXViINXDAUMd/WwUIvpMWbub+evvW5ggxRVaQMUnehUoqf/iJUqZgU+wcoy1BiOIHQd/Yn X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 16 Nov 2023 13:18:16 -0800 (PST) On 11/16/23 15:08, Kees Cook wrote: > On Thu, Nov 16, 2023 at 12:54:59PM -0600, Gustavo A. R. Silva wrote: >> Fake flexible arrays (zero-length and one-element arrays) are deprecated, >> and should be replaced by flexible-array members. So, replace >> zero-length array with a flexible-array member in `struct >> privcmd_kernel_ioreq`. >> >> Also annotate array `ports` with `__counted_by()` to 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 via `CONFIG_UBSAN_BOUNDS` (for array >> indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions). >> >> This fixes multiple -Warray-bounds warnings: >> drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] >> drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] >> drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] >> drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] >> drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] >> >> This results in no differences in binary output. >> >> Signed-off-by: Gustavo A. R. Silva > > Looks right to me. I can see the allocation: Yep, I always check for that; in particular, the 'counter' assignment. :) Do you want me to mention it in the changelog text? > > size = struct_size(kioreq, ports, ioeventfd->vcpus); > kioreq = kzalloc(size, GFP_KERNEL); > if (!kioreq) > return ERR_PTR(-ENOMEM); > > kioreq->dom = ioeventfd->dom; > kioreq->vcpus = ioeventfd->vcpus; > > > Reviewed-by: Kees Cook Thanks! -- Gustavo