Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1407607rwb; Tue, 4 Oct 2022 22:02:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5sNJ0tOxA+X9znw7XKnCJYKXeXexzcGR1YmAqOLFmfNdiJFJT36TH+NzCBMrDnEYC4cj17 X-Received: by 2002:a17:906:8449:b0:78b:74c1:ca32 with SMTP id e9-20020a170906844900b0078b74c1ca32mr10609177ejy.46.1664946158280; Tue, 04 Oct 2022 22:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664946158; cv=none; d=google.com; s=arc-20160816; b=NldXhcVcOIsOkDNB7q2iMGCm13ouRyWBXAfmQA3aV2RRfZDGMSYH52h7T8AzIkt4w2 mqdTF+emuiv2GcjpGcOv/KWYs3uhboZglXIBA3OcBRkHrb6agANtYehBwR2P6KsZmIYz vwGj8wznCO7Tazeidnh0lYnyE4P/xFfxaD0vvB2uFdEgzzzpHtBWzil5LBYWfJd9Tknn HKpEhTXVhOjoYNqvAvogeKi4qsHdGJn9jH+zhp0NBY8MzEGln4O2bRjcjYnddE5N94Id sMLkNoFJlFM5rMHbfDgMl7hBsUb036Zz/jRMM2qmV53LrVmFz25s833g0zjbB2zLaHzs EdIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AhtD3Nxeo233ijtaBGAkFch/kfp5ptj7ps5Ve0jS3rE=; b=GQGSewnp6t07zJs/nx/3dc71G4dlFSwK/CastgJHoCag6OTnr6R2b6iTkG6Ne9T2ZZ MNHQ01ILzDyCxmzE1zixf+qSnJgX+D6otNt9wO77kvtXZFCr4oS/GNFvto8ZE1sRXpB9 MVWkl6OOhz+wuFyRYm68zwZQd1H6hdOVYTqh1o+tuSnSKXtAmODynpAU4ifTAbUnxZtc mCCJCcm9MVczoFlOs/j8lngFIBIYRvoa8FyGIagKWy4tbHL1LCPwQ2vwAnZz/EhdoGWE i8GCvsFkANPSgtjYC+KMWXxShuV18VR91l8X/u6V4c6wkyvebb4YpDf+8gYXlTDzGQFA 8N6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PwXAORUa; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a056402274800b00454561e3ba6si6390742edd.560.2022.10.04.22.02.13; Tue, 04 Oct 2022 22:02:38 -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=@gmail.com header.s=20210112 header.b=PwXAORUa; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiJEDfF (ORCPT + 99 others); Tue, 4 Oct 2022 23:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbiJEDej (ORCPT ); Tue, 4 Oct 2022 23:34:39 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D27376440; Tue, 4 Oct 2022 20:30:32 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id k2so2850606ejr.2; Tue, 04 Oct 2022 20:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=AhtD3Nxeo233ijtaBGAkFch/kfp5ptj7ps5Ve0jS3rE=; b=PwXAORUakcWhQUOq+9BdIiqm5+8hgckUXnhGYtenuGEQKFD2WR5BXzI0aZjcNWIcW2 MLfOfhA+zo30sbiASXK/KLXM7FVB5qiT46CvHWSYUYXZIUCwbK8JUuWjm8j1dqxJnfaO /nvIQ4pO5tXkPmtMW1vMP8jbeiHjGBgtPJVfICYQYeZUbBdxblgGPg0ofZDan4t6vOhp luGdjgmmxpJ+ExWCcy6VEx4YfvNhXk5ezdF/APujX0Xj4TsXwz5o3WUacfKba0nHvGId tGi/n/EKJUpVUzgz8LTcQyCO2q2fBEEAnWBYPYHfNthW7BfVU+1wKMcg3ZYDDrqXzu35 YUSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AhtD3Nxeo233ijtaBGAkFch/kfp5ptj7ps5Ve0jS3rE=; b=yNjIJBDm8R0aEQahc4jXeztosRgJdsaK9Q3SoqIhMlzUkUeDtYQdoSSpqaxhwIVgSp n5OHb046teQonXEmNDYsJuBofSHjpLLepdYEBI7+9KtTURjCLEKL3QhMfzwH/Ho2OTmt CKUGaHQU6Q5MIIbBxoe2rcn9Ut9azi4zMJMJWg0iTigxZ98lD7ow1CdBpCKO/RryZ+x7 iJgDzTZPUBrP3lbuy2Y5J2Hlo9lqhV3DGqUqu0XcfDnKuEjzFMo3J8wnCiWONQn2Q1Dn Wp0ivW3fKbUMFp2wV4KI/oVK9rJCEnVeM9Mp4TD7KSr+2+RovnEbaPW0YIfw9JYFyMdI eirw== X-Gm-Message-State: ACrzQf3Kyez85U7cFoPUciuJHCGiCPaiN63TJ/X3xegV5EINg5Z/4qlb 4oRc+alCuaXu9sUgpm/e5tYoKy0v5jTS6CCLFCw= X-Received: by 2002:a17:907:7b95:b0:731:113a:d7a2 with SMTP id ne21-20020a1709077b9500b00731113ad7a2mr21333233ejc.377.1664940624371; Tue, 04 Oct 2022 20:30:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: ronnie sahlberg Date: Wed, 5 Oct 2022 13:30:11 +1000 Message-ID: Subject: Re: [PATCH][next] cifs: Replace a couple of one-element arrays with flexible-array members To: "Gustavo A. R. Silva" Cc: Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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, 5 Oct 2022 at 12:31, Gustavo A. R. Silva wrote: > > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element arrays with flexible-array > member in structs negotiate_req and extended_response, and refactor the > rest of the code, accordingly. > > Also, make use of the DECLARE_FLEX_ARRAY() helper to declare flexible > array member EncryptionKey in union u. This new helper allows for > flexible-array members in unions. > > Change pointer notation to proper array notation in a call to memcpy() > where flexible-array member DialectsArray is being used as destination > argument. > > Important to mention is that doing a build before/after this patch results > in no binary output differences. Looks good to me. Reviewed-by me Thanks for verifying that it does not change the binary utput. > > 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/229 > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] > Signed-off-by: Gustavo A. R. Silva > --- > fs/cifs/cifspdu.h | 7 ++++--- > fs/cifs/cifssmb.c | 2 +- > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h > index aeba371c4c70..d1abaeea974a 100644 > --- a/fs/cifs/cifspdu.h > +++ b/fs/cifs/cifspdu.h > @@ -483,7 +483,7 @@ put_bcc(__u16 count, struct smb_hdr *hdr) > typedef struct negotiate_req { > struct smb_hdr hdr; /* wct = 0 */ > __le16 ByteCount; > - unsigned char DialectsArray[1]; > + unsigned char DialectsArray[]; > } __attribute__((packed)) NEGOTIATE_REQ; > > #define MIN_TZ_ADJ (15 * 60) /* minimum grid for timezones in seconds */ > @@ -508,13 +508,14 @@ typedef struct negotiate_rsp { > __u8 EncryptionKeyLength; > __u16 ByteCount; > union { > - unsigned char EncryptionKey[1]; /* cap extended security off */ > + /* cap extended security off */ > + DECLARE_FLEX_ARRAY(unsigned char, EncryptionKey); > /* followed by Domain name - if extended security is off */ > /* followed by 16 bytes of server GUID */ > /* then security blob if cap_extended_security negotiated */ > struct { > unsigned char GUID[SMB1_CLIENT_GUID_SIZE]; > - unsigned char SecurityBlob[1]; > + unsigned char SecurityBlob[]; > } __attribute__((packed)) extended_response; > } __attribute__((packed)) u; > } __attribute__((packed)) NEGOTIATE_RSP; > diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c > index 7aa91e272027..7a808e41b1b8 100644 > --- a/fs/cifs/cifssmb.c > +++ b/fs/cifs/cifssmb.c > @@ -465,7 +465,7 @@ CIFSSMBNegotiate(const unsigned int xid, > for (i = 0; i < CIFS_NUM_PROT; i++) { > size_t len = strlen(protocols[i].name) + 1; > > - memcpy(pSMB->DialectsArray+count, protocols[i].name, len); > + memcpy(&pSMB->DialectsArray[count], protocols[i].name, len); > count += len; > } > inc_rfc1001_len(pSMB, count); > -- > 2.34.1 >