Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3241491ybl; Mon, 19 Aug 2019 14:57:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX6yRc1MRieAg8/1nh1P3lx6S4DzAeaoAK2x1hUPrcS81keQaUnXeIshwrWTgIHUhxPbct X-Received: by 2002:a63:460d:: with SMTP id t13mr21254461pga.205.1566251820393; Mon, 19 Aug 2019 14:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566251820; cv=none; d=google.com; s=arc-20160816; b=tTuj6f5h9Jd2bYC2476ZMnD5FwTMD2h3Ouc8elBccwEJhs9zZuV+wfujPQaZim4qaJ mRC7tDZQJauyJSwkF6JDPHINT2Pv7z1+a4v1mu7EG6lSwJ+Pm2YSSRMYxD1Q49KDWT7E K8+reNl4XK6VGHM9dV+B7FCDjO1SdRh67rQ7tEetnGfEytPLPs9eeHZiDEaoKa/AmBYp q8kUhECpmpxvRHWOJ/pHyRYd3tGyFHS4rQNyavaG/7UZfBL/Z9qol79gQRXFHu30A6B2 MoEmTedHwNjs0NWxWxCmCE7AUAmxWL8eVBV/7AR3YbGTonTJKsFiHQ+YWpv13dzognv7 kqkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=j8ArHqoH8hRKY32uSG2n9B6xxahAFt/eVeW0eXi2ctw=; b=dEoOSfla36OvMEzwzF7PdL4+jcjBlDc1DrC67ZSScibf+wRg9ycqXdF8Qvpj3RWIA7 XJJVkmTfidcil4g/z4gZ4Aer0cNmhfLFlwsp5b8G9urrfVpCAx6dUSZJeJUaKImsO6Y5 Rc4kFQKE2hA0WtbCb6h7AQ1foqtcdSyDFvPoYG107S80Vw7Di87NS3WeDjvXMoIvbXrw IaRFaQaDv/XSBlj8Ibth0k7s1Hh2mFDziaJOMjNqCyzMRjpKTFgHYFlBRAxujo8boqyd txvNTmBbrdix3uBO39YRIZXWA2smb3elw+kdOSYQ0hRTvkZ7hGGCTvBmtXgA9jEu7pv5 Q/1A== ARC-Authentication-Results: i=1; mx.google.com; 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 e5si10568400pgk.96.2019.08.19.14.56.45; Mon, 19 Aug 2019 14:57:00 -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; 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 S1728499AbfHSVzO (ORCPT + 99 others); Mon, 19 Aug 2019 17:55:14 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:41052 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728283AbfHSVzO (ORCPT ); Mon, 19 Aug 2019 17:55:14 -0400 Received: by mail-yw1-f68.google.com with SMTP id i138so1450740ywg.8 for ; Mon, 19 Aug 2019 14:55:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=j8ArHqoH8hRKY32uSG2n9B6xxahAFt/eVeW0eXi2ctw=; b=OTBwoCirHelODOBjjYOT7yneJNZw5CzlMnZuFXAqQkis6e/8UdUGhzDxJOMqlbaCR9 r8gqq0xrzkT7nBS+CO4lvk+m/cNA4tDaFIfbITigoZkc3gQET0O5pJXf6kM4361EkS8R ftU29Fvre7SHYH6I5Ioj5C0H5rkXPYj9ez4CDwwS9Z2tix//NO+ddJhsihSGd2clmMsJ MgJK5X+rCwCUcdVOM2xdw6jI4LOAY8gB1OSiBv2LnHFu+sKr7WWDg1wre/exzLZej1Za J2FLP//bHIFcUhO1a6RQ/YpP5DsbvEJXYAVKZdkeHZfoEoSjwOtsKqZoVQPtyprv538b mnVA== X-Gm-Message-State: APjAAAVeGYFU+czGsryg/pAlSa/kY/nn+xkpu/3V0g88WCeba20oAMtt WiX5u6ajPsmkJmD+vKMPb5g= X-Received: by 2002:a81:f81:: with SMTP id 123mr14292554ywp.469.1566251713421; Mon, 19 Aug 2019 14:55:13 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id x10sm3491960ywl.16.2019.08.19.14.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Aug 2019 14:55:12 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: David Woodhouse , Richard Weinberger , linux-mtd@lists.infradead.org (open list:JOURNALLING FLASH FILE SYSTEM V2 (JFFS2)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] jffs2: fix a memory leak bug Date: Mon, 19 Aug 2019 16:55:04 -0500 Message-Id: <1566251705-7133-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In jffs2_scan_eraseblock(), 'sumptr' is allocated through kmalloc() if 'sumlen' is larger than 'buf_size'. However, it is not deallocated in the following execution if jffs2_fill_scan_buf() fails, leading to a memory leak bug. To fix this issue, free 'sumptr' before returning the error. Signed-off-by: Wenwen Wang --- fs/jffs2/scan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 90431dd..5f7e284 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -527,8 +527,11 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo err = jffs2_fill_scan_buf(c, sumptr, jeb->offset + c->sector_size - sumlen, sumlen - buf_len); - if (err) + if (err) { + if (sumlen > buf_size) + kfree(sumptr); return err; + } } } -- 2.7.4