Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp467802yba; Wed, 15 May 2019 04:38:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmCV7usMyjWP35NAXkUtpBGaWe1jWg5p0TLuymVA05sa+uKyd52cIBvBcZ29DyfBiN579G X-Received: by 2002:a63:2260:: with SMTP id t32mr5977003pgm.222.1557920321925; Wed, 15 May 2019 04:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920321; cv=none; d=google.com; s=arc-20160816; b=FhXA/EowF77pbxOJto6EseYdrouTlMf/s3F8Z1vH42ylm0WMld9KvUy65zdflUh6ey THCTw9zFXJKQ611aP5C70IlBAfjXQhDgIQCIC4A8UBGJHgd4nVB1x5ibsDtoBpKusire I6B04vaGgINvj/IDfO9JARLxf61O3N9xZ+smpum5LFlt2pZvY7cw/Fo/a4/8DdzZkrBW oDAxelTN1uu6j4CLeeH6Q6fwvuNazCCnsWBsNkZ8/s3dyve//ez/vW2jSrNxd7kxtbSN 7KJFhGo42ysCdi/ZV/gL/YGuV2gyZf4j558eMTL+MtlzqbeDQHVvQ6UPa2q+/wmdYLG5 Vfwg== 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=IF9hOWKsSLMwrLNcVZAkGydom5rLYTM3mJIx/P1PPmkLctIbscF88q5wQPTqy6eVUX D78XsnE27dOe9JeUf5eDb3sCwM3/GiELTTFsjmX2LKxDoBSz8fiMuc92amkO8VFfR8ea O11QIM/8NhweBzuqZInCNbhE1rW0UsDLUGYO1+mBenrQQtUyiGwzp0gzGV9gdCSrNkkw IJ+8tcRYUsp1F6tejx9sO45to8g8mdLWelB8/DATs8+1VlHVfnKLuJJgZnHuLcMeqOwm /2ipakxMT3IRXoTaO+HKjFmONmjjzpWdppO5LdZq8FXKnFW++f5trPX8/4haKKEZx1Vo 8uFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yx8XhmDP; 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 m5si1567349pgj.451.2019.05.15.04.38.27; Wed, 15 May 2019 04:38:41 -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=yx8XhmDP; 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 S1733033AbfEOLc3 (ORCPT + 99 others); Wed, 15 May 2019 07:32:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:44224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733007AbfEOLcW (ORCPT ); Wed, 15 May 2019 07:32:22 -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 71D7B2053B; Wed, 15 May 2019 11:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919941; bh=UU3Ny3DXCIZiG/CnTQgtWArACPnuP6EUlUSiPWLi2ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yx8XhmDPgwn50o0gLJbGfUsV1W34UtUtNm6bN74b5rGezHBF7B9XF0zDCLC22hrpK 75l/Twaflkp3BtQRGCUhPDxCsKX3k9Xnr4XcnDjm8D3lFUpEoyz1t27Kl/HyBG7QlS VYetWQI3gp3q4isJGQbEREflKToS2vISHmysLUgw= 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.1 15/46] bridge: Fix error path for kobject_init_and_add() Date: Wed, 15 May 2019 12:56:39 +0200 Message-Id: <20190515090622.969444556@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090616.670410738@linuxfoundation.org> References: <20190515090616.670410738@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; }