Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4839698rwb; Tue, 8 Aug 2023 15:01:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9Ud2guDPYT3vscmWxpNlGJ3tX8wOyDm4ksBI/OwAcbUQ+q3c8jpADWn3A7BGc3TBGN2S9 X-Received: by 2002:a17:902:e80c:b0:1b8:3936:7b64 with SMTP id u12-20020a170902e80c00b001b839367b64mr1458309plg.1.1691532116786; Tue, 08 Aug 2023 15:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691532116; cv=none; d=google.com; s=arc-20160816; b=hP8UiccGLU4xoctDfc6fonVg7YisWv5inLp7ikUGqns+4iWLwJQVlHQj8dc+MtwqzF KABss/l1zcHBoebGWQ481wh3RY22UGwWXNFyUe0+QIR/+LQBAkHUM52Xyvj+fpa5iUsV n80c35CQ5Z31WJZGXquaAYS1mZ+RoJ9W/KexKi+cd7KqIc/kpEArrNevs6gWR/T+WtXC gkAzmcZdi7rqdLaR3j0pSCKiCwGhhUGUr23PNiX1y1pIja/IaHpiyDu6nQP+zarnGp4p yBelrU4xHVD1ufEQuP6TclShAKwtppeFIHgQw4M0PrTdpa2GdycxJ5cJQkMEmCGmCQkY makw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=6BOKB0SU4NlfqYKZ8J0hN0ve9ifE7NHBHUSTyRuY9LE=; fh=O63IryxzGsBPvfSEuBQrY4gQO4Dt5kdLA7nkl36gPo8=; b=gMBgLz1yeeCeYFoy/MkSI+h7lS7s7BqhmgTRc190XryQ9A5w2INAcEeL6dCSBggOJk wPNlxNSB4r73tdWdZlEG3MRB/ilHTEPTGguownw2tWZnjTppkIgt6UFYSfQtKyFBNLWr 0xHfv3+TvJGxkM/DUqHpPSzkdxu0k5mjVE/aTySYcffTNJLhonWvXJIA5/Jfn72se5DM 7S1rM+d9HwlCJLly9O7VOWDIHucKEHKjIOLbTZVLX1tZeI1HyEP/b7+Aiu6gGemBF/9d mMyZg5RpOhSqz7lGGFHL72XoleGvmmofcNd2u3R5e0BCAHXrWp1SWDqkzJjExdtpVAD+ ixeg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a170902ebc500b001b02bd00c67si7994109plg.324.2023.08.08.15.01.43; Tue, 08 Aug 2023 15:01:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233897AbjHHUyy (ORCPT + 99 others); Tue, 8 Aug 2023 16:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbjHHUyi (ORCPT ); Tue, 8 Aug 2023 16:54:38 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97CB11B508; Tue, 8 Aug 2023 10:10:57 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RKvHw44tyz4f3t7S; Tue, 8 Aug 2023 21:32:28 +0800 (CST) Received: from vm-fedora-38.huawei.com (unknown [10.67.174.164]) by APP3 (Coremail) with SMTP id _Ch0CgDX+sLnQ9JkxaPeAA--.27925S2; Tue, 08 Aug 2023 21:32:31 +0800 (CST) From: "GONG, Ruiqi" To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Roopa Prabhu , Nikolay Aleksandrov , Kees Cook , "Gustavo A . R . Silva" Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Wang Weiyang , Xiu Jianfeng , gongruiqi1@huawei.com Subject: [PATCH v2] netfilter: ebtables: fix fortify warnings Date: Tue, 8 Aug 2023 21:30:38 +0800 Message-ID: <20230808133038.771316-1-gongruiqi@huaweicloud.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _Ch0CgDX+sLnQ9JkxaPeAA--.27925S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXF1xJw4UCw4xZw1DCF45KFg_yoW5Cr1DpF 1qka45trWrJ3yakw4rJw1vvr1ruw4kWa43ArW7C34FkFyjqFyDXa92kryjka4kJws09F13 trZ0qFWfGrWDAaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2 j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7x kEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY 0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I 0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAI cVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcV CF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280 aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1zuWJUUUUU== X-CM-SenderInfo: pjrqw2pxltxq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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 From: "GONG, Ruiqi" When compiling with gcc 13 and CONFIG_FORTIFY_SOURCE=y, the following warning appears: In function ‘fortify_memcpy_chk’, inlined from ‘size_entry_mwt’ at net/bridge/netfilter/ebtables.c:2118:2: ./include/linux/fortify-string.h:592:25: error: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror=attribute-warning] 592 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The compiler is complaining: memcpy(&offsets[1], &entry->watchers_offset, sizeof(offsets) - sizeof(offsets[0])); where memcpy reads beyong &entry->watchers_offset to copy {watchers,target,next}_offset altogether into offsets[]. Silence the warning by wrapping these three up via struct_group(). Signed-off-by: GONG, Ruiqi --- v2: fix HDRTEST error by replacing struct_group() with __struct_group(), since it's a uapi header. include/uapi/linux/netfilter_bridge/ebtables.h | 14 ++++++++------ net/bridge/netfilter/ebtables.c | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/uapi/linux/netfilter_bridge/ebtables.h b/include/uapi/linux/netfilter_bridge/ebtables.h index a494cf43a755..b0caad82b693 100644 --- a/include/uapi/linux/netfilter_bridge/ebtables.h +++ b/include/uapi/linux/netfilter_bridge/ebtables.h @@ -182,12 +182,14 @@ struct ebt_entry { unsigned char sourcemsk[ETH_ALEN]; unsigned char destmac[ETH_ALEN]; unsigned char destmsk[ETH_ALEN]; - /* sizeof ebt_entry + matches */ - unsigned int watchers_offset; - /* sizeof ebt_entry + matches + watchers */ - unsigned int target_offset; - /* sizeof ebt_entry + matches + watchers + target */ - unsigned int next_offset; + __struct_group(/* no tag */, offsets, /* no attrs */, + /* sizeof ebt_entry + matches */ + unsigned int watchers_offset; + /* sizeof ebt_entry + matches + watchers */ + unsigned int target_offset; + /* sizeof ebt_entry + matches + watchers + target */ + unsigned int next_offset; + ); unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); }; diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 757ec46fc45a..5ec66b1ebb64 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -2115,8 +2115,7 @@ static int size_entry_mwt(const struct ebt_entry *entry, const unsigned char *ba return ret; offsets[0] = sizeof(struct ebt_entry); /* matches come first */ - memcpy(&offsets[1], &entry->watchers_offset, - sizeof(offsets) - sizeof(offsets[0])); + memcpy(&offsets[1], &entry->offsets, sizeof(offsets) - sizeof(offsets[0])); if (state->buf_kern_start) { buf_start = state->buf_kern_start + state->buf_kern_offset; -- 2.41.0