Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2951610rwb; Sat, 8 Oct 2022 18:13:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Bn16ZUjjExmHLB+RoPnUgcPOIOyr4/h2eXtATAfbhStYDlWte0nMo8syLyjGUnzdB7tpa X-Received: by 2002:aa7:c60a:0:b0:458:d707:117 with SMTP id h10-20020aa7c60a000000b00458d7070117mr11396310edq.258.1665278032641; Sat, 08 Oct 2022 18:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665278032; cv=none; d=google.com; s=arc-20160816; b=te7LCCuMfrJQfqL2Oc/N6WEryPp5U4yqm9JB/2fq429dXiz+v4zISrct+wugnv6uFS Zc7ZFBFfnS+gSNpFCMiQ2RQJFBqjB+Qp3IXDK23TQYvQPZlNArrmdDqBEIfoI9upPKeD uViS3bmnTTeyB9oyEVUe12M4yzU1mYc3VBSmp3rgbdTnPIS6axK6ah9v7HaQ1shFxX7T Ah/CypsFWlIUebcbm4E9qA6bXbIY4Gl1KfLWFfD+/qYpR29xcIh6yUOipdKlA1NuUyZL PfI9oxTj0VbeGbsaLcvbEHwLVqordkj3hRrXK1maxmFGJXHrdEndOYA0i3dKUqem45up TkYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=lULkEACMGXAqLMVro1NAmGHqDFrc11oNE+hqnHHNv9k=; b=I+yeKOeoI/6F1HSItQ5hIfj7kdCq7Vq5M31E6DZRIpU7NuTvPGY9gFniQ+QC2W14p/ IGJNTBNOzYgUkcoJFiLU50xMZG1atbdtT6xLEWVnqbrZgkbiBduZxxjGH06u+FZ4dPuw U68KNcuRbKXvD0m3xO1HvGv2Fv7X2s0TbADI9SaPcFII8N/yUACXA2rRzmqX0a62Kmks m92qHY8srkJT51Oryd/jEacJIW2ZBBia+9fCgN6mUl7cBFOiL/rpt3rvsdZSTttoAWRT /uLQLdrnBY2TG4haSn/Uj2XjO3VnJO5QOZ0h56HrHdGgxBdOYJZlnG1FQwg+7DpZ35Me KyvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Of0rgZhZ; 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 g19-20020a1709065d1300b00773b8e3b6a1si7229868ejt.805.2022.10.08.18.13.17; Sat, 08 Oct 2022 18:13:52 -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=Of0rgZhZ; 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 S229564AbiJHXRq (ORCPT + 99 others); Sat, 8 Oct 2022 19:17:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiJHXRp (ORCPT ); Sat, 8 Oct 2022 19:17:45 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DD5B17A8F; Sat, 8 Oct 2022 16:17:44 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d24so7508633pls.4; Sat, 08 Oct 2022 16:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=lULkEACMGXAqLMVro1NAmGHqDFrc11oNE+hqnHHNv9k=; b=Of0rgZhZNm/DOfl8gCGmaW0Z9i/p50pUPg86vCNuYcDOiRzCHe4hsqzkPU04pVf/tm n2E2j835OaHbUT7Z6HqWoUskm4hv4g+mi8UWz2G18AG9103fXphC7VJuHoBLwMMZfdON 2ssEr5cIGmU9k0lwvN1jiTWb7rdOi4bgb17N9ZmMxE/F4FtGNw7uKn0px9aXx5PNCM22 Xjyb64G2cjZF+UsnyJ91CDYI3OaoahaMyo91TMmSsckTLM2+o8w9UBHWGB7iWVQVynKm A+LAS4oUZ7mbibX+JjDc+DIJbXAucgnPidb9eZcjGNKraUkJ+v7WvFFMWDPMeBsgM7od cKKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lULkEACMGXAqLMVro1NAmGHqDFrc11oNE+hqnHHNv9k=; b=rz/7m52M+ru2JL4VKSprYYX3p8/REs1MjgkosXGl5UWwFgoRrG2BTuMz9TafLnwjvm fGdTPuAt/+q8cAHSr7pJm/72cs9d+BbqRhWR7TsB3pvv+kok025kR+Iun+FC4nuPnSuP 6gkYBtmA//a9ld63DhTDs3WUGY9r4PDBRqgjMcnmKaGtySCeVsRg2k6chV13uAS2FN0i Q2fm9YiR69zQhbt+xR+Aa4/YwAAntvw3HHNbYZtG0N50l15wz+rdtpVz58lgsMhSFth8 INnfz1ZAKZAGmHFMnoQCk+aoMTvZlkeoR5jI77JW+TPf9SKt9UlI+MNs0NUBKT9T0nSD dziw== X-Gm-Message-State: ACrzQf0dcx0oHMFHeXVMkC17Kfg69b4/79gNRNGlzRNe7hgJ0BonnZX3 d/jv5vRR1A3R8h/eDuEmz7w= X-Received: by 2002:a17:902:bc8c:b0:178:a406:72ea with SMTP id bb12-20020a170902bc8c00b00178a40672eamr11495880plb.56.1665271064101; Sat, 08 Oct 2022 16:17:44 -0700 (PDT) Received: from mail.google.com (122-58-209-93-fibre.sparkbb.co.nz. [122.58.209.93]) by smtp.gmail.com with ESMTPSA id c17-20020a170903235100b00180daa59314sm1963597plh.125.2022.10.08.16.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 16:17:43 -0700 (PDT) Date: Sun, 9 Oct 2022 12:17:37 +1300 From: Paulo Miguel Almeida To: Christine Caulfield , David Teigland , cluster-devel@redhat.com Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, paulo.miguel.almeida.rodenas@gmail.com Subject: [PATCH v2][next] dlm: Replace one-element array with flexible-array member Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 dlm_ls, and refactor the rest of the code, accordingly. We strive to make changes that don't produce any before/after binary output differeces as that makes it easier for the reviewer to accept the patch. In this particular instance, it wasn't possible to achieve this due to the fact that the ls_name[1] size, which is used as the NUL-terminator space, was hidden within the struct's padding as shown below. $ diff <(objdump -M intel -j .text -D dlm.old) <(objdump -M intel -j .text -D dlm.new) 13778c13778 < c693: 49 8d bc 24 c0 08 00 lea rdi,[r12+0x8c0] --- > c693: 49 8d bc 24 c1 08 00 lea rdi,[r12+0x8c1] $ pahole dlm.old -C dlm_ls ... int ls_namelen; /* 2232 4 */ char ls_name[1]; /* 2236 1 */ /* size: 2240, cachelines: 35, members: 90 */ /* sum members: 2166, holes: 17, sum holes: 71 */ /* padding: 3 */ /* paddings: 3, sum paddings: 17 */ /* forced alignments: 1 */ } __attribute__((__aligned__(8))); $ pahole dlm.new -C dlm_ls ... int ls_namelen; /* 2232 4 */ char ls_name[]; /* 2236 0 */ /* size: 2240, cachelines: 35, members: 90 */ /* sum members: 2165, holes: 17, sum holes: 71 */ /* padding: 4 */ /* paddings: 3, sum paddings: 17 */ /* forced alignments: 1 */ } __attribute__((__aligned__(8))); 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/228 Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [1] Signed-off-by: Paulo Miguel Almeida --- My apologies for v2, there was an accidental I added on the CC line which messed up the body of my previus email. This patch sets it right. --- fs/dlm/dlm_internal.h | 2 +- fs/dlm/lockspace.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index e34c3d2639a5..ce2e32ed2ede 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h @@ -670,7 +670,7 @@ struct dlm_ls { void *ls_ops_arg; int ls_namelen; - char ls_name[1]; + char ls_name[]; }; /* diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index bae050df7abf..c3a36f3197da 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c @@ -473,7 +473,7 @@ static int new_lockspace(const char *name, const char *cluster, error = -ENOMEM; - ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_NOFS); + ls = kzalloc(sizeof(struct dlm_ls) + namelen + 1, GFP_NOFS); if (!ls) goto out; memcpy(ls->ls_name, name, namelen); -- 2.37.3