Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4496533imm; Sat, 21 Jul 2018 22:02:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJz43PjfJ+7PvkpbUUUaSeCMDyviUeZMENCCNCRgTkPLSKDsru1BnprskHSfcC8AEGAv43 X-Received: by 2002:a63:647:: with SMTP id 68-v6mr7631671pgg.205.1532235769171; Sat, 21 Jul 2018 22:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532235769; cv=none; d=google.com; s=arc-20160816; b=MlJfIp+YNnMFoPoYxnhoVoyE2ddZ+3NWT7GG71gahzSHGNVG3X+7JDJ4HiY5j9JI5U 0aB68vOnRXwvLcX+IfiqyzFSmzuXUHxQAxstaeE8ph7mz6d9qAUkZ+sCqtj34/HEBeVL rAMoIdZhSnwznFbpU9+ZohyNH0bvwCwX4Saznbkib+Ql1edOTRprAcV0/njeO/CWFqd8 xHkgBKxlPgFguJ8aMvuZlHtJIAyxKV+jJ4Y4JPmorjwgpJAFFe4G/Hx7JDtZkwLq5tmG ewBUtBasrB4VnE2yOtHjeUimXbkHDEjgX2NMOOP25SwoCe3i+Gccp8zaIPnsZePVtMAM UqOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=+67K/KrzvvmjxzVPy3jGfMMFhvRW62N1sV67jZRNdqU=; b=J7tfmwnIo2HtuduksHmBVLhVPqt/ObBFYdwv9NWs0Sv8kccs86etK4kwLRxnQdyhzN st6+y4VASHM4QIhQxbH1hqBDlsIY3gk1feJSOhPqZLf5b6pp0tHz9TMHmY4jYJPtWlWh AHOKuHUBtitVMsU8a07Q/0eoeeCZInVDrGabr8JnuDiWMfUD1g39AJWzzn2PWi/m9Upn hTGf+UV439YOwHp9hEJhPjuDA26jrJ58PdST66TPdpGP/vicYzvZb27AHgOJOZVBwIe3 zJYGDMr2k6X8WNqz8SPyO6U2QC8A2pMZAIn3PGjVumhcdkf/r9UQzdwKUAHWSMpRLDZq 2OLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=M+m7TrAs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 80-v6si5823625pgf.604.2018.07.21.22.02.24; Sat, 21 Jul 2018 22:02:49 -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=@zx2c4.com header.s=mail header.b=M+m7TrAs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727872AbeGVF4W (ORCPT + 99 others); Sun, 22 Jul 2018 01:56:22 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:51963 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbeGVF4W (ORCPT ); Sun, 22 Jul 2018 01:56:22 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id d35ed52c; Sun, 22 Jul 2018 04:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=mime-version :references:in-reply-to:from:date:message-id:subject:to:cc :content-type; s=mail; bh=uI4k+BL24/Cs1Sdbow7t7gVyK9c=; b=M+m7Tr AsRQlLC8Khp8J7mU4cTqEDhV5gGx0UCJ3BTz/uIV6q7gZhvVqd1zr1pKgcIiKtul 6MQNWR0vSMjc+CS5TH9Um9eTjh75mRn258246TbBLRAaOD3Q641fPcY4jE2uEPrF nAB8/sowL8C7ioeLdiox3AdpD1pN9EtP8iJf6Pu6rL59quz1ZSPxZuQrAqmw+e4/ SNYxUiiYixJN90bU5B3PkBE+5qgRbfZ3UZ5B8I4aj/w0X8OCmrsLGUxc0Zxid5U1 IBhiQuUrbdR28RW9vgQMCYV86qfhjwUJmsD0a8qZ1w16JJVYeTb4z8+6wOIYfNjo oMkibIirfkZmSYig== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 17af482c (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128:NO); Sun, 22 Jul 2018 04:50:54 +0000 (UTC) Received: by mail-oi0-f43.google.com with SMTP id k81-v6so27927371oib.4; Sat, 21 Jul 2018 22:01:00 -0700 (PDT) X-Gm-Message-State: AOUpUlGIAJ0S44bb1MpO6FVh+xk2RZ4sOB6ydgQ3RC5KABHibkLGxDTf fXopmupC+K1EcKsE5GKDUsRney2n66k0DgGxKoc= X-Received: by 2002:aca:ceca:: with SMTP id e193-v6mr3911977oig.37.1532235659121; Sat, 21 Jul 2018 22:00:59 -0700 (PDT) MIME-Version: 1.0 References: <20180722024925.3176-1-cscnull@gmail.com> In-Reply-To: <20180722024925.3176-1-cscnull@gmail.com> From: "Jason A. Donenfeld" Date: Sun, 22 Jul 2018 07:00:47 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] netlink: fix memory leak To: cscnull@gmail.com Cc: Pablo Neira Ayuso , kadlec@blackhole.kfki.hu, Florian Westphal , David Miller , "Berg, Johannes" , Philippe Ombredanne , kstewart@linuxfoundation.org, Greg Kroah-Hartman , dsahern@gmail.com, lucien.xin@gmail.com, ktkhai@virtuozzo.com, Cong Wang , LKML , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Netdev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 22, 2018 at 4:51 AM Shaochun Chen wrote: > diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c > index 393573a99a5a..7b85176cf9bb 100644 > --- a/net/netlink/af_netlink.c > +++ b/net/netlink/af_netlink.c > @@ -2275,6 +2275,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, > struct netlink_callback *cb; > struct sock *sk; > struct netlink_sock *nlk; > + bool cb_running = false; > int ret; > > refcount_inc(&skb->users); > @@ -2317,6 +2318,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, > > nlk->cb_running = true; > nlk->dump_done_errno = INT_MAX; > + cb_running = true; > > mutex_unlock(nlk->cb_mutex); > > @@ -2339,6 +2341,8 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, > mutex_unlock(nlk->cb_mutex); > error_free: > kfree_skb(skb); > + if (cb_running) > + netlink_dump_start_fail(control); cb_running is never true here, since nothing jumps to error_free after you set it to be true. Pasting more code for context: nlk->cb_running = true; nlk->dump_done_errno = INT_MAX; 1) ----> cb_runnning = true; mutex_unlock(nlk->cb_mutex); ret = netlink_dump(sk); sock_put(sk); if (ret) A) return ret; /* We successfully started a dump, by returning -EINTR we * signal not to send ACK even if it was requested. */ B) return -EINTR; error_put: module_put(control->module); error_unlock: sock_put(sk); mutex_unlock(nlk->cb_mutex); error_free: kfree_skb(skb); 2) ----> if (cb_running) netlink_dump_start_fail(control); return ret; After (1) is set, the function exits via (A) or (B), and so (2) is never hit. But even if you moved it somehow to the if(ret), I'm still not sure it'd be correct; start cbs should either succeed, or they should error out and cleanup entirely after themselves. > return ret; > } > EXPORT_SYMBOL(__netlink_dump_start); > -- > 2.17.1 >