From patchwork Mon Apr 10 09:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 81444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1782532vqo; Mon, 10 Apr 2023 02:48:19 -0700 (PDT) X-Google-Smtp-Source: AKy350ZD8kahhvSS9T2AAjfTQPQU1vR8lb8BYffx6rZFNo6N+nBhxu3162iPae1aYskBdkXQudBD X-Received: by 2002:a17:907:2da6:b0:930:3916:df17 with SMTP id gt38-20020a1709072da600b009303916df17mr8771678ejc.0.1681120098871; Mon, 10 Apr 2023 02:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681120098; cv=none; d=google.com; s=arc-20160816; b=A6eF885eA9Af9DJ4mcphqz/b79FyeYhwQEhUDwKdMRgP2RdC7I2Nsu4TvCbhMtJHAW Is8jTcjZC0y8tUOLxvnZpeLGvhQuP517xhRIN6xn0O7bZ1umHnteyMNH5y1Gz/3bFhZu VEbhibycQZyZ/BlSC7h7Ex7RCAcDFC2oOM/leLVGoPpH20rnMbeDQPkJI60gCZn3Y/tu hpHpmagwqQbazX+xaMzil8hCVehth9i+GU9HspumaS8HCVX/8dsWVr1QjWsz0f2qlqWO S4xUzUUrnPhhKc35AF8GNaBSR7STBvZ9t+Tk9HDbqxIeXyI+lNTg3wSjwWC2cWsqdThk c0Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=34PIO6SrlnWyAE9Crf9k461BcbBgI3ePB5fo3MJHERo=; b=ffOvwFhDuk0Mns8X4McIJU9nv2SO4I3tLRz2kQu6uRTuH9N+ayuLVmwPq6E0quM/ob kVMsd9+AqYdW6sssKtd/jHOmmfeusiIpubXgQEfBBQLsrjlJKIwy/Ii/zfB0b4B750vR j8DK4SUJubTyKckl54+8iRiWmgseN+BZja3H2MDkD1Xa6yky9oybginX/mnnJ+FDd0dp 6PNSdt5Jv3ilcHCuwFJ5ebq9TtLAUFH1Snlpcderhmj4jBryQpO+9bN6LDJYrcF4mOkQ BBXoGhnGasnz2icJchO+aVaMNpg4K3dU1BiYdEBIbso39d8K1J542KYCjUhVyihr/NSn Nnrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lnBmAS4v; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170906584600b00933e8f8ccf9si8545618ejs.1001.2023.04.10.02.47.55; Mon, 10 Apr 2023 02:48:18 -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=@kernel.org header.s=k20201202 header.b=lnBmAS4v; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbjDJJnA (ORCPT + 99 others); Mon, 10 Apr 2023 05:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjDJJm4 (ORCPT ); Mon, 10 Apr 2023 05:42:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 239851FDD; Mon, 10 Apr 2023 02:42:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AE7AB61177; Mon, 10 Apr 2023 09:42:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8916C4339C; Mon, 10 Apr 2023 09:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681119775; bh=qATQ34H7t/140BYO5XpIrp+uhhYgzRmHCSvABBsP+MI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lnBmAS4vUtio7WSZOM1tLmliF8G1CrqwtndUF+ToVoQiC2CLHHYFpyc7wphXN+uZT Brft6s2w7m4zWbgcXH83iUqFXv78HeDasibEgex1G+f+mXQQI0rl7mSiuAndyj9J5j 5QUHOriA5KL5OLZlKjGH8px1RDbJCZOhxOc2Qvj9y1WNIVjcg1nY5hFSEWNqCGR9ht PIHI1VfF1RhIqCFvSiCT+Vd6+aCgSGMUWXzDs9fsb6JjroHPC8frdbkX+lhyopngKB 4gC24OTE8IGrYs/3fwyEbLdexbCqQ005TitTw8wtwbsDyx41qkNj2bdIXGt0YZD8in psjwlVeWFMBrA== From: Simon Horman Date: Mon, 10 Apr 2023 11:42:35 +0200 Subject: [PATCH nf-next 1/4] ipvs: Update width of source for ip_vs_sync_con_options MIME-Version: 1.0 Message-Id: <20230409-ipvs-cleanup-v1-1-98cdc242feb0@kernel.org> References: <20230409-ipvs-cleanup-v1-0-98cdc242feb0@kernel.org> In-Reply-To: <20230409-ipvs-cleanup-v1-0-98cdc242feb0@kernel.org> To: Julian Anastasov Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , netdev@vger.kernel.org, "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , lvs-devel@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762782188942112358?= X-GMAIL-MSGID: =?utf-8?q?1762782188942112358?= In ip_vs_sync_conn_v0() copy is made to struct ip_vs_sync_conn_options. That structure looks like this: struct ip_vs_sync_conn_options { struct ip_vs_seq in_seq; struct ip_vs_seq out_seq; }; The source of the copy is the in_seq field of struct ip_vs_conn. Whose type is struct ip_vs_seq. Thus we can see that the source - is not as wide as the amount of data copied, which is the width of struct ip_vs_sync_conn_option. The copy is safe because the next field in is another struct ip_vs_seq. Make use of struct_group() to annotate this. Flagged by gcc-13 as: In file included from ./include/linux/string.h:254, from ./include/linux/bitmap.h:11, from ./include/linux/cpumask.h:12, from ./arch/x86/include/asm/paravirt.h:17, from ./arch/x86/include/asm/cpuid.h:62, from ./arch/x86/include/asm/processor.h:19, from ./arch/x86/include/asm/timex.h:5, from ./include/linux/timex.h:67, from ./include/linux/time32.h:13, from ./include/linux/time.h:60, from ./include/linux/stat.h:19, from ./include/linux/module.h:13, from net/netfilter/ipvs/ip_vs_sync.c:38: In function 'fortify_memcpy_chk', inlined from 'ip_vs_sync_conn_v0' at net/netfilter/ipvs/ip_vs_sync.c:606:3: ./include/linux/fortify-string.h:529: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] 529 | __read_overflow2_field(q_size_field, size); | Compile tested only. Signed-off-by: Simon Horman --- include/net/ip_vs.h | 6 ++++-- net/netfilter/ipvs/ip_vs_sync.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index 6d71a5ff52df..e20f1f92066d 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -630,8 +630,10 @@ struct ip_vs_conn { */ struct ip_vs_app *app; /* bound ip_vs_app object */ void *app_data; /* Application private data */ - struct ip_vs_seq in_seq; /* incoming seq. struct */ - struct ip_vs_seq out_seq; /* outgoing seq. struct */ + struct_group(sync_conn_opt, + struct ip_vs_seq in_seq; /* incoming seq. struct */ + struct ip_vs_seq out_seq; /* outgoing seq. struct */ + ); const struct ip_vs_pe *pe; char *pe_data; diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 4963fec815da..d4fe7bb4f853 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -603,7 +603,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, if (cp->flags & IP_VS_CONN_F_SEQ_MASK) { struct ip_vs_sync_conn_options *opt = (struct ip_vs_sync_conn_options *)&s[1]; - memcpy(opt, &cp->in_seq, sizeof(*opt)); + memcpy(opt, &cp->sync_conn_opt, sizeof(*opt)); } m->nr_conns++;