Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp469821yba; Wed, 15 May 2019 04:41:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwL8Zgb5a6+WOGFBpCOHOsbrMt1AsEvO41yjKYw1U/1cXjlw5q3NKoO1dhKiTv98IpmkXci X-Received: by 2002:a63:f54c:: with SMTP id e12mr43820835pgk.62.1557920483286; Wed, 15 May 2019 04:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920483; cv=none; d=google.com; s=arc-20160816; b=bYrn0G4mqi3HXV2srGJY9hnUARRYLXOH0/gBBr4HS19q3EWDoUYRhV5SWiGHNv7t2x zb8vnnf4wm2gLmEwsBP9pNunajx9FgP5CSRTXvGXuj7uF23pAvK07lglv5XAwkJhwmX4 Fo/d5JdGlfe0HkAxHKgDNuEner438vMe1M5B6l++1WobmwzmreWVEW/GcW5UDcKzwGkj kX3CqcQUoNozwViyyrh27JlNQPDOabhct1c8dTdAEJIr0e6QrC7YfXhdoy0etQsDASHX Sz2cIu3SDWq+71OaB9gCCtAFCyixn2qP2UB+w4gNtdWWvPhiCP3OMnzqh3wMKeTHOpiQ nrGQ== 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=GB75O5pDRE93wlRvIYK8Ij3ofjBYNkK44SohmxH2am4=; b=HNCPHJrmc3T5RAUbawVNb+8JyFpJH4qJVYDQIcJ/d+hTJbeFq29jmP1jnfTzhd03Z6 zXXAREP0FuUhw1AEnmXbrFKPZi3hlszS5jxOE/RRdTO9ygeg7GVzWZ19za5BegwMAvNx 5iNSPS6facHb/OIrgfz0fw3rvQ81dVehCZbm3xy2o+ZxjaOl1jQkd8WyLBIB7s57xWRg NCQKPZf94403Th/aKskNr5VtmElt5WSIF1GkNHIA6kkRmGCu81/6zQ5xmHrz7pvnkeNP wdXxGW3al7QyNcKXeMeurYYYkP+Wo0TQJPqUC2hQvfY0TXc73YA9V52vuO8r6ah+jmvv H46w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HO+Y8O4j; 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 a14si1867418pff.135.2019.05.15.04.41.08; Wed, 15 May 2019 04:41:23 -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=HO+Y8O4j; 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 S1732127AbfEOLjO (ORCPT + 99 others); Wed, 15 May 2019 07:39:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732718AbfEOLaY (ORCPT ); Wed, 15 May 2019 07:30:24 -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 BE8ED206BF; Wed, 15 May 2019 11:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919823; bh=UU3Ny3DXCIZiG/CnTQgtWArACPnuP6EUlUSiPWLi2ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HO+Y8O4jl+P1pdEys36TTI4JGKBsx+vWnTVzJZSCksKdS7IottOiaPPHjLiwW2W0n 3ZA3DIXcZPzblVpNzqjMDVzBlwjQVwhi0bSx2QLTwDrlemupq4osao5sBXXFdyoDjv u84UVBLR4LVZTF8oIOxPJOjzDKtXnOQ6kyLPDheQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Tobin C. Harding" , "David S. Miller" Subject: [PATCH 5.0 106/137] bridge: Fix error path for kobject_init_and_add() Date: Wed, 15 May 2019 12:56:27 +0200 Message-Id: <20190515090701.255944297@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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: "Tobin C. Harding" [ Upstream commit bdfad5aec1392b93495b77b864d58d7f101dc1c1 ] Currently error return from kobject_init_and_add() is not followed by a call to kobject_put(). This means there is a memory leak. We currently set p to NULL so that kfree() may be called on it as a noop, the code is arguably clearer if we move the kfree() up closer to where it is called (instead of after goto jump). Remove a goto label 'err1' and jump to call to kobject_put() in error return from kobject_init_and_add() fixing the memory leak. Re-name goto label 'put_back' to 'err1' now that we don't use err1, following current nomenclature (err1, err2 ...). Move call to kfree out of the error code at bottom of function up to closer to where memory was allocated. Add comment to clarify call to kfree(). Signed-off-by: Tobin C. Harding Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/bridge/br_if.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -602,13 +602,15 @@ int br_add_if(struct net_bridge *br, str call_netdevice_notifiers(NETDEV_JOIN, dev); err = dev_set_allmulti(dev, 1); - if (err) - goto put_back; + if (err) { + kfree(p); /* kobject not yet init'd, manually free */ + goto err1; + } err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj), SYSFS_BRIDGE_PORT_ATTR); if (err) - goto err1; + goto err2; err = br_sysfs_addif(p); if (err) @@ -700,12 +702,9 @@ err3: sysfs_remove_link(br->ifobj, p->dev->name); err2: kobject_put(&p->kobj); - p = NULL; /* kobject_put frees */ -err1: dev_set_allmulti(dev, -1); -put_back: +err1: dev_put(dev); - kfree(p); return err; }