All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Dingisoul <dingiso.kernel@gmail.com>
Cc: linux-sgx@vger.kernel.org, dave.hansen@linux.intel.com,
	tglx@kernel.org, mingo@redhat.com, bp@alien8.de, x86@kernel.org,
	hpa@zytor.com, shuangpeng.kernel@gmail.com
Subject: Re: [BUG] x86/sgx: missing kref_put() in sgx_encl_mm_add() error path
Date: Wed, 8 Apr 2026 11:58:11 +0300	[thread overview]
Message-ID: <adYYo727zh6BVGPp@kernel.org> (raw)
In-Reply-To: <20260330210957.839878-1-dingiso.kernel@gmail.com>

On Mon, Mar 30, 2026 at 05:09:57PM -0400, Dingisoul wrote:
> Hi Kernel maintainers,
> 
> We found a possible refcount leak in sgx_encl_mm_add().
> 
> In this function, a reference to encl->refcount is taken before registering the MMU notifier:
> 
> /* Grab a refcount for the encl_mm->encl reference: */
> kref_get(&encl->refcount);  // 1. Reference acquired here.
> encl_mm->encl = encl;
> 
> ret = __mmu_notifier_register(&encl_mm->mmu_notifier, mm);
> if (ret) {
> 	kfree(encl_mm);     
> 	return ret;         // 2. Returns without kref_put.
> }
> 
> If __mmu_notifier_register() fails, the function frees encl_mm but does not drop the reference acquired by kref_get(&encl->refcount). This seems to leak one reference to encl.
> 
> Please let us know if the kref_put is unnecessary here.
> 
> Thanks.

It is a leak as encl's, stored in file, will retain increased refcount.

BR, Jarkko

      parent reply	other threads:[~2026-04-08  8:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 21:09 [BUG] x86/sgx: missing kref_put() in sgx_encl_mm_add() error path Dingisoul
2026-03-30 21:15 ` Dave Hansen
2026-03-30 21:25   ` Dingisoul
2026-04-08  8:58 ` Jarkko Sakkinen [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=adYYo727zh6BVGPp@kernel.org \
    --to=jarkko@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dingiso.kernel@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=shuangpeng.kernel@gmail.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.