Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1622041rwb; Wed, 14 Dec 2022 12:36:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nQsFE21Wtghc+hw5KS++Vb/BXYL9hj6TgoXIpMn36jQpZxKC7SXTV17tqAEPdEM3NnhEh X-Received: by 2002:a05:6a21:6d8e:b0:af:7320:664c with SMTP id wl14-20020a056a216d8e00b000af7320664cmr4823026pzb.23.1671050173947; Wed, 14 Dec 2022 12:36:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671050173; cv=none; d=google.com; s=arc-20160816; b=nBjLH2Ktz7HEZ+hG5A74dNfSuTG6d593+Ym8nXfPYRGhcrJARUB/MnpOqUInEqaaCE lmlJHP60SFOgZl9vGJlh+uZSqqg4OFY3p7ZAp0kWWrV08rEFTVDeUaLYpVQUp1bgUID+ uhaFI0yVfCarYzcp9vdN2SvU5RjDx2PlVbrwzo93iz/LEhihDqB2MAwbAuVgOiShmgKi 1gusN+eLFx21xNOwEEdXK+FqVNd0j7W7M0JmdiY8p9Jpdctt1tpI2kRD2T6sJyay4V1M ZaEHyfDkfxbF0lMAit4YQ8PCRJNmlCZluRcgYeudHJxRXrhdqKE3jb3VuGy9ozmJkyxF Rkdw== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=R4++XUu80LunZaKsdjvyt+0/rbOtR+T2hXuJjGDgzM8=; b=ISy+mk2hGvDcypxnO0rMv+2LK/iCKDLCtKhlQw2pIfqHe8FWSI8V+L+wsbwEQXgmJc l/k2Enz3AKmHmp7wJ5cbtOp97DL1bxGWDruEaiZsRYvq8U13daq2R0Dop46g+UX+kh2c 6CzienQrf5fgIJHV2ex1Txtxh/spYO6qD0g42BuRKKUAmPWKclmne+izj2K+RACHZefY ZRpw8Z5v3rfr5OmL26wJzC7bJa7NaUB9XMB9llVnCyuARNkM+yjuVK2vjjSkqzyUE8cF mXoXEXI6ZUcIB4LTrCYp2h/Tki9jjRt1Cy+X86qd7xmzSh7Wmj4iAnjWfUTO2oGZqFdh yrPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vqg62PaC; 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 v10-20020a63f20a000000b004776762655fsi684769pgh.606.2022.12.14.12.36.03; Wed, 14 Dec 2022 12:36:13 -0800 (PST) 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=Vqg62PaC; 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 S237580AbiLNT3p (ORCPT + 69 others); Wed, 14 Dec 2022 14:29:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiLNT3l (ORCPT ); Wed, 14 Dec 2022 14:29:41 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56A9B19C2B for ; Wed, 14 Dec 2022 11:29:39 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id hd14-20020a17090b458e00b0021909875bccso4399651pjb.1 for ; Wed, 14 Dec 2022 11:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=R4++XUu80LunZaKsdjvyt+0/rbOtR+T2hXuJjGDgzM8=; b=Vqg62PaCJgKuNsInFR+NrrhkFl7LCAyJQpOT+rN4+5PWgz53ql6NQbSv1OQLy41Ea4 5b5RhppCBdu00GK8YuC/8xE2xUMOner2rJBPtPQ7r2faAhN2Sz4q02psIb8PuWrWbWi0 zo63+jvVRRHaiIVppslJ4P5nU8YmzBsHFRhfY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to: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=R4++XUu80LunZaKsdjvyt+0/rbOtR+T2hXuJjGDgzM8=; b=43zK6G/ICgf0l3tWAXCfc0wQK9lq/teUlOkozJkhd1S4JSk0vCiXNipXBdQQgqvg1J GsK3dGGpTZZv2TIxHXeFK+u+mmndsIjwbTQHsIzNYAIG2Jo4Qw4Qo9L3CQLp8XhPQCBo 5u961SfDrI2B3gzAEoLDIiVNBN4zSnY/2MkDgGn6TyK5A/Tb4iwWxBef3yCkrC4pxPvD /SOsb956thtqKNCq7lp0ZiKlLvzM1lqkgTVMx9QCOMqhP1kJAcrNZzdwUssoawb52oyj Q/62GFodBkSpzqbCWN6H60Zt7nHSAZzSvSdREohSdwEinncipZ0GNGSzkfaIVFQlqy8H GczA== X-Gm-Message-State: ANoB5plaKSV033WLorZIEJ3VY4QXa0XoGr0awxEvpJZPt/7zKlGXv8u+ eF0i+OQSJoeCOxVwUmLN6q73wQ== X-Received: by 2002:a17:902:f211:b0:189:8f0c:d314 with SMTP id m17-20020a170902f21100b001898f0cd314mr23098980plc.39.1671046178866; Wed, 14 Dec 2022 11:29:38 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o9-20020a170903210900b00186616b8fbasm2266487ple.10.2022.12.14.11.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 11:29:38 -0800 (PST) Date: Wed, 14 Dec 2022 11:29:37 -0800 From: Kees Cook To: Paulo Miguel Almeida Cc: Arnd Bergmann , Greg Kroah-Hartman , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Jiri Slaby , Haowen Bai , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] [next] pcmcia: synclink_cs: replace 1-element array with flex-array member Message-ID: <202212141124.736E3DE2A8@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 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=ham 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 Wed, Dec 14, 2022 at 09:42:00PM +1300, Paulo Miguel Almeida wrote: > 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 RXBUF and refactor the rest of the code > accordingly. > > It's worth mentioning that doing a build before/after this patch > results in no binary output differences. > > 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://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] > > Signed-off-by: Paulo Miguel Almeida > --- > drivers/char/pcmcia/synclink_cs.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c > index b2735be81ab2..1ab2d552f498 100644 > --- a/drivers/char/pcmcia/synclink_cs.c > +++ b/drivers/char/pcmcia/synclink_cs.c > @@ -105,7 +105,7 @@ static MGSL_PARAMS default_params = { > typedef struct { > int count; > unsigned char status; > - char data[1]; > + char data[]; > } RXBUF; > > /* The queue of BH actions to be performed */ > @@ -2611,7 +2611,8 @@ static int mgslpc_proc_show(struct seq_file *m, void *v) > static int rx_alloc_buffers(MGSLPC_INFO *info) > { > /* each buffer has header and data */ > - info->rx_buf_size = sizeof(RXBUF) + info->max_frame_size; > + info->rx_buf_size = max(offsetof(typeof(RXBUF), data) + 1, sizeof(RXBUF)) > + + info->max_frame_size; It seems like there is an existing size bug here, and likely should be fixed separately? i.e. this was already allocating 1 byte "too much". I'd expect this first: - info->rx_buf_size = sizeof(RXBUF) + info->max_frame_size; + info->rx_buf_size = sizeof(RXBUF) - 1 + info->max_frame_size; and then the next patch: - char data[1]; + char data[]; ... - info->rx_buf_size = sizeof(RXBUF) - 1 + info->max_frame_size; + info->rx_buf_size = sizeof(RXBUF) + info->max_frame_size; The above would induce a binary output change, and the second would not. Though this results in what you had for the v2 patch (but I can't believe it had no binary changes...) -- Kees Cook