From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21A92C433E1 for ; Fri, 5 Jun 2020 19:30:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4C22206FA for ; Fri, 5 Jun 2020 19:30:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CM7S9hzo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727877AbgFETa2 (ORCPT ); Fri, 5 Jun 2020 15:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726963AbgFETa2 (ORCPT ); Fri, 5 Jun 2020 15:30:28 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84400C08C5C2 for ; Fri, 5 Jun 2020 12:30:27 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id m1so5692525pgk.1 for ; Fri, 05 Jun 2020 12:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=AbyBZikI3hqgXmsHBOfV75n7XdKr0G/JAWMAPeCKaVM=; b=CM7S9hzo9pTl7u6+baQLjXQEAeN1JeKl7OKM3VOg/W5H7eiQwaxhARGEUpluvm5OZE qn/79lkDeXfzIlQH7fGekrn/YUFxJZfRMp48Jp6lvtniA5VWnvNqjkqPyX6dbDM8ytgq FlAykxq3HNcAX2dQtka5uiu3J/ZrW3Ii+QuAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AbyBZikI3hqgXmsHBOfV75n7XdKr0G/JAWMAPeCKaVM=; b=ho9kLjBmamJwpmsabhfpB+QeCaMUvTbvmRvL/CwQKeYAn+Dowmj2QLUf6o5ggj2TK+ 8AMWrLsFfhBPKYo49uBoDuWNEx9Usx4WoGVi55eLonLnW46uVQNZ7R3C4a5N6U7HFMkM 7zxp9cNWuqoyt+cfzj6JOz8UNSGLN2G2kAzjG142Xc9z5Mr9Q90zql0qo8Owbev0DdQ7 vqKXvJq22790txDd1pJy+knPxvXy3KmjsEIPWyAQ0V6FzFoZmaX0rgKruPNYpEv5k7kp K0rtZxqJrZ+sW7pHYVkRFIRH4pYjzqB36ERNBxETNAeTANYF+RWwMy9WENS85Qn8tDdH 8Juw== X-Gm-Message-State: AOAM531/F8t+KL1dNnEb8LH56+bu57Lo7BP2zJMEbljRHQpd27stvqd1 LsXHldC2N8S2wpHb1ZHky+jDxg== X-Google-Smtp-Source: ABdhPJwF7iSAohqEGKNsj8WMqTwy2PzH6/8uc+MdsDrlJtOWrk3aZlMTtCIbbLzwQ7WIMzePkNkM+Q== X-Received: by 2002:a63:454c:: with SMTP id u12mr10994700pgk.153.1591385426987; Fri, 05 Jun 2020 12:30:26 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x11sm332239pfq.169.2020.06.05.12.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 12:30:26 -0700 (PDT) Date: Fri, 5 Jun 2020 12:30:24 -0700 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: Re: [PATCH v2] docs: deprecated.rst: Add zero-length and one-element arrays Message-ID: <202006051150.B30EE1104D@keescook> References: <20200605162142.GA1617@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200605162142.GA1617@embeddedor> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 05, 2020 at 11:21:42AM -0500, Gustavo A. R. Silva wrote: > Add zero-length and one-element arrays to the list. > > While I continue replacing zero-length and one-element arrays with > flexible-array members, I need a reference to point people to, so > they don't introduce more instances of such arrays. And while here, > add a note to the "open-coded arithmetic in allocator arguments" > section, on the use of struct_size() and the arrays-to-deprecate > mentioned here. > > Signed-off-by: Gustavo A. R. Silva > --- > Changes in v2: > - Adjust some markup links for readability. > > Documentation/process/deprecated.rst | 83 ++++++++++++++++++++++++++++ > 1 file changed, 83 insertions(+) > > diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst > index 652e2aa02a66c..042c21c968e19 100644 > --- a/Documentation/process/deprecated.rst > +++ b/Documentation/process/deprecated.rst > @@ -85,6 +85,11 @@ Instead, use the helper:: > > header = kzalloc(struct_size(header, item, count), GFP_KERNEL); > > +NOTE: If you are using struct_size() on a structure containing a zero-length Please use: .. note:: for this kind of "NOTE:" > +or a one-element array as a trailing array member, stop using such arrays And I think it was likely my language suggestion to say "stop using", but probably this should be more friendly. How about "please refactor such arrays ..." > +and switch to `flexible arrays <#zero-length-and-one-element-arrays>`_ ... to a `flexible array member <#... > +instead. > + > See array_size(), array3_size(), and struct_size(), > for more details as well as the related check_add_overflow() and > check_mul_overflow() family of functions. > @@ -200,3 +205,81 @@ All switch/case blocks must end in one of: > * continue; > * goto