Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2694995pxy; Tue, 3 Aug 2021 12:40:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIpvAHsk5JrDKtQskPl5dL+fSLD2/8I2HJYFoJnD+VK9ikKD4raSPV00DQRO5DZBn+yfC5 X-Received: by 2002:a92:c144:: with SMTP id b4mr2497ilh.159.1628019641170; Tue, 03 Aug 2021 12:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628019641; cv=none; d=google.com; s=arc-20160816; b=ccmLqMZlte7fNOcbs/v9OodGT3J9/fyJepsBRFvqBDxmEHWF89kptqclMDAYSwLELX ns7/kCPIL9u4pEPkHZecnUFcvdNojv98P06RfBQnjITBG20UNDxdxHHUU9y4Yr4e9lYo 42rU8jUWhorX7JCZAdd/Ks07kqjH7vDoBY24Wzgg/msfm8s+CqtjNO3nVyvkMBxS+LH2 obf9GDb+E8qncminnELP1XAV9z1AL6PlaKXfJHhgeZmQXqo6T/ftoVWrklKb/cyfPYRP vIcSHVGhSnVehpWtRYojy77Ra5GHpBK2rFditcl592Fm595rj4x5VIEgZOJf1U/GCzJS Rjdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date; bh=ZHThKTdP9i2PjaJRcdsiu/5K+FphL3LGV0w2PIpMMc8=; b=xD4wLu0Xp4bAHM73JNMmTE4H9uDZGDntlLXzrafdxrh1rEEdU2CiWURzlXEd3Q7hwI FZYyk1TeS98TYQOPjRP96u1jQb/PzSEU+ZOGpIRTXOATt8B/ONenNegS2wekcGzfbwlm TJJRjkgGrzF9smkOayUK6R//2U8Ehis9xL4m6vCI1DV0Ck3x2tUdw47ZkPQc+Bl5yNnT TKE15ExqtV25XPn9nsSlSZNN8zKDBzdyF2yOOAtgmttac+xV32/zTGekA+92ttbFQZsD hrQD0TVcrdhOiuKXgwFiXFXRskEZtp6COBjAnlo79PguQfzGDlbaMQU0gi/qOWv+dAXI zanA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si3230893jad.56.2021.08.03.12.40.27; Tue, 03 Aug 2021 12:40:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240083AbhHCTh5 (ORCPT + 99 others); Tue, 3 Aug 2021 15:37:57 -0400 Received: from smtp-out.kfki.hu ([148.6.0.48]:48979 "EHLO smtp-out.kfki.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240082AbhHCTh5 (ORCPT ); Tue, 3 Aug 2021 15:37:57 -0400 X-Greylist: delayed 422 seconds by postgrey-1.27 at vger.kernel.org; Tue, 03 Aug 2021 15:37:56 EDT Received: from localhost (localhost [127.0.0.1]) by smtp2.kfki.hu (Postfix) with ESMTP id 613E7CC0101; Tue, 3 Aug 2021 21:30:39 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at smtp2.kfki.hu Received: from smtp2.kfki.hu ([127.0.0.1]) by localhost (smtp2.kfki.hu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP; Tue, 3 Aug 2021 21:30:37 +0200 (CEST) Received: from blackhole.kfki.hu (blackhole.szhk.kfki.hu [148.6.240.2]) by smtp2.kfki.hu (Postfix) with ESMTP id E13B9CC00FC; Tue, 3 Aug 2021 21:30:36 +0200 (CEST) Received: by blackhole.kfki.hu (Postfix, from userid 1000) id D08AB340D60; Tue, 3 Aug 2021 21:30:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by blackhole.kfki.hu (Postfix) with ESMTP id CBB7B340D5D; Tue, 3 Aug 2021 21:30:36 +0200 (CEST) Date: Tue, 3 Aug 2021 21:30:36 +0200 (CEST) From: Jozsef Kadlecsik To: Nathan Chancellor cc: Pablo Neira Ayuso , Florian Westphal , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nick Desaulniers , kernel test robot Subject: Re: [PATCH] netfilter: ipset: Fix maximal range check in hash_ipportnet4_uadt() In-Reply-To: <20210803191813.282980-1-nathan@kernel.org> Message-ID: References: <20210803191813.282980-1-nathan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, 3 Aug 2021, Nathan Chancellor wrote: > Clang warns: > > net/netfilter/ipset/ip_set_hash_ipportnet.c:249:29: warning: variable > 'port_to' is uninitialized when used here [-Wuninitialized] > if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE) > ^~~~~~~ > net/netfilter/ipset/ip_set_hash_ipportnet.c:167:45: note: initialize the > variable 'port_to' to silence this warning > u32 ip = 0, ip_to = 0, p = 0, port, port_to; > ^ > = 0 > net/netfilter/ipset/ip_set_hash_ipportnet.c:249:39: warning: variable > 'port' is uninitialized when used here [-Wuninitialized] > if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE) > ^~~~ > net/netfilter/ipset/ip_set_hash_ipportnet.c:167:36: note: initialize the > variable 'port' to silence this warning > u32 ip = 0, ip_to = 0, p = 0, port, port_to; > ^ > = 0 > 2 warnings generated. > > The range check was added before port and port_to are initialized. > Shuffle the check after the initialization so that the check works > properly. > > Fixes: 7fb6c63025ff ("netfilter: ipset: Limit the maximal range of consecutive elements to add/delete") > Reported-by: kernel test robot > Signed-off-by: Nathan Chancellor Yes, good catch! Acked-by: Jozsef Kadlecsik Best regards, Jozsef > --- > net/netfilter/ipset/ip_set_hash_ipportnet.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/net/netfilter/ipset/ip_set_hash_ipportnet.c b/net/netfilter/ipset/ip_set_hash_ipportnet.c > index b293aa1ff258..7df94f437f60 100644 > --- a/net/netfilter/ipset/ip_set_hash_ipportnet.c > +++ b/net/netfilter/ipset/ip_set_hash_ipportnet.c > @@ -246,9 +246,6 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[], > ip_set_mask_from_to(ip, ip_to, cidr); > } > > - if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE) > - return -ERANGE; > - > port_to = port = ntohs(e.port); > if (tb[IPSET_ATTR_PORT_TO]) { > port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]); > @@ -256,6 +253,9 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[], > swap(port, port_to); > } > > + if (((u64)ip_to - ip + 1)*(port_to - port + 1) > IPSET_MAX_RANGE) > + return -ERANGE; > + > ip2_to = ip2_from; > if (tb[IPSET_ATTR_IP2_TO]) { > ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2_TO], &ip2_to); > > base-commit: 4d3fc8ead710a06c98d36f382777c6a843a83b7c > -- > 2.33.0.rc0 > > - E-mail : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.hu PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt Address : Wigner Research Centre for Physics H-1525 Budapest 114, POB. 49, Hungary