Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2722163rwi; Fri, 28 Oct 2022 10:22:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7GkYi4je8ffn0VlSO6j8JRq2erAl+yF/QuL8ptJaFz+e+Z47EAkDmvxWyG8+qT5Eudwppp X-Received: by 2002:a05:6402:344:b0:461:7d4:9c9 with SMTP id r4-20020a056402034400b0046107d409c9mr478653edw.141.1666977720889; Fri, 28 Oct 2022 10:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666977720; cv=none; d=google.com; s=arc-20160816; b=ONceewyXLkoJtJhERP3qhHdRLv7wHB8JmUpdWPpASU/YblRoWddz3M8U09JKjw88rB tK/FtthSepDqcRhv6SfKdenP4O0gOkeH3dwQBvz239FPCt+qWW73DxKH5Fy8ivaDiddr WQyT8fFnm2udOEZuG/mDhH7Nxh5GxC6bSMBafbcIw0dQJ2wKnC8XwEF/mzWUv8TtgmKE twzA24pihDhnZdGYR4VYi7FIXh3Mxi2X0pVxCQMPVaepLeISmvFYB9p5/OeZUPsMkVIh HvCM4uj3KkOpiTMzYXhJ0wtbXWdPUbUSPXKrXPOTjv2muwD5ewGYQIAYvm/QMH1u/LrX CAnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=fiP/gtk1BinFFJgTXUZEj1NdMWlthKZ0OUfBLn7rLIU=; b=QO/2Ba2YH7D4ZTNdtSV9Sq70quPSkW0vvGI+fvV3JqYTouj0etKYCAg6V92LYy6EkE azHVY1FBvev5iqUVrEO5/bwy+yLDTCWZoX8qc2cIHdRBZ24hyazea0BQAgNnIC81k94C aOUvokW/Pa3Rn0TTI/rwykff3XNAc88uXbm29TW+DdtPEZJfZYpulfzYupyOZ7bau2z7 Zmq19d4tbmqRppD3akYmf4fYvmvZD9/+dAUhR9M+o1KT1Imd5ORIP8/OXkDY6mCnOA53 bhCSGMS/VLpW9iVxrMMMVNrz6nomcTY+Y2CdJfkcl4eusl/TXeWTeMtUsL837oaTsICZ 0oig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nimtRxz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j18-20020a05640211d200b00462df2b0639si1669559edw.335.2022.10.28.10.21.35; Fri, 28 Oct 2022 10:22:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nimtRxz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiJ1Qgd (ORCPT + 99 others); Fri, 28 Oct 2022 12:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbiJ1QgW (ORCPT ); Fri, 28 Oct 2022 12:36:22 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97001CCCCA for ; Fri, 28 Oct 2022 09:36:21 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id 130so5212661pfu.8 for ; Fri, 28 Oct 2022 09:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=fiP/gtk1BinFFJgTXUZEj1NdMWlthKZ0OUfBLn7rLIU=; b=nimtRxz4mCnrDpP+awp+tQ1a53a8hyPg7iNtWXfhDq3ltrOL5UCs75i4rozXJGbMPX SDVQCO8PRkleubIaQin2/IPNBC4hc/yjrIa8pVbxkiahBacQ89eO+azcDW644Ub8H9WK rSEWZcGkj/DmpWCp2i1iWe6DBzQ+UBvL4XPl8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fiP/gtk1BinFFJgTXUZEj1NdMWlthKZ0OUfBLn7rLIU=; b=RG+irE231AySc8mi/JAw97eYchH7S56SnktD8tjfJKosFP8+0JO67N/B4062dV4irR zpFL+SEYrGDlBVXZFNUVtkjAfG+ivx7wnnqZbMZR6HDaoFf6cYsgbt/1baX/atvvVPKc GdoWj9WHdPj1eECB/tiPffk0kYYD4y4ym6ej1m/U/9xfrVHFpDufUOUiQpNA4vYxLeL9 MEf/paKddVXR1HBRqEgjKx29mmttcl4QxukWKnytWuvQ4wgTfcsGx6TFYEOvnlzUddGk XaYXp7c3xVljHY09AZUzYTszYrhQaPhv02JWRoWi47L2Reyyv+B+vIRwsHqbavK5uicY lZWw== X-Gm-Message-State: ACrzQf3BZoVD4jjJR/bvFK2tl0yr6YnuL7xeBRXbL3Yq9ZAXOOqh8Ium xHAO7e1krnUY1Jzq/5x4kX4TXQ== X-Received: by 2002:a63:5a05:0:b0:434:23a5:a5ca with SMTP id o5-20020a635a05000000b0043423a5a5camr296969pgb.515.1666974981269; Fri, 28 Oct 2022 09:36:21 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v9-20020a170902ca8900b00180a7ff78ccsm3223888pld.126.2022.10.28.09.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 09:36:20 -0700 (PDT) Date: Fri, 28 Oct 2022 09:36:19 -0700 From: Kees Cook To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: Paulo Miguel Almeida , Alex Deucher , "Pan, Xinhui" , David Airlie , Daniel Vetter , Hans de Goede , Grigory Vasilyev , Claudio Suarez , Slark Xiao , Rongguang Wei , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] [next] drm/amdgpu: Replace one-element array with flexible-array member Message-ID: <202210280855.9DF8E4D72@keescook> References: <04e37ee1-53b0-97ab-d6d7-a39edfbdc2ea@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <04e37ee1-53b0-97ab-d6d7-a39edfbdc2ea@amd.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 28, 2022 at 09:18:39AM +0200, Christian K?nig wrote: > Am 28.10.22 um 07:10 schrieb Paulo Miguel Almeida: > > One-element arrays are deprecated, and we are replacing them with > > flexible array members instead. So, replace one-element array with > > flexible-array member in struct _ATOM_FAKE_EDID_PATCH_RECORD and > > refactor the rest of the code accordingly. > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > > routines on memcpy() and help us make progress towards globally > > enabling -fstrict-flex-arrays=3 [1]. > > > > Link: https://github.com/KSPP/linux/issues/79 > > Link: https://github.com/KSPP/linux/issues/238 > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] > > I'm not sure if that's a good idea. We had multiple attempts to refactor > this now and it always caused a regression. > > Additional to that the header in question came from our BIOS team and isn't > following Linux styles in general. > > Alex what do you think? Fake flexible arrays (i.e. 1-element arrays) are deprecated in Linux[1] (and, frankly, deprecated in C since 1999 and even well before then given the 0-sized extension that was added in GCC), so we can't continue to bring them into kernel sources. Their use breaks both compile-time and run-time bounds checking efforts, etc. All that said, converting away from them can be tricky, and I think such conversions need to explicitly show how they were checked for binary differences[2]. Paulo, can you please check for deltas and report your findings in the commit log? Note that add struct_size() use in the same patch may result in binary differences, so for more complex cases, you may want to split the 1-element conversion from the struct_size() conversions. -Kees [1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays [2] https://outflux.net/blog/archives/2022/06/24/finding-binary-differences/ -- Kees Cook