Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3327894ybl; Mon, 19 Aug 2019 16:48:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxki/gImtOoe86EYx4fmNfKRlZdl7Drx6q7O4FeqUbw81fN4QDkSaxy+sanM5KXySkz7gI9 X-Received: by 2002:aa7:9210:: with SMTP id 16mr27642768pfo.11.1566258524802; Mon, 19 Aug 2019 16:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566258524; cv=none; d=google.com; s=arc-20160816; b=j4KKAcI7bGmsrkPk7PFbl/h08TpwLjhJaZseNfUk7+73LV06nO0AlzQ9zH0fCFifyq EwLSuc1+X3PAzs8XvYzFkyFpGdrwRZysTNWdm+8N6Npkb1O4ZGWJweEKoD59ZWE6kzXa 16AATl7eV5+GRg7RVLbqN1trGQNMwPx7xYGI4tCeIh79cw9mlBbK1jfqvk9hc0/5IcY4 1PhkOgsaysWaljMkkFbVjw128OuZsIMGCjhTLfkhVBrZuXln/fmuGPKDny0wQ7OdcCzk nVlcJlQ7NFiHNfTVgtHkmhZkagCoNri8s5I0hNtB2YuiZLYGjF78t28OVUFcTjKLXvrt cL5A== 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=4Iy+tGZa9MuoKDFNlVuMOvVXUYJe5OTSe94gRpB2FE4=; b=VAJD0lwZaWHbKHo/7flb7EQLMjFi7foDE0UaxhZBdhx3kXePHlltXdnJQutW20KNWX uyqPQ4MeZUMMYPFFx3/zY+H0+dZyVZT83QIFTr0pEplJzzvyz8THc4aQkjcW/EEOpJyp 40tHTucOsVzlLYd4jqRSEsZzVKwhNdLoA+XDaIuE4tizq4wwYe1nnJTdRH8FIhB0lkic 6YISLbDikipogGlzcfIwOyuTvuBVLcQgAksEYydk3yJwZVJU4N8UsYH4HWHC2/pjx8uX Gh1e6lIKiTt8aphV4MpNkG5YOadFBZj/rweN03Kj39gXaVRx7XFTflIPq/34GDeEtanM Jkew== 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 b23si9625573pjp.62.2019.08.19.16.48.29; Mon, 19 Aug 2019 16:48:44 -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 S1728627AbfHSXrk (ORCPT + 99 others); Mon, 19 Aug 2019 19:47:40 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:42762 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728351AbfHSXrk (ORCPT ); Mon, 19 Aug 2019 19:47:40 -0400 Received: by mail-yw1-f65.google.com with SMTP id z63so1579434ywz.9; Mon, 19 Aug 2019 16:47:40 -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=4Iy+tGZa9MuoKDFNlVuMOvVXUYJe5OTSe94gRpB2FE4=; b=MoHO2qCA8nVuYZ/bh+uCz24CNnYoAxwHTqKqnguLc09RVo5HCeQALTX4QGwcsZQ06m XNcQfUHAG/ummrhOXvfQvSQ6cO+/m+8PcxBg5WDQNeACDYATutm1lj2Ppk4by4ijeIDj f81HgcVE29lyfK9qoGlVSx9yJXXuFbVDTAPpAa4Xcse+laSKf4C1gJiRlCMDW+Q3UyEm HwPwsFDDjWXLqFHtlnFuQpzUvZccyVZyUClx3RCMyi4Jj9xd2IFQYBCay749tVsg3f7X k/wdY8RBmznbiwhEmYZTomwhdqW17Yo2x7dwSN+u7C6f/A2gxEEnvjY6IiWssJbTjKgo dGZQ== X-Gm-Message-State: APjAAAUEzCP+P9lt7vVkEDrCK16i9LbefbaeEhf88tgS6GF6EMXc2DyL DfbNy/GvYaTQxqeYFKatJRk= X-Received: by 2002:a81:2305:: with SMTP id j5mr9857116ywj.81.1566258459429; Mon, 19 Aug 2019 16:47:39 -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 x138sm3357252ywg.4.2019.08.19.16.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Aug 2019 16:47:38 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Alexander Viro , Jeff Layton , "J. Bruce Fields" , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] locks: fix a memory leak bug Date: Mon, 19 Aug 2019 18:47:34 -0500 Message-Id: <1566258454-7684-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 __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; } -- 2.7.4