Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp876317pxk; Thu, 17 Sep 2020 20:02:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuvEWADDvJaXzKsPZzCW9FSHm5JpCoNWH0gh20krfMQ42dx1/624Se0FCZ3FTIVGoaFrOQ X-Received: by 2002:aa7:c554:: with SMTP id s20mr36080223edr.230.1600398179520; Thu, 17 Sep 2020 20:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398179; cv=none; d=google.com; s=arc-20160816; b=opO1SVCEXGuTqa9wQAHRKdUL/1p738p6UGT0x/7ROQM8TIDxJXwQdJ6mOL9Y0C/MDw I1xg7Z4NvBk77cQerzHqrUrdB/3a1qWJnFYVB95m0fciVXGOGjI2XFG/cIiax8P+vWge EWJQlOT/RXAAObnHnezhXaDlZly9Ao80z4x/QpsDlHkL7/J0C6643ggmiFl+2UfCGvfY FS6JEwJPr838fhXizI25MRJuQvbkhxvOKiC+lApq06tO5W2PLpmHW89HQRv2FxnTro+y meDvqMEc2Ll45atuHJMc3Wk3V41HbXrtxXgwaIqt3WsF7I1zifynmTpsjCUnyIKxhnhp OOGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nTOlokX0kDkfoaEvz/j/A+JOtZq8Q6SMb22o075K/lA=; b=Nzgp1AR6HFuwD4uTSJzzh8YZzrHQYTAQ1H8/rQkCgVHLa9P3mRX3PqgqX8LaoKlncy sC0WaM6coYBI+TK7+c2NlJpyZ14iW1y+Jesq7x9Mq8nhViggeTROrtRXp7D+J7InL0qX LXlRZHr8EWSQgoCWYPRrZGeYxD0TghnM74eAvzHLcgpKEyoQ6+eR51u5feiseTsfT1MO iHKneJLtqi0da4Z0RJqvsPcUkulB95Xb2hIkktkJZkrhv8B2VJGSRyem9ZHypHZyLb+9 tpRvAWosu7KHAGp9Um7EPMlppVFOta1O54iiIx7JpQZ0k3codR+KvyRtM8M9ic41NEkk vyVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xdAjwns8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si1178045edy.380.2020.09.17.20.02.36; Thu, 17 Sep 2020 20:02:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xdAjwns8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730442AbgIRDA3 (ORCPT + 99 others); Thu, 17 Sep 2020 23:00:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:54062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbgIRCFi (ORCPT ); Thu, 17 Sep 2020 22:05:38 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 08419238A0; Fri, 18 Sep 2020 02:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394737; bh=P1Nxwkmp1ODADvpVBMOspS3S8Fm6UaImrkwa3DwaVEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xdAjwns8md8HN8OSUDMaETtqOk2/eVc9UTnTfSNMUW7/Bi3rtQdXsBP9e5KdLWP5S EETQhwAsk8IW/jTBvG/tHhym7UWWDStSlLBWCH/7K/6w5hhqRRXJn7NkmwDzZPRjVC DNKPxn0T36b+at1pSN3WtCyNVoaLRa1sc9SDaxpU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhihao Cheng , Richard Weinberger , Sasha Levin , linux-mtd@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 218/330] ubifs: ubifs_add_orphan: Fix a memory leak bug Date: Thu, 17 Sep 2020 21:59:18 -0400 Message-Id: <20200918020110.2063155-218-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng [ Upstream commit 927cc5cec35f01fe4f8af0ba80830a90b0533983 ] Memory leak occurs when files with extended attributes are added to orphan list. Signed-off-by: Zhihao Cheng Fixes: 988bec41318f3fa897e2f8 ("ubifs: orphan: Handle xattrs like files") Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- fs/ubifs/orphan.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c index 7dd740e3692da..283f9eb48410d 100644 --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c @@ -157,7 +157,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) int err = 0; ino_t xattr_inum; union ubifs_key key; - struct ubifs_dent_node *xent; + struct ubifs_dent_node *xent, *pxent = NULL; struct fscrypt_name nm = {0}; struct ubifs_orphan *xattr_orphan; struct ubifs_orphan *orphan; @@ -181,11 +181,16 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) xattr_inum = le64_to_cpu(xent->inum); xattr_orphan = orphan_add(c, xattr_inum, orphan); - if (IS_ERR(xattr_orphan)) + if (IS_ERR(xattr_orphan)) { + kfree(xent); return PTR_ERR(xattr_orphan); + } + kfree(pxent); + pxent = xent; key_read(c, &xent->key, &key); } + kfree(pxent); return 0; } -- 2.25.1