Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4121518rwe; Mon, 17 Apr 2023 08:14:01 -0700 (PDT) X-Google-Smtp-Source: AKy350bPR22oSNOoWWi9V3+3PfCX/SIMw1LHsjB6EburOxCIaEZyM4yINjNggdKhYEvMrWc2TS9y X-Received: by 2002:a05:6a20:6984:b0:ec:6c32:4e35 with SMTP id t4-20020a056a20698400b000ec6c324e35mr18354546pzk.26.1681744441014; Mon, 17 Apr 2023 08:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681744440; cv=none; d=google.com; s=arc-20160816; b=cJcfXAQA5zzUT4+A0AqK4yjorx4snOG3eG2y+b5itRK0oj3W6d+NvnRSjp+TvKQhQ3 LKezP04MVCSFB6arUMb6PH2Wpt5nRVJ7rVaR1ODuO/v5VnN08JrN0jGyltfC38Li+FWz BXa7P/BD7I7xUQBXkd7WDjLE4amHMTKbup3LzqRjEmxtceTwDzAg0I/NjecjK3RsqnIb 38E2UCxle82lL9yywpduNqEovV27sZd8V8S1OFMPbWEBGTf22DbdXour2xr7VvPkuKZt YCkJZfaJ7TDV3xougjYUK5NzrbJINE7US0IYhM93Muee2LsNy9dEiB/mAhFg6ffYuQ72 KiXQ== 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=QQYt8B3t4tdm1qr2F60QMB/wSyN4pYivEqnfx4yEh8I=; b=KjRDFZuYdMgXIXcveSuntFxhHwQlI7+EExCVeOeK+TDiCs51hKc3TEisJDjZO77IfS tkQusV73sq6okn4Ndrf7J7JNPoQQpptC9kkSnO9tW1Ytz6wNDSdXozrchQ1tIH79NmZ2 XQvf0ditMP9s9tbfOzfRLh/SqMQ6jUKcIKxnsW27G85C1hazeOMNPDREG9XXSDrIo1IP JvNsYQFwHOQdz0ZBXQKQnTceX8vYMFrgpQr/TMtzRckYoYEJMEyiREfsDqehy0EOmNMf ViNyy184nnH1vXyKHtq5TXrcefZmGZDJcdcXlIPqeBibcROmLhX8VCaJCaOSg70wnijV CVbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aHfd5Es5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 16-20020a630b10000000b00519a8f54d2esi11532527pgl.479.2023.04.17.08.13.49; Mon, 17 Apr 2023 08:14:00 -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=aHfd5Es5; 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 S231130AbjDQPLi (ORCPT + 99 others); Mon, 17 Apr 2023 11:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231296AbjDQPL3 (ORCPT ); Mon, 17 Apr 2023 11:11:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A25847A84; Mon, 17 Apr 2023 08:11:23 -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 3DBB8626BF; Mon, 17 Apr 2023 15:11:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E71FC433D2; Mon, 17 Apr 2023 15:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681744282; bh=nFZaWwujVFrftUNAia1GiV9zhEX4XBBOtU64C6rgGTg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aHfd5Es54U+PSkGYFjqXdaOz+piDfKMh6VyNxXMY5qW0A644GvPjn7OZvqJYyoUr6 /2JlUZ7BLkYYAmD/VNbmAIJ5pUE5bnK8Z1gG8KO6aXD0n8T+MtF2A5aB9NKdo8OMer B1WlRRiM4WfrLVBXrNGplpBNYCkUbTkduOMnrj7vMFtvuteH8LmzTUZJXN4VHwoyr+ L9cNt5v+j9QmxhY/++d02Yp8qVUg7v4jbB8D0F9gYA+Hsw7HhU2loxUJ9JmdrxlOvN 4+1BXYFAo2m4zZl1+uID5Z+jJ+R1lD9RReitlqte8BQ4pvmTXhmUR45K+DiKjxmzAI L0zl5SiwftTBg== From: Simon Horman Date: Mon, 17 Apr 2023 17:10:45 +0200 Subject: [PATCH nf-next v3 1/4] ipvs: Update width of source for ip_vs_sync_conn_options MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230409-ipvs-cleanup-v3-1-5149ea34b0b9@kernel.org> References: <20230409-ipvs-cleanup-v3-0-5149ea34b0b9@kernel.org> In-Reply-To: <20230409-ipvs-cleanup-v3-0-5149ea34b0b9@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, Horatiu Vultur X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 Reviewed-by: Horatiu Vultur --- v3 - Add Horatiu's Reviewed-by tag v2 - Correct spelling of 'conn' in subject - No change --- 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++; -- 2.30.2