Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2486681rwd; Fri, 16 Jun 2023 04:30:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jplSVgCuE6VNX+1ki3e7GksdsDubOc+4T3KBcJqeHD20nHOHqD813KOL6xcDgkqx4/SnZ X-Received: by 2002:a05:6358:cb24:b0:129:c1c1:f6de with SMTP id gr36-20020a056358cb2400b00129c1c1f6demr1534876rwb.10.1686915053144; Fri, 16 Jun 2023 04:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686915053; cv=none; d=google.com; s=arc-20160816; b=VfANL2CrGFS/F+g3LMw2JrAT5yJvBE1BeNMgp+rVVi3u03agdb4sw65diENgpn7CmL UUSpiJ189lasf+cZyi1bnRKYChancrYPa8caH9FuqZgsoN5bR4/mVs43vdrZBv5u7B5A t16lHmvXtZq+GyAHbNy3f0i2WbiJC1RvUUPZ9TP1bsGqqzhcgGbvHt8ey/DvwWtIkJ1K nnE0KhcjCs8bIa77FX/bY9eBlgfgnCmtQrbizhw7qX6u5nipoCIXgZEakpyFwrYI46TO CNzS/8ns8CJ8IWsbM1FjGUTj7TblhqPoIYnk5nO78nRVGtdbv80W6GncesVGYKku3Nn3 zsJw== 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=lnLoIGjIi2+8IjAx0m875W1Q3+Cv81DCyJza5YTswMk=; b=mWD9SC0fvTe2VfZMn/TWO9ja93k4DkObCCdyaa64hZvjFLDvkpNhf7FqutN19J+gSs JZIPB5TVoI4Ger2FZvFQAo7ujW9T1ae78yDkdLVYlna7NLSx3Wi0FUaOmqRj8FSUcsmQ GeugnRSC9jOJ/vGJRhXJJP9PZ/bRGxNvbqJTnNJLypkUR/M6JjC4dxQdlqrtnIA2qOq9 9rG4n0W73X5mYXoiMOboj+yNEcray3myQ4K10eJf5A5GCtC+bAPI45xYj/GoAtb/32k4 jnD2zRF+MIZesK+EXfY4h5cohyqHM1evDNVSSbes9cDB+oWOtryTom3qRrk2ZptDqGj5 kjyA== 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 m20-20020a637114000000b0054294720d51si15753085pgc.386.2023.06.16.04.30.41; Fri, 16 Jun 2023 04:30:53 -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 S235280AbjFPLLT (ORCPT + 99 others); Fri, 16 Jun 2023 07:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjFPLLS (ORCPT ); Fri, 16 Jun 2023 07:11:18 -0400 X-Greylist: delayed 602 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 16 Jun 2023 04:11:15 PDT Received: from smtp-out.kfki.hu (smtp-out.kfki.hu [148.6.0.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 022F1C5; Fri, 16 Jun 2023 04:11:14 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.kfki.hu (Postfix) with ESMTP id 0F2FCCC0100; Fri, 16 Jun 2023 12:51:21 +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; Fri, 16 Jun 2023 12:51:18 +0200 (CEST) Received: from blackhole.kfki.hu (blackhole.szhk.kfki.hu [148.6.240.2]) by smtp2.kfki.hu (Postfix) with ESMTP id 8219DCC00FE; Fri, 16 Jun 2023 12:51:16 +0200 (CEST) Received: by blackhole.kfki.hu (Postfix, from userid 1000) id 5CB2B3431A9; Fri, 16 Jun 2023 12:51:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by blackhole.kfki.hu (Postfix) with ESMTP id 5B076343155; Fri, 16 Jun 2023 12:51:16 +0200 (CEST) Date: Fri, 16 Jun 2023 12:51:16 +0200 (CEST) From: Jozsef Kadlecsik To: Azeem Shaikh cc: Pablo Neira Ayuso , Florian Westphal , linux-hardening@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: Re: [PATCH] netfilter: ipset: Replace strlcpy with strscpy In-Reply-To: <20230613003437.3538694-1-azeemshaikh38@gmail.com> Message-ID: References: <20230613003437.3538694-1-azeemshaikh38@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Tue, 13 Jun 2023, Azeem Shaikh wrote: > strlcpy() reads the entire source buffer first. > This read may exceed the destination size limit. > This is both inefficient and can lead to linear read > overflows if a source string is not NUL-terminated [1]. > In an effort to remove strlcpy() completely [2], replace > strlcpy() here with strscpy(). > > Direct replacement is safe here since return value from all > callers of STRLCPY macro were ignored. > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > [2] https://github.com/KSPP/linux/issues/89 > > Signed-off-by: Azeem Shaikh Acked-by: Jozsef Kadlecsik Best regards, Jozsef > --- > net/netfilter/ipset/ip_set_hash_netiface.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/net/netfilter/ipset/ip_set_hash_netiface.c b/net/netfilter/ipset/ip_set_hash_netiface.c > index 031073286236..95aeb31c60e0 100644 > --- a/net/netfilter/ipset/ip_set_hash_netiface.c > +++ b/net/netfilter/ipset/ip_set_hash_netiface.c > @@ -40,7 +40,7 @@ MODULE_ALIAS("ip_set_hash:net,iface"); > #define IP_SET_HASH_WITH_MULTI > #define IP_SET_HASH_WITH_NET0 > > -#define STRLCPY(a, b) strlcpy(a, b, IFNAMSIZ) > +#define STRSCPY(a, b) strscpy(a, b, IFNAMSIZ) > > /* IPv4 variant */ > > @@ -182,11 +182,11 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb, > > if (!eiface) > return -EINVAL; > - STRLCPY(e.iface, eiface); > + STRSCPY(e.iface, eiface); > e.physdev = 1; > #endif > } else { > - STRLCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out)); > + STRSCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out)); > } > > if (strlen(e.iface) == 0) > @@ -400,11 +400,11 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb, > > if (!eiface) > return -EINVAL; > - STRLCPY(e.iface, eiface); > + STRSCPY(e.iface, eiface); > e.physdev = 1; > #endif > } else { > - STRLCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out)); > + STRSCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out)); > } > > if (strlen(e.iface) == 0) > -- > 2.41.0.162.gfafddb0af9-goog > > > - 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