Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp489128yba; Wed, 15 May 2019 05:03:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2YzVfsFGb2j9d3gETTNJ0EvXr9vscjyQFu+cfZbKvzJ+2nsTr/Gf8Pd391btlZ1LtoJdl X-Received: by 2002:a63:ed12:: with SMTP id d18mr44575420pgi.248.1557921826948; Wed, 15 May 2019 05:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557921826; cv=none; d=google.com; s=arc-20160816; b=oNp1eF1XBJbrCtcD/TqJPxpGr8B8Vx2jg7yCRJPnCVV8Yfa/M+IU9SOzgp1TmkiMwE 3UK8YmTmVGUu6b4QKd3sx4bQVOdZqCJ1NBhJ6tKtoOu0dIpv4rJrjkdK1T0NBpweUCMB jVDufnrbV8lAmE1R/ggr0U/itRi18slW5Cz+eRQOWhoVSBYH91fcqmtokM4VeZZQEzPb TBS6tBnZbNk31/suTdN+f5wG1sZ06z7XrRqILJMdkgJP1flfceqUIWqFSpdNKeiohF8R Y+icXZ7LBROyL8rjGz38M+iIGWV95sXwd59Bg+Obsi572G0N9Kf4WOW1mxuW380J47LC fJig== 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=Z+snhkuHZqCVhOvXGxEZVYic594NooEhPUAhWdOfId8=; b=k2OpUGropRay5cMy/xRA1veOhL/H32MYZ8Sd2zyTBnQtn7gI3Lvt6NLKf48tdCtEPd t1qF9FBIvbBWA/+1wRT4lj+SaoPSXdmjGzd1tG/u+B3Zp3Mk/YM/oUgyGl7/VUJWJnxx yBFbhOmLMp7+v4aI/vaPMHG0okm5MUewobVDgJjP5BHkvIdN4vONBY2h4nOa8kiOcQwN WQV0IVwG/x4q/8bCG41EX74OPRakyXACggD8cmUSkezcyrUmzkMWYrUqWrQaJBfNsp92 sgyyKPlZsPkVHuLqEHCWJe36/BjbdnKTM4V2WHDQKWzz8yt98JmySqZERhUT30iiKhQ9 1RGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="esqfv/I6"; 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 p188si1943630pfp.112.2019.05.15.05.03.31; Wed, 15 May 2019 05:03:46 -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="esqfv/I6"; 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 S1730534AbfEOMAR (ORCPT + 99 others); Wed, 15 May 2019 08:00:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:51154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbfEOLOw (ORCPT ); Wed, 15 May 2019 07:14:52 -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 B5EAE20843; Wed, 15 May 2019 11:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557918892; bh=rfHNivLtK0FwOga3PE75e8224BeOh40qOTB60qT6/uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=esqfv/I6y0CjA6H48Yl55kSUJSp9AmxpxkNOQsxShgmRVKE5EtOHmBwQl3huUxuOh ADFX5tMMtaN51lzlZK+QAi87sEtf7tBkDHo4vH+tZ6G5KKLkrEWyY6Kemb2h/O0/dq ToWSUZ8kM95m8UiiWLL+Vtaib+2A6WMpFIx5PHR4= 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 4.9 40/51] bridge: Fix error path for kobject_init_and_add() Date: Wed, 15 May 2019 12:56:15 +0200 Message-Id: <20190515090627.915124616@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090616.669619870@linuxfoundation.org> References: <20190515090616.669619870@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 @@ -519,13 +519,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) @@ -608,12 +610,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; }