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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no 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 46A71C433E0 for ; Mon, 1 Jun 2020 15:37:53 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F107C2065C for ; Mon, 1 Jun 2020 15:37:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bpGARYo+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F107C2065C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=paul-moore.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-audit-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591025872; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bYnORDg48O8RXTQjA3hwGPRI5jmuP4ShQpIj4mUtiUM=; b=bpGARYo+Op+p9h3QUU6ZP7EpqFF7wfdbBJ8eUvmpX2HTRIaYh+9bUrfF36ly+MTC+RlVUT vQBFrbYP9oy/28g2/7urNOQGiY1C8NmqqDzSk0RGtgzXL+BakBaUf2WP5oq4aQBLlX0ETu HohABTbzFqV0AlD6LN7OwqSIcVqE6BI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-FgP5DUZzNKuUMfxoWET8bg-1; Mon, 01 Jun 2020 11:37:35 -0400 X-MC-Unique: FgP5DUZzNKuUMfxoWET8bg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 858B2BFC0; Mon, 1 Jun 2020 15:37:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EDEF5D9C9; Mon, 1 Jun 2020 15:37:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 060F41809547; Mon, 1 Jun 2020 15:37:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 051FaSUF028945 for ; Mon, 1 Jun 2020 11:36:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 063A7105AD50; Mon, 1 Jun 2020 15:36:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFB55105AD4D for ; Mon, 1 Jun 2020 15:36:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E133282883A for ; Mon, 1 Jun 2020 15:36:25 +0000 (UTC) Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-56-AqEluLXkPVGDuXdRg6Z2ig-1; Mon, 01 Jun 2020 11:36:22 -0400 X-MC-Unique: AqEluLXkPVGDuXdRg6Z2ig-1 Received: by mail-ej1-f66.google.com with SMTP id k11so9599734ejr.9 for ; Mon, 01 Jun 2020 08:36:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cOzQOgAom9rQmo+hpj4LfsaeGdzJ+MyyfqV630jExfM=; b=i3CFtuOOnZK/oEJ1Lc7Gmm8dlecnTfP8yoVV3RsbJXZiVDvon5l7zlGo3WT2xmaE5D U+Vw5nppC6C4VsmK3XdPMl+d+z2BHK74ms+lNy0bSsE7jfnse+P4wW8XNeRXbPK2XD4F 2G9Syq4NniQTSJIfDKjNEz/uLUGzRnjJk1p+tvllH3AJoZBvN45UnvKzVnQ6mI7aQ1Yy YHqufEdskKFwqyLbnVzglma8W9ywkIJfKcvRqH1yQ7UAoZI4ALiClk1PWf80oFCGGBsx VAHTrU2+Ux+WIFbwBx0XAOfSDq2x5CwGmBWyWFUX593FhsMkIx8MLMlCBKhRjonjzbZd 1ykg== X-Gm-Message-State: AOAM533avmnmWxvz7z3uqvQVyn942QkEqGkNIPxFHegY4LhHwQaQSUF2 b9IHYOF+Cfo3l42PEHMOZzbTQfbEaMVUUiV6nYnd X-Google-Smtp-Source: ABdhPJxVaLECnW5ysWNl7aGrxxD3Sa6GGI54d7azZ3A9R39oQ9z6eiacAbvYKZ6DiQ+k7L+7xyOd2//IcuQOaHPJrQo= X-Received: by 2002:a17:906:f1ca:: with SMTP id gx10mr2336087ejb.542.1591025780793; Mon, 01 Jun 2020 08:36:20 -0700 (PDT) MIME-Version: 1.0 References: <20200524205238.GA17576@embeddedor> In-Reply-To: <20200524205238.GA17576@embeddedor> From: Paul Moore Date: Mon, 1 Jun 2020 11:36:09 -0400 Message-ID: Subject: Re: [PATCH] audit: Use struct_size() helper in alloc_chunk To: "Gustavo A. R. Silva" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: linux-audit@redhat.com Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Sun, May 24, 2020 at 4:47 PM Gustavo A. R. Silva wrote: > One of the more common cases of allocation size calculations is finding > the size of a structure that has a zero-sized array at the end, along > with memory for some number of elements for that array. For example: > > struct audit_chunk { > ... > struct node { > struct list_head list; > struct audit_tree *owner; > unsigned index; /* index; upper bit indicates 'will prune' */ > } owners[]; > }; > > Make use of the struct_size() helper instead of an open-coded version > in order to avoid any potential type mistakes. > > So, replace the following form: > > offsetof(struct audit_chunk, owners) + count * sizeof(struct node); > > with: > > struct_size(chunk, owners, count) > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva > --- > kernel/audit_tree.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) Thanks, this looks reasonable to me, but it came in too late for the v5.8 merge window (I dislike taking changes past -rc5/6 unless critical). Once the merge window closes I'll merge this into audit/next. -- paul moore www.paul-moore.com -- Linux-audit mailing list Linux-audit@redhat.com https://www.redhat.com/mailman/listinfo/linux-audit