diff mbox series

[v4,01/12] nvdimm/pmem: Fix leak on dax_add_host() failure

Message ID 20240208184913.484340-2-mathieu.desnoyers@efficios.com (mailing list archive)
State New
Headers show
Series Introduce cpu_dcache_is_aliasing() to fix DAX regression | expand

Commit Message

Mathieu Desnoyers Feb. 8, 2024, 6:49 p.m. UTC
Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done
before setting pmem->dax_dev, which therefore issues the two following
calls on NULL pointers:

out_cleanup_dax:
        kill_dax(pmem->dax_dev);
        put_dax(pmem->dax_dev);

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: Mike Snitzer <snitzer@kernel.org>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: linux-arch@vger.kernel.org
Cc: linux-cxl@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-xfs@vger.kernel.org
Cc: dm-devel@lists.linux.dev
Cc: nvdimm@lists.linux.dev
---
 drivers/nvdimm/pmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Andrew Morton Feb. 8, 2024, 9:21 p.m. UTC | #1
On Thu,  8 Feb 2024 13:49:02 -0500 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:

> Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done
> before setting pmem->dax_dev, which therefore issues the two following
> calls on NULL pointers:
> 
> out_cleanup_dax:
>         kill_dax(pmem->dax_dev);
>         put_dax(pmem->dax_dev);

Seems inappropriate that this fix is within this patch series?

otoh I assume dax_add_host() has never failed so it doesn't matter much.


The series seems useful but is at v4 without much sign of review
activity.  I think I'll take silence as assent and shall slam it all
into -next and see who shouts at me.
Dan Williams Feb. 8, 2024, 9:28 p.m. UTC | #2
Mathieu Desnoyers wrote:
> Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done
> before setting pmem->dax_dev, which therefore issues the two following
> calls on NULL pointers:
> 
> out_cleanup_dax:
>         kill_dax(pmem->dax_dev);
>         put_dax(pmem->dax_dev);
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

Looks good to me.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Mathieu Desnoyers Feb. 8, 2024, 10:04 p.m. UTC | #3
On 2024-02-08 16:21, Andrew Morton wrote:
> On Thu,  8 Feb 2024 13:49:02 -0500 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
> 
>> Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done
>> before setting pmem->dax_dev, which therefore issues the two following
>> calls on NULL pointers:
>>
>> out_cleanup_dax:
>>          kill_dax(pmem->dax_dev);
>>          put_dax(pmem->dax_dev);
> 
> Seems inappropriate that this fix is within this patch series?
> 
> otoh I assume dax_add_host() has never failed so it doesn't matter much.
> 
> 
> The series seems useful but is at v4 without much sign of review
> activity.  I think I'll take silence as assent and shall slam it all
> into -next and see who shouts at me.
> 

Thanks Andrew for picking it up! Dan just reacted with feedback that
will help reducing the patch series size by removing intermediate
commits. I'll implement the requested changes and post a v5 in a few
days.

So far there are not behavior changes requested in Dan's feedback.

Should I keep this patch 01/12 within the series for v5 or should I
send it separately ?

Thanks,

Mathieu
Andrew Morton Feb. 8, 2024, 10:12 p.m. UTC | #4
On Thu, 8 Feb 2024 17:04:52 -0500 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:

> > The series seems useful but is at v4 without much sign of review
> > activity.  I think I'll take silence as assent and shall slam it all
> > into -next and see who shouts at me.
> > 
> 
> Thanks Andrew for picking it up! Dan just reacted with feedback that
> will help reducing the patch series size by removing intermediate
> commits. I'll implement the requested changes and post a v5 in a few
> days.

Yup.  I'll leave v4 out there for testers to bet on.

> So far there are not behavior changes requested in Dan's feedback.
> 
> Should I keep this patch 01/12 within the series for v5 or should I
> send it separately ?

Doesn't matter much, but perfectionism does say "standalone patch please".
Mathieu Desnoyers Feb. 8, 2024, 10:16 p.m. UTC | #5
On 2024-02-08 17:12, Andrew Morton wrote:
> On Thu, 8 Feb 2024 17:04:52 -0500 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:

[...]

>> Should I keep this patch 01/12 within the series for v5 or should I
>> send it separately ?
> 
> Doesn't matter much, but perfectionism does say "standalone patch please".

Will do. I plan to add the following statement to the commit message
to make it clear that there is a dependency between the patch series
and this fix:

[ Based on commit "nvdimm/pmem: Fix leak on dax_add_host() failure". ]

Thanks,

Mathieu
diff mbox series

Patch

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 4e8fdcb3f1c8..9fe358090720 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -566,12 +566,11 @@  static int pmem_attach_disk(struct device *dev,
 	set_dax_nomc(dax_dev);
 	if (is_nvdimm_sync(nd_region))
 		set_dax_synchronous(dax_dev);
+	pmem->dax_dev = dax_dev;
 	rc = dax_add_host(dax_dev, disk);
 	if (rc)
 		goto out_cleanup_dax;
 	dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
-	pmem->dax_dev = dax_dev;
-
 	rc = device_add_disk(dev, disk, pmem_attribute_groups);
 	if (rc)
 		goto out_remove_host;