Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4474535pxj; Tue, 22 Jun 2021 00:42:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTKLpYqWuN6KES43/YnV0euqo3wd9mzkLRTrfFliQVnYE32LNYJGmaAdJkUmoaLQmmCEQU X-Received: by 2002:a17:907:7050:: with SMTP id ws16mr2496262ejb.95.1624347728085; Tue, 22 Jun 2021 00:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624347728; cv=none; d=google.com; s=arc-20160816; b=W1q8Lk/+f0ZtcTyAExc/SVIREHgBPnOK5YRiOfl8DiCoVgKOeksnmT/CVnkD8jqYh0 hRrqPpU5vM6E1ka2gGTvMvYAgujcVxuTeRO6vvhWtVRaIWnr1hrOuJjJsvx3dQuDcAL0 b/BHR11XyRoJe2tfG5bBjYV1cx1Hd1yE/xF9IdOJ+7qIluxVj9PTZu6kCDpkGCEgC0k/ 5LCIZUPLOrNj53x1psGux4pTshzpDTuvtAHjZDyzH1YzRAPPjC4z8hU+5tBniScmJPb/ 0WeXdVWh5vXzvyQXaFwo4FEvcbbODgnodSsBOGO2P5mecKe29Kni5yFfd+6VE/Hoe80v 3a9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xQyABpWzE19xRadtudcaP3+NTE2M7E6yiV97ca/yhww=; b=ECgeL5NUlS0xtO9ABuJTRxVwPolSz0lSZe+5IPgRAJQpps02EpKC3pEmJ223BqfDqm vP7RtZd8CxMx/FP9txNczGOJACwmSz6LClWUDmw/f3bFm4QRks7iZ7XX4i+NXFOPYHh6 f4nCWeN26CUiarGoNKqQMSOAv5P1Z5FPXOOdiUXWkYkOQc7N9L5DpydZSUdMTEmOSza+ Jql/el6CJsJ/76gjJHCPPuyrj6Ew7dzRl3VbV8yyjOBcufttaqIrIEucEp4udLljJaoz CVNs//70oQQ0D8R3tl8ui9wi7j3a6KO2QWD4gcBY7jphSBRsHrpenRz4usfHnnk8tI4o JwKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QZvDdaoO; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 20si13670912ejj.661.2021.06.22.00.41.45; Tue, 22 Jun 2021 00:42:08 -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=@gmail.com header.s=20161025 header.b=QZvDdaoO; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbhFVHmm (ORCPT + 99 others); Tue, 22 Jun 2021 03:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbhFVHmm (ORCPT ); Tue, 22 Jun 2021 03:42:42 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BECCC061574; Tue, 22 Jun 2021 00:40:26 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id he7so32935414ejc.13; Tue, 22 Jun 2021 00:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xQyABpWzE19xRadtudcaP3+NTE2M7E6yiV97ca/yhww=; b=QZvDdaoOkVYQLG8otklFFBe/0ZsEeILKWvXBF3qUOpC2R5PuSHowtJOHv9FApI3o/G OJNMWjLZb16lmrKAz3uL+iX2dPnIzSq+upTI8t7tb0SXLHPKDY4DHQvJPZ7FZRUJa3cg RU+X43a5PZO1baFqI3NF003p6IuuADeFuWosIslZil8GoyIa9akhb+OkxhTD8WxIYNsY k4202UDJX4KGzCosjI1MxXTlbx13XuOFh8Ou2+OPrrkbpuxm9BzBDEhAKRnO1ZCMPGS0 7M0B5maG0tUredvMuoEyC7tuGWbdpl+fWHvMLlmmduEFGy4UQUAfOMXmc/+dOD/MnOjp o1nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xQyABpWzE19xRadtudcaP3+NTE2M7E6yiV97ca/yhww=; b=DDLiXHMtKiihhZUtNCceDPfWe7sSj1sAWgdP8MDB+k0X8hEwTvXgUuybyckqDvai6L jiya/QY/cVUbykO2fum71BB8keUNh6dtGBy9NSgyR8/BmS5V+nC+FGGVydu60Sq0qT9X i5CJMQiJtcpLgXlmmxUWCelZA8vb+5k6vN4fOMxXzXXDQwgpCjxMuu3HY8UPTdZb0NGT lEDtz2Qbz8xZf62+VVten1SeHFceAw+98aIBAFRfmTpO8Ul8v/ze9XDo8m6QrfbKmMsx zCu/YKL6Zso7h3AmnidCE0zRLVYXv+wjx6OiK328QocrCNCkMByDxGxbd/Ld3/OeNRKU m2Cg== X-Gm-Message-State: AOAM5302cFH8zntZCady19R2cIQVPv1o/POndUFb2dSQBZz0C0oZJC5W 7wbnzT1dNdXrfYqsw/vft3ukmx9nbVT+7UYzOYs= X-Received: by 2002:a17:906:1486:: with SMTP id x6mr2559515ejc.69.1624347624690; Tue, 22 Jun 2021 00:40:24 -0700 (PDT) MIME-Version: 1.0 References: <20210618075925.803052-1-cccheng@synology.com> <20210622060419.GA29360@lst.de> In-Reply-To: <20210622060419.GA29360@lst.de> From: Chung-Chiang Cheng Date: Tue, 22 Jun 2021 15:40:13 +0800 Message-ID: Subject: Re: [PATCH] configfs: fix memleak in configfs_release_bin_file To: Christoph Hellwig Cc: jlbec@evilplan.org, Pantelis Antoniou , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chung-Chiang Cheng Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It works for me. I've verified it with ACPI configfs that is the only one using configfs binary attributes so far, and the memleak issue is solved. On Tue, Jun 22, 2021 at 2:04 PM Christoph Hellwig wrote: > > Hmm. The issue looks real, but I think we should just call the vfree > unconditionally given that the buffer structure is zeroed on allocation > and freed just after, and also remove the pointless clearing of all the > flags. Does something like this work for you? > > diff --git a/fs/configfs/file.c b/fs/configfs/file.c > index 53913b84383a..1ab6afb84f04 100644 > --- a/fs/configfs/file.c > +++ b/fs/configfs/file.c > @@ -393,11 +393,8 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file) > { > struct configfs_buffer *buffer = file->private_data; > > - buffer->read_in_progress = false; > - > if (buffer->write_in_progress) { > struct configfs_fragment *frag = to_frag(file); > - buffer->write_in_progress = false; > > down_read(&frag->frag_sem); > if (!frag->frag_dead) { > @@ -407,13 +404,9 @@ static int configfs_release_bin_file(struct inode *inode, struct file *file) > buffer->bin_buffer_size); > } > up_read(&frag->frag_sem); > - /* vfree on NULL is safe */ > - vfree(buffer->bin_buffer); > - buffer->bin_buffer = NULL; > - buffer->bin_buffer_size = 0; > - buffer->needs_read_fill = 1; > } > > + vfree(buffer->bin_buffer); > configfs_release(inode, file); > return 0; > }