Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4432903pxb; Mon, 21 Feb 2022 21:27:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZyWUN58HHXPoKh6ozmmrQEe2O0r4GJ+92Ro9by8ht0nul6HwsOnig3lKvQSumA7TqQgs4 X-Received: by 2002:a05:6a00:124a:b0:4e1:7cfb:634c with SMTP id u10-20020a056a00124a00b004e17cfb634cmr23363882pfi.12.1645507673467; Mon, 21 Feb 2022 21:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645507673; cv=none; d=google.com; s=arc-20160816; b=h0o3cxvLg5YsfmDPG31WT3ZtWSA8/jaRPKEvve8DNPiU/qu5Htck3vrNB06M6bFh1n 72ZxfDIe0rN4ZGNmNxRpXO1nzmdFQNf2GfM3R6prmek3GNE9TpRhW1q0lxnoLiQDWmhG 1sjyHBcXR5oOvuquB6iF7NAUJxWrdcBBbKbuu7+E3QFgBVNmtCrMGxK5Yq3J2osZfMj3 TO85d9EqsSAlfogjR5PDeVZPmG1PnZCh/eqeKbpVBjjY2eCAnM2iJEisSsBXr+iyARhW AChvRj1MIkR1+RkOgiUe3HNzndXHu9RyVWO9X/D7gpsMeJuxp4vcQD4NOT5u8nJaY8od ITIA== 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=VwPFY1hzazSG6YHgDzyJMo1ijfkghnjaKJ1DpIghmmCi00rOZeNxSj8QKOts9Wz+uR VVMkTZ6H/JvlKay4lIfyKifEwNf+QTSSZaxVb/JqPW/3vPYEBNo1F+0SxxRSOR8QX4be YzuUs+P3EPe2PvNC8xxuCvlReYlWzCvpnNoj+PeASmrUb0OnzQNYJmMt03yD2twIhL/5 kQ5uS4MsF/dRgiNXEDmfDqxxIwpvqFbyYAIpobFiyYlxNAQssag0y7IJNdINDqYcdAmk K7mx34FVrNWvDiz1XG3InE5O6h4IrkzIcx6QPqAuOpI5hjGqcaKfh1r16/Raybv82igc 0TJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c9viq9eK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id g15si23517096pgk.863.2022.02.21.21.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:27:53 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c9viq9eK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 1B092B91C2; Mon, 21 Feb 2022 20:57:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352413AbiBUKA6 (ORCPT + 99 others); Mon, 21 Feb 2022 05:00:58 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352076AbiBUJwt (ORCPT ); Mon, 21 Feb 2022 04:52:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A874836686; Mon, 21 Feb 2022 01:23: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 6107DB80EA1; Mon, 21 Feb 2022 09:23:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78823C340E9; Mon, 21 Feb 2022 09:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435392; bh=8E9nmzjr+oVBPaIx2NahacyRPguKBnPNkSFQybHOK2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9viq9eKochMI1Fs9PXBIEtEwZEUgTvSIgLLTfr3GsbiU/SCS3dVJ8kQZUYaOP8AY AnK3EUkec5Y2HwVE7mYqXERtssqEq7YxeRuVDHHr/6wSzjZRfzadU5/hz5y8CAOawh LN9+Essro1C37FwTnDAxV1EHqTYXfy68R1rPq68M= 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.16 115/227] ping: fix the dif and sdif check in ping_lookup Date: Mon, 21 Feb 2022 09:48:54 +0100 Message-Id: <20220221084938.689761389@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@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);