Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp533036rwd; Mon, 12 Jun 2023 18:14:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5I4P8RnXNSjM1SwQQcVitgSlFeAcZret4S9GHVt/9ufm+BKqgVFjhdeBS52e0IPPeXFIjv X-Received: by 2002:aa7:c70d:0:b0:514:7afc:67d4 with SMTP id i13-20020aa7c70d000000b005147afc67d4mr5251545edq.39.1686618861470; Mon, 12 Jun 2023 18:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686618861; cv=none; d=google.com; s=arc-20160816; b=W1bbrGap5xBz5AIzibGHjO640BngHc4dD/ix3GC6RpDRxZqo4zCLXZIlyA0He4LPGL edNfP5wA1qC+Ecg/HmL12r7phEjvWvsLO5UUklGqy0a81gUEqj+bOzrIOfT+qYvXoql7 gD0mYe8fvdl07MSkTRnXPf867mVOsKj82i/0vbFKlcMYMI/RgtpxmfQASy6ZMxljrMkd +F2spV80OyYZdAC25fBVLtWe2EKgzx2rlPduoadKoJqAn5jclJ1Br0RWW0lRiDQLxgAa VZiOSQFEZEklpkx7m2RLysk43hN0PndA8H7nHDLZirx3kUVOn+TKLjQpqXP0OhKdH/CN T1VQ== 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:dkim-signature; bh=wvMdVrWmm1KsKBFUWEX6pgpKCo/fWwZOLXy0dcLNEyU=; b=Dpb9UScjBg7TThYQVAlr39gbZwQrh52hkjZnhVZ0f6Gq3pMh7T2REC+C4K5JK2Pg0S siZ+1OWfr6o7I7XHXG0lo3nZFXhTp8LJmaKPhchy7wmEnvuGU7b+ItUeIEDa7nkUSur3 3yPLadfHUJazcEHo4UY2IPSChEGtFz+kPSi2vJZtaIhYX0l0JHNDlSQoKZ4LFIeC5Wjj 9nuf3E2u1gCxeezSF17eLwoOkXaTmJFKSXwq/fsFyXttswauck6rZBi7c9dHgjnzwpkD /JRdBB+WnlZJa+9Zi/NdvUY5WkjmgvL/r1hZ5020V+g1hzjmq4yjMHlV0C0x9MsyYC06 1hog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mCW+LG6b; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bo10-20020a0564020b2a00b005185ef8d2fcsi986820edb.500.2023.06.12.18.13.56; Mon, 12 Jun 2023 18:14:21 -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=@gmail.com header.s=20221208 header.b=mCW+LG6b; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237073AbjFMAes (ORCPT + 99 others); Mon, 12 Jun 2023 20:34:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbjFMAel (ORCPT ); Mon, 12 Jun 2023 20:34:41 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EACDE188; Mon, 12 Jun 2023 17:34:40 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-77ad3bba2a9so305273939f.1; Mon, 12 Jun 2023 17:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686616480; x=1689208480; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wvMdVrWmm1KsKBFUWEX6pgpKCo/fWwZOLXy0dcLNEyU=; b=mCW+LG6bMXAYtLCunsvonmLxyBwyUFcx5jUrWNVjeHc7toh2Dq4/vOar2JNiboPLme YcOH0Fu+C6tihvwzzV4+yjl3a4IPYxr19Og3DsyjYJg0mChL7A8gjWUvRQjPjr4213w4 Jfc35+Oj6B6tYLRkMf082yIDz6YpUeGnlo4OjrUHXMCekHvCreSqrC3KmpGGs5Wnf0cI IjB79ujFXXWDosvZfxjNzM/FPiUsCwj5V+SvNyaGdDZCyaw+ztAt5x5HR6YKSn8SjqnC v0Y+YLVRqSn5BO4mRLTRTc825WBm4b6PzRUqx/M8hNBp+O3e8rJC+HOZp6L8dSVPXWmP R0iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686616480; x=1689208480; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wvMdVrWmm1KsKBFUWEX6pgpKCo/fWwZOLXy0dcLNEyU=; b=LbwvehTKKdfwjPVj8sI+Z3dSKvjq/rxsQ6Uydz3GY5NHfBa1q6dgw2axtMroJAqOjQ n81o63lkYe2+EOiRscqaFThRGyQw2ayT8s/X5WPfcfxMKRYAtLNd7FdZ0bp86pQnXueh LorgTrlllmxXt87EE6lIqPTayvu9lz+S5Zr90wRzEMYrWAbcwJ73e+Yid7mtWq39IwXV FogEMl5YWiZSBNU7pGLyx9jwLBSSt2legyaagucsb47TcJm72+BhIKU2ijYU7lP4SZLJ VghEzfjbP6G87VWEBZChTA8qV74qShu7Pn7oli+FlG69rgcKl3Xb/YoyMIvBcThIXJ+l 9+dA== X-Gm-Message-State: AC+VfDy2f7Kkwe1EbboPb4LBwbPeWoLhn0JL9Fb4HG55MRSp58Zff6sW ZOjhRBsmT4F335ecVBJ5Cp0= X-Received: by 2002:a05:6602:1851:b0:77a:c00c:1166 with SMTP id d17-20020a056602185100b0077ac00c1166mr9660252ioi.15.1686616480236; Mon, 12 Jun 2023 17:34:40 -0700 (PDT) Received: from azeems-kspp.c.googlers.com.com (54.70.188.35.bc.googleusercontent.com. [35.188.70.54]) by smtp.gmail.com with ESMTPSA id f5-20020a056638118500b0041eb1fb695csm3115812jas.105.2023.06.12.17.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 17:34:39 -0700 (PDT) From: Azeem Shaikh To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal Cc: linux-hardening@vger.kernel.org, Azeem Shaikh , 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: [PATCH] netfilter: ipset: Replace strlcpy with strscpy Date: Tue, 13 Jun 2023 00:34:37 +0000 Message-ID: <20230613003437.3538694-1-azeemshaikh38@gmail.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 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 --- 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