From patchwork Wed Jul 30 12:14:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 34518 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 29B7A20792 for ; Wed, 30 Jul 2014 12:34:01 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf6088662iec.8 for ; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=h5/XnV7CVtY5rhEhOKR9Xvt5n5cEg+elxLFnKp8FtT0=; b=PVqhv+q+A0h7eRKgOd6cn05TaZKJrVKVVh4CWknm2Qo5NF5apfjEOYu7e15tlhCat1 IizxHCzGQ2kpsXUzUoR7OpbhrSbu5/UMqWvHdlkTGA/OHHuAxHHLZlhCVA7MWEmvA/bk TdkUSY7tA+bImiZrbiU5r6V7F25IVQcnA/83i+opGV7PbEBssL2WCB3VlP00/oP+1dJH 88cEFWh3B5I+plZZWjqb4lGKtOEX0413J2FMdEKXNVAp49CauLmZjmg9L+CosXTFynDV BPZLSkQRnaOvESGhrbvnrbNt2/UaNIYIaVqYAHDPVowLMnXLhR5lfxtaJa0JC+As4INm ZMBg== X-Gm-Message-State: ALoCoQn+oUV6QZmUOWVVzehYwha1vPB0cv2fjSthMdOa+r+DxSdyfmhTxkz3tw1AdMI0dVCq02pg X-Received: by 10.182.107.135 with SMTP id hc7mr1499232obb.48.1406723640683; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.11 with SMTP id n11ls482332qge.11.gmail; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) X-Received: by 10.220.68.208 with SMTP id w16mr707080vci.79.1406723640476; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id wv1si1453356vdb.80.2014.07.30.05.34.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 05:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so1608926vcb.35 for ; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr644727vdj.95.1406723640398; Wed, 30 Jul 2014 05:34:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp23862vcb; Wed, 30 Jul 2014 05:33:59 -0700 (PDT) X-Received: by 10.70.36.33 with SMTP id n1mr4374210pdj.26.1406723639214; Wed, 30 Jul 2014 05:33:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pk4si2278727pac.99.2014.07.30.05.33.58 for ; Wed, 30 Jul 2014 05:33:59 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753908AbaG3Mdn (ORCPT + 26 others); Wed, 30 Jul 2014 08:33:43 -0400 Received: from ip4-83-240-18-248.cust.nbox.cz ([83.240.18.248]:36724 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905AbaG3MPc (ORCPT ); Wed, 30 Jul 2014 08:15:32 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XCSn4-00043e-SW; Wed, 30 Jul 2014 14:15:30 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dingtianhong , "David S. Miller" , Jiri Slaby Subject: [PATCH 3.12 46/94] igmp: fix the problem when mc leave group Date: Wed, 30 Jul 2014 14:14:35 +0200 Message-Id: <31ae2665fbbd0aaa3636b9d3e2cf161f95eb67eb.1406722270.git.jslaby@suse.cz> X-Mailer: git-send-email 2.0.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: dingtianhong 3.12-stable review patch. If anyone has any objections, please let me know. =============== [ Upstream commit 52ad353a5344f1f700c5b777175bdfa41d3cd65a ] The problem was triggered by these steps: 1) create socket, bind and then setsockopt for add mc group. mreq.imr_multiaddr.s_addr = inet_addr("255.0.0.37"); mreq.imr_interface.s_addr = inet_addr("192.168.1.2"); setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 2) drop the mc group for this socket. mreq.imr_multiaddr.s_addr = inet_addr("255.0.0.37"); mreq.imr_interface.s_addr = inet_addr("0.0.0.0"); setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 3) and then drop the socket, I found the mc group was still used by the dev: netstat -g Interface RefCnt Group --------------- ------ --------------------- eth2 1 255.0.0.37 Normally even though the IP_DROP_MEMBERSHIP return error, the mc group still need to be released for the netdev when drop the socket, but this process was broken when route default is NULL, the reason is that: The ip_mc_leave_group() will choose the in_dev by the imr_interface.s_addr, if input addr is NULL, the default route dev will be chosen, then the ifindex is got from the dev, then polling the inet->mc_list and return -ENODEV, but if the default route dev is NULL, the in_dev and ifIndex is both NULL, when polling the inet->mc_list, the mc group will be released from the mc_list, but the dev didn't dec the refcnt for this mc group, so when dropping the socket, the mc_list is NULL and the dev still keep this group. v1->v2: According Hideaki's suggestion, we should align with IPv6 (RFC3493) and BSDs, so I add the checking for the in_dev before polling the mc_list, make sure when we remove the mc group, dec the refcnt to the real dev which was using the mc address. The problem would never happened again. Signed-off-by: Ding Tianhong Signed-off-by: David S. Miller Signed-off-by: Jiri Slaby --- net/ipv4/igmp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 7defdc9ba167..9fa5c0908ce3 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -1952,6 +1952,10 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) rtnl_lock(); in_dev = ip_mc_find_dev(net, imr); + if (!in_dev) { + ret = -ENODEV; + goto out; + } ifindex = imr->imr_ifindex; for (imlp = &inet->mc_list; (iml = rtnl_dereference(*imlp)) != NULL; @@ -1969,16 +1973,14 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) *imlp = iml->next_rcu; - if (in_dev) - ip_mc_dec_group(in_dev, group); + ip_mc_dec_group(in_dev, group); rtnl_unlock(); /* decrease mem now to avoid the memleak warning */ atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); kfree_rcu(iml, rcu); return 0; } - if (!in_dev) - ret = -ENODEV; +out: rtnl_unlock(); return ret; }