Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp217965ybi; Fri, 26 Jul 2019 08:37:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQ1tsRkygS5LpakBLzsyxEOXfnSRmmTF2WQZF7yQFGBrNy91KV79sZbI9ddEwASvD94Oel X-Received: by 2002:a62:1807:: with SMTP id 7mr22395076pfy.149.1564155479037; Fri, 26 Jul 2019 08:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564155479; cv=none; d=google.com; s=arc-20160816; b=Umdv4OqFUu2MJzp3yHl94Ax6xDRlKAAW9Uz7EwSFNOUj3HWZlL4mucIpAl4NsCCTeT T4lbFBnqsEsgb1zAvZq0FxoanoCA/sUOo6fJVhu3D2G4ixfL4uG3Kg75VEs1nPh5/6pW MYYnm+6m/y0E0W74kWwln9PY6mv4d7AymUH1M2oChjY9Rv+Zhz3D8a/hB80yqU3VlbP9 9obsa24guCLxQhRiYerCah0Ir7/3bwUCQwYDZyrPzrk1JRpm6a/bXG4ruOKv/F6WNGY1 LC0UXj7k8m6estc+ofIG7HEKzxBGGm8bijSRxiLE2SYoPQ0vnFWbAkXm6xIq+Cn40xUs xtEg== 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=fipReHKMaU3lbSxojbSV1i7MnOQPu+NKtBk152Szmnk=; b=W25ph88ZPgA4NcfZQSpPk3bYa4a8hT7zCtfJJfEqnyBE4FJK/nOeB26gI+kMwpU6qr iTRiBM99jd23H4EaNPTjKaNC1m0xO8WhfCLIbGKDFWxJwkXrgCoBEKkxHQnLVEwmkzjI XMMKBqZ5zK1efwNSbfvez9Q9wujigQR/56mh+fI5AbcXghcarHF1Ot14HSxCQPUO3Vng aIwQxZyLptsNeWOhHLDEOohNdwWjgUzyR/OjONWlDr8YNSMcqVAJt9jZcfPWd9pmyeOc YKnvfp7uRLyqABqh4MjDb6XgdJ8CvufIISc0IbOjEJDrbeNT03dIZhCovktIjfdXl8JV BtJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XgYtMp2A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si16990470plv.26.2019.07.26.08.37.43; Fri, 26 Jul 2019 08:37:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XgYtMp2A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389581AbfGZPdD (ORCPT + 99 others); Fri, 26 Jul 2019 11:33:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389577AbfGZPdB (ORCPT ); Fri, 26 Jul 2019 11:33:01 -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 0DAD622CBD; Fri, 26 Jul 2019 15:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564155180; bh=bahlsBMkVkYMfpPIdhKmsQdccPk3ZEPzUihRE6jKl+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgYtMp2A13w6TdGSV02GJ5T726tLXPyiQCAd4V84wrthfU9h+RkqWpjFZAUCoTpnH Y5x2KNkuPNSbT//hX+8+w4b4sumMR5W5yW3/48iPbPekYY6IRpU37jC9Xc+5lUxnlj 13M+jOimmA5GUDh0Dpv+D1t1PFWd2BQ9b2e4fk4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Hangbin Liu , syzbot+6ca1abd0db68b5173a4f@syzkaller.appspotmail.com, "David S. Miller" Subject: [PATCH 4.19 04/50] igmp: fix memory leak in igmpv3_del_delrec() Date: Fri, 26 Jul 2019 17:24:39 +0200 Message-Id: <20190726152301.163583356@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190726152300.760439618@linuxfoundation.org> References: <20190726152300.760439618@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: Eric Dumazet [ Upstream commit e5b1c6c6277d5a283290a8c033c72544746f9b5b ] im->tomb and/or im->sources might not be NULL, but we currently overwrite their values blindly. Using swap() will make sure the following call to kfree_pmc(pmc) will properly free the psf structures. Tested with the C repro provided by syzbot, which basically does : socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3 setsockopt(3, SOL_IP, IP_ADD_MEMBERSHIP, "\340\0\0\2\177\0\0\1\0\0\0\0", 12) = 0 ioctl(3, SIOCSIFFLAGS, {ifr_name="lo", ifr_flags=0}) = 0 setsockopt(3, SOL_IP, IP_MSFILTER, "\340\0\0\2\177\0\0\1\1\0\0\0\1\0\0\0\377\377\377\377", 20) = 0 ioctl(3, SIOCSIFFLAGS, {ifr_name="lo", ifr_flags=IFF_UP}) = 0 exit_group(0) = ? BUG: memory leak unreferenced object 0xffff88811450f140 (size 64): comm "softirq", pid 0, jiffies 4294942448 (age 32.070s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 ................ 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ................ backtrace: [<00000000c7bad083>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline] [<00000000c7bad083>] slab_post_alloc_hook mm/slab.h:439 [inline] [<00000000c7bad083>] slab_alloc mm/slab.c:3326 [inline] [<00000000c7bad083>] kmem_cache_alloc_trace+0x13d/0x280 mm/slab.c:3553 [<000000009acc4151>] kmalloc include/linux/slab.h:547 [inline] [<000000009acc4151>] kzalloc include/linux/slab.h:742 [inline] [<000000009acc4151>] ip_mc_add1_src net/ipv4/igmp.c:1976 [inline] [<000000009acc4151>] ip_mc_add_src+0x36b/0x400 net/ipv4/igmp.c:2100 [<000000004ac14566>] ip_mc_msfilter+0x22d/0x310 net/ipv4/igmp.c:2484 [<0000000052d8f995>] do_ip_setsockopt.isra.0+0x1795/0x1930 net/ipv4/ip_sockglue.c:959 [<000000004ee1e21f>] ip_setsockopt+0x3b/0xb0 net/ipv4/ip_sockglue.c:1248 [<0000000066cdfe74>] udp_setsockopt+0x4e/0x90 net/ipv4/udp.c:2618 [<000000009383a786>] sock_common_setsockopt+0x38/0x50 net/core/sock.c:3126 [<00000000d8ac0c94>] __sys_setsockopt+0x98/0x120 net/socket.c:2072 [<000000001b1e9666>] __do_sys_setsockopt net/socket.c:2083 [inline] [<000000001b1e9666>] __se_sys_setsockopt net/socket.c:2080 [inline] [<000000001b1e9666>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2080 [<00000000420d395e>] do_syscall_64+0x76/0x1a0 arch/x86/entry/common.c:301 [<000000007fd83a4b>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 24803f38a5c0 ("igmp: do not remove igmp souce list info when set link down") Signed-off-by: Eric Dumazet Cc: Hangbin Liu Reported-by: syzbot+6ca1abd0db68b5173a4f@syzkaller.appspotmail.com Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/igmp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -1218,12 +1218,8 @@ static void igmpv3_del_delrec(struct in_ if (pmc) { im->interface = pmc->interface; if (im->sfmode == MCAST_INCLUDE) { - im->tomb = pmc->tomb; - pmc->tomb = NULL; - - im->sources = pmc->sources; - pmc->sources = NULL; - + swap(im->tomb, pmc->tomb); + swap(im->sources, pmc->sources); for (psf = im->sources; psf; psf = psf->sf_next) psf->sf_crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; } else {