Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3824780ybl; Tue, 20 Aug 2019 02:52:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqymMSlNlb3zcLfaprjD8ktVu/YngJQMzf3l2LjnmuL8CjKnn8JWobxH0Y1TgNTNO2duRa5w X-Received: by 2002:a63:58c:: with SMTP id 134mr25030605pgf.106.1566294752733; Tue, 20 Aug 2019 02:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566294752; cv=none; d=google.com; s=arc-20160816; b=GX2r1AtIMd/6gUexON1NUeVha9exnqEOPrELeXj4bMad+4sjlXJvIfE3YfS5runoil KGEUkBe1WGrSDgpxXkLA8lrioUdkt4VZZSFsT0iMK7zVQBQraENWFvWJXCbLEDYRJCQ2 nMM6XsK4ETHhDg53HvlIikKg9hAdo9oWo5I/Rg6hedLPirJSIqw2i9L6CPP8xNWweMIb PHZM7RLpNDyQONziJYEU58Wc+9ROUKlv2VcXhDOJA5gJPawNwPXha2H4PIUhixjvOIz8 LytSNV54ToTPi2QJoynlfHwb1AIWDUJwMggk8ED32fbxHj/Q4ob2LLorYaEzzxFi6D0o nvHA== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=FHjVZVbPocy8U7Qs54IIjSRzDqw7lS0H9Wd4J7rCwEE=; b=oc6EwgalbxJPQAlNDSnUmsApdRDctk/hgyHyP4z8qk+uvKFcMm6IE3lEFbWJVvYsai oMhAcKJhoG78qlr2r7JFVXKCxuvYnPdkZFXGvuQsZgGernvG3mC3tDx1OAVKdQNq+DSS rfJ6xmu1zb+LZCeAXku5zZ+YFVM2zA8KWBw52aMrizPEdqMBQ8mP9j+ClXWEbrpJPM3f 5q7Sz5oj0Tz3e2BNZ3sE1yQaXuTSCbzU6ssszZfR7RX3ECmPDBWnSsfm0f9vozJ8kDRN XONn+uQC/cWk6+BBKhFSjtnvZ/TA7FHUhl0W4sr8P0oNI7bzs6m2X43H4HELltBojTHB iGVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JCTVilkL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2si10922573pjw.1.2019.08.20.02.52.17; Tue, 20 Aug 2019 02:52:32 -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=JCTVilkL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729733AbfHTJvZ (ORCPT + 99 others); Tue, 20 Aug 2019 05:51:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:59726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729396AbfHTJvZ (ORCPT ); Tue, 20 Aug 2019 05:51:25 -0400 Received: from tleilax.poochiereds.net (68-20-15-154.lightspeed.rlghnc.sbcglobal.net [68.20.15.154]) (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 882EE22CF7; Tue, 20 Aug 2019 09:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566294684; bh=K8sJJxvvQKJl8QWVEqPaTDFCFZYjha7QbbMLOeXPdr0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JCTVilkLtjMxPIUYr5HeBTQrzW68s+3jJ+9gXUohRnN7k1WBZ8mJrUKi10fRmqwnK s1F1eZIqCwofauy6ozMJQgUYs4EK1MQ9pvitZT8lS1JNq372YojVinHVCAggYt8T1x BBBa8l+5n90TkzXSdDoO+GXS2ajz9gEu2HAn1xGc= Message-ID: <25478fb3102ecebe09297948dcbb666c22845de1.camel@kernel.org> Subject: Re: [PATCH] locks: fix a memory leak bug From: Jeff Layton To: Wenwen Wang Cc: Alexander Viro , "J. Bruce Fields" , "open list:FILESYSTEMS (VFS and infrastructure)" , open list Date: Tue, 20 Aug 2019 05:51:22 -0400 In-Reply-To: <1566258454-7684-1-git-send-email-wenwen@cs.uga.edu> References: <1566258454-7684-1-git-send-email-wenwen@cs.uga.edu> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-08-19 at 18:47 -0500, Wenwen Wang wrote: > In __break_lease(), the file lock 'new_fl' is allocated in lease_alloc(). > However, it is not deallocated in the following execution if > smp_load_acquire() fails, leading to a memory leak bug. To fix this issue, > free 'new_fl' before returning the error. > > Signed-off-by: Wenwen Wang > --- > fs/locks.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/locks.c b/fs/locks.c > index 686eae2..5993b2a 100644 > --- a/fs/locks.c > +++ b/fs/locks.c > @@ -1592,7 +1592,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) > ctx = smp_load_acquire(&inode->i_flctx); > if (!ctx) { > WARN_ON_ONCE(1); > - return error; > + goto free_lock; > } > > percpu_down_read(&file_rwsem); > @@ -1672,6 +1672,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) > spin_unlock(&ctx->flc_lock); > percpu_up_read(&file_rwsem); > locks_dispose_list(&dispose); > +free_lock: > locks_free_lock(new_fl); > return error; > } Good catch! Merged for v5.4. Let me know if you think this needs to go in earlier and/or to stable kernels. Thanks, -- Jeff Layton