The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Mike Rapoport <rppt@kernel.org>, Jiangshan Yi <yijiangshan@kylinos.cn>
Cc: akpm@linux-foundation.org, shuah@kernel.org, ljs@kernel.org,
	liam@infradead.org, vbabka@kernel.org, surenb@google.com,
	mhocko@suse.com, linux-mm@kvack.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	13667453960@163.com
Subject: Re: [PATCH] selftests/mm: cow: fix leaks in child_vmsplice_memcmp_fn()
Date: Thu, 2 Jul 2026 09:58:07 +0200	[thread overview]
Message-ID: <c7effa7a-be9a-4172-8dba-642b1b31ff02@kernel.org> (raw)
In-Reply-To: <akYVVzhEpG3-D3LF@kernel.org>

On 7/2/26 09:37, Mike Rapoport wrote:
> On Thu, Jul 02, 2026 at 03:24:36PM +0800, Jiangshan Yi wrote:
>> child_vmsplice_memcmp_fn() allocated two heap buffers (old, new) and
>> opened a pipe, but every return path - including the normal one -
>> returned directly without freeing the buffers or closing the pipe file
>> descriptors. It also used the malloc() results without checking them,
>> so memcpy(old, mem, size) would crash on allocation failure (size can
>> be as large as a huge page).
>>
>> The sibling helper do_test_vmsplice_in_parent() in the same file already
>> uses the goto-based cleanup pattern; follow it here.
> 
> The difference is that child_vmsplice_memcmp_fn() runs in a forked process
> that dies if any error happens, so the allocated resources are anyway
> immediately freed.

I think this is the third time I have to reject such a patch. :)

> 
>> Check the allocations up front
> 
> This is the only check that is actually required, others are nice to have
> at best.
> 
> I'd keep the code simple and only add the allocation check that returns
> -ENOMEM on failure.

malloc() failing here is rather unlikely ... but yeah, why not.


-- 
Cheers,

David

      reply	other threads:[~2026-07-02  7:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  7:24 [PATCH] selftests/mm: cow: fix leaks in child_vmsplice_memcmp_fn() Jiangshan Yi
2026-07-02  7:37 ` Mike Rapoport
2026-07-02  7:58   ` David Hildenbrand (Arm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7effa7a-be9a-4172-8dba-642b1b31ff02@kernel.org \
    --to=david@kernel.org \
    --cc=13667453960@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=yijiangshan@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox