Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3794769ybz; Mon, 20 Apr 2020 09:34:19 -0700 (PDT) X-Google-Smtp-Source: APiQypK6umSzC1wndTedw/G2dpbIkPNcXk0xpFoT2j3nInD39sKBrD2M7fnFSeJldEU+meU7ciNN X-Received: by 2002:a05:6402:1297:: with SMTP id w23mr6201661edv.151.1587400459397; Mon, 20 Apr 2020 09:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587400459; cv=none; d=google.com; s=arc-20160816; b=no8n4KUVQqITsEc6Mxn3NGTBaoEaCZJp3xJAedMWvI+bArjZh8NbcuDz5cyGU5LRdv 10rtMmX28T1hGT7kDeuWuPGUP0SFYoZJhCxTitiadwJFCI0ZaWS/ODptbjXEBoJr7JfM j8Rv5wNp+fpvpjaaWoI8rUyWDet0mwXet5IC5NITFXxFAGyXj5O8ep9zeHyx8XTp6JYt fiOxBK1klFT73QTbAhqaafrLZnU2+yEQlaqxRAiMKPtYZHI6tREFzJjuhKTZ3KxPh2m2 +6Dcjl6ixqQ8PqsX4BY/7nDFvUsymxmfw0ZaTb5+vGlBCp2BL0Nz3H7STHwlyIB6iPRm rAZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kfBY5OV07BvCwU5FfKtAHwacD2w1a+kp9MEIK4Yil/M=; b=S4BXTnTW5CQyQj/HNuHh/mjo/n466K0bGniWXJUVlDSHwNS0KGPGW/3FvDzl0V/oBR zp1OoEv2kenIj/u8k0vn/Yde8uaLwXYmc9O0kTtJEnF+MjsrQAOIypVdGNsHqCTEwDKC 4J/ex9ivReCxjDzxUKcski1X1VeOD/QPc7hOlnmrsrT698BxkPwvxwBRHEr4jno5isAY LDxnqsYq0zhGCfuhD4sXKhZ8Z9fUtoY4cmp86YH2b1HLWhxsaYHjnGk+HVCXuSeX5Omm HvINVLqeUU4M4cVpZbprVor2aG3FN12QrNhVzt1WQPKF5d3SC2j57p3QQJxwoYmU5X6o IyJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2Y/x+Oad"; 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 a88si892530edf.379.2020.04.20.09.33.55; Mon, 20 Apr 2020 09:34:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b="2Y/x+Oad"; 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 S1729566AbgDTMva (ORCPT + 99 others); Mon, 20 Apr 2020 08:51:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:44904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729230AbgDTMsU (ORCPT ); Mon, 20 Apr 2020 08:48:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D7B3820735; Mon, 20 Apr 2020 12:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587386899; bh=X6HHSiGPxDds4aAYE1pVBzYbDO1xRfaiocXNMNWYJgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Y/x+Oadogk5hmFCTPTqxe4iHNtPJ6Q7YMy1l4ZyKeshhPNuc2eB3+grIGLXlawub 67+dIonItYnmImE4tlc09qxg4gic5oObA1mSaCP3gQ1t1575746dYwX33DVW7aythc ftg1E0A4/gnOJhdFD6LzJg64HFnJEHlRoa731maE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taras Chornyi , Vadym Kochan , "David S. Miller" Subject: [PATCH 4.19 03/40] net: ipv4: devinet: Fix crash when add/del multicast IP with autojoin Date: Mon, 20 Apr 2020 14:39:13 +0200 Message-Id: <20200420121450.667479590@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200420121444.178150063@linuxfoundation.org> References: <20200420121444.178150063@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Taras Chornyi [ Upstream commit 690cc86321eb9bcee371710252742fb16fe96824 ] When CONFIG_IP_MULTICAST is not set and multicast ip is added to the device with autojoin flag or when multicast ip is deleted kernel will crash. steps to reproduce: ip addr add 224.0.0.0/32 dev eth0 ip addr del 224.0.0.0/32 dev eth0 or ip addr add 224.0.0.0/32 dev eth0 autojoin Unable to handle kernel NULL pointer dereference at virtual address 0000000000000088 pc : _raw_write_lock_irqsave+0x1e0/0x2ac lr : lock_sock_nested+0x1c/0x60 Call trace: _raw_write_lock_irqsave+0x1e0/0x2ac lock_sock_nested+0x1c/0x60 ip_mc_config.isra.28+0x50/0xe0 inet_rtm_deladdr+0x1a8/0x1f0 rtnetlink_rcv_msg+0x120/0x350 netlink_rcv_skb+0x58/0x120 rtnetlink_rcv+0x14/0x20 netlink_unicast+0x1b8/0x270 netlink_sendmsg+0x1a0/0x3b0 ____sys_sendmsg+0x248/0x290 ___sys_sendmsg+0x80/0xc0 __sys_sendmsg+0x68/0xc0 __arm64_sys_sendmsg+0x20/0x30 el0_svc_common.constprop.2+0x88/0x150 do_el0_svc+0x20/0x80 el0_sync_handler+0x118/0x190 el0_sync+0x140/0x180 Fixes: 93a714d6b53d ("multicast: Extend ip address command to enable multicast group join/leave on") Signed-off-by: Taras Chornyi Signed-off-by: Vadym Kochan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/devinet.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -587,12 +587,15 @@ struct in_ifaddr *inet_ifa_byprefix(stru return NULL; } -static int ip_mc_config(struct sock *sk, bool join, const struct in_ifaddr *ifa) +static int ip_mc_autojoin_config(struct net *net, bool join, + const struct in_ifaddr *ifa) { +#if defined(CONFIG_IP_MULTICAST) struct ip_mreqn mreq = { .imr_multiaddr.s_addr = ifa->ifa_address, .imr_ifindex = ifa->ifa_dev->dev->ifindex, }; + struct sock *sk = net->ipv4.mc_autojoin_sk; int ret; ASSERT_RTNL(); @@ -605,6 +608,9 @@ static int ip_mc_config(struct sock *sk, release_sock(sk); return ret; +#else + return -EOPNOTSUPP; +#endif } static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, @@ -646,7 +652,7 @@ static int inet_rtm_deladdr(struct sk_bu continue; if (ipv4_is_multicast(ifa->ifa_address)) - ip_mc_config(net->ipv4.mc_autojoin_sk, false, ifa); + ip_mc_autojoin_config(net, false, ifa); __inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).portid); return 0; } @@ -907,8 +913,7 @@ static int inet_rtm_newaddr(struct sk_bu */ set_ifa_lifetime(ifa, valid_lft, prefered_lft); if (ifa->ifa_flags & IFA_F_MCAUTOJOIN) { - int ret = ip_mc_config(net->ipv4.mc_autojoin_sk, - true, ifa); + int ret = ip_mc_autojoin_config(net, true, ifa); if (ret < 0) { inet_free_ifa(ifa);