Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4395248pxb; Mon, 21 Feb 2022 20:10:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyP/ODBfmN/nQl8wZa4dHWBB92n9WiinR/3Lt2rc2WNFT1fDlwydwyQm7+teCFn+gNj7CNU X-Received: by 2002:a17:90a:c28a:b0:1bc:66fd:b398 with SMTP id f10-20020a17090ac28a00b001bc66fdb398mr2181842pjt.153.1645503042538; Mon, 21 Feb 2022 20:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645503042; cv=none; d=google.com; s=arc-20160816; b=zNTrKPpetXsrZoa5A7khrJQGfgdKlIjkfwt6qK6wnrb87KUsOOtcFltQNoIymQt+Z6 YDf992+gkhFNYWiOofzQc9sPvDaCgu1+/IVdIIP+Br7hI800RWgIbWwiPnKR0PkIVAgr wqYbYUkt7eyuGwomy3T0k4HkaXgch4J4no8DJvooYhupsuAAlCAMVicIDlZCDDgd3eIf f6PYVyKL1wFt2D/4gGjJHeiJo/BjdQ7C+92hKI6n0tG09JGLCFj7SvBBjuf594rrfd5b tHIPLMxSwV35TlZPkmTMlqcin81Q3itP5eAMNCakbRVdj2MNFxqYpv9u7XWzWzfGlPnK ArCg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CDkJOU4+RIxbxi9bHg+qEDUKPGI4y2lVZrUrkl8jGtc=; b=JvkcweGqv7fdqZIql+2RUJLtAlcLANQjnwdxRACaL7qU9Y21ldSHP3JUYNT6QWgYF9 PWSXNrgv7sGcO5ncDzmhNvyQG5lzZyjNcHhBA4pSoA27eHFvgv75JoZ8XfNyUWUuOnMM QBv6pu+LEqjQrploXa+ztyAK43B9H79DJTbHbnzzlp1KxPT/U2pgDfdAAlNRjLGmrmBJ +Hf6qSguX6xauRDhI5wQqzYT9VL42+gQ3gqpKiAXt8OmbPHeGrlJmLbxptdObfcCHRmq Pf5bUeoU+s2/0y0UCUT0TO4J0l5XoUs8WmYmjTA966k04nGtBp/rh8U2OtKCgbf3HNh4 MOpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nh8NBTcs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ng7-20020a17090b1a8700b001b9f9bb4b30si1154209pjb.130.2022.02.21.20.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:10:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nh8NBTcs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B41E71CBD; Mon, 21 Feb 2022 20:10:33 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347532AbiBUJKE (ORCPT + 99 others); Mon, 21 Feb 2022 04:10:04 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347518AbiBUJFv (ORCPT ); Mon, 21 Feb 2022 04:05:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2BD2E0B5; Mon, 21 Feb 2022 00:59:14 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 4DAB7B80EAC; Mon, 21 Feb 2022 08:59:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 692F4C340E9; Mon, 21 Feb 2022 08:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433953; bh=8E9nmzjr+oVBPaIx2NahacyRPguKBnPNkSFQybHOK2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nh8NBTcs0TkzwRukRtwuhmzftU/fZRzQ07oUx85YDzP5Bkf+7feQ1xF79VW5fXGl+ 2G5nqUcBweSsCMvtM+adR7xNYZ0qEjtz/umDP/PkU0xdIbjCPRll/8XDv5PFedH5k2 ceY7+owFITHVfdgPyQx/tllRUSP7rPyT7LUAF6K4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianlin Shi , Xin Long , "David S. Miller" Subject: [PATCH 5.4 41/80] ping: fix the dif and sdif check in ping_lookup Date: Mon, 21 Feb 2022 09:49:21 +0100 Message-Id: <20220221084916.922438699@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Xin Long commit 35a79e64de29e8d57a5989aac57611c0cd29e13e upstream. When 'ping' changes to use PING socket instead of RAW socket by: # sysctl -w net.ipv4.ping_group_range="0 100" There is another regression caused when matching sk_bound_dev_if and dif, RAW socket is using inet_iif() while PING socket lookup is using skb->dev->ifindex, the cmd below fails due to this: # ip link add dummy0 type dummy # ip link set dummy0 up # ip addr add 192.168.111.1/24 dev dummy0 # ping -I dummy0 192.168.111.1 -c1 The issue was also reported on: https://github.com/iputils/iputils/issues/104 But fixed in iputils in a wrong way by not binding to device when destination IP is on device, and it will cause some of kselftests to fail, as Jianlin noticed. This patch is to use inet(6)_iif and inet(6)_sdif to get dif and sdif for PING socket, and keep consistent with RAW socket. Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind") Reported-by: Jianlin Shi Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ping.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -172,16 +172,23 @@ static struct sock *ping_lookup(struct n struct sock *sk = NULL; struct inet_sock *isk; struct hlist_nulls_node *hnode; - int dif = skb->dev->ifindex; + int dif, sdif; if (skb->protocol == htons(ETH_P_IP)) { + dif = inet_iif(skb); + sdif = inet_sdif(skb); pr_debug("try to find: num = %d, daddr = %pI4, dif = %d\n", (int)ident, &ip_hdr(skb)->daddr, dif); #if IS_ENABLED(CONFIG_IPV6) } else if (skb->protocol == htons(ETH_P_IPV6)) { + dif = inet6_iif(skb); + sdif = inet6_sdif(skb); pr_debug("try to find: num = %d, daddr = %pI6c, dif = %d\n", (int)ident, &ipv6_hdr(skb)->daddr, dif); #endif + } else { + pr_err("ping: protocol(%x) is not supported\n", ntohs(skb->protocol)); + return NULL; } read_lock_bh(&ping_table.lock); @@ -221,7 +228,7 @@ static struct sock *ping_lookup(struct n } if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif && - sk->sk_bound_dev_if != inet_sdif(skb)) + sk->sk_bound_dev_if != sdif) continue; sock_hold(sk);