lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4267108c-ac26-4528-97cc-0d160568baee@amd.com>
Date: Thu, 19 Jun 2025 16:43:00 +0530
From: Shivank Garg <shivankg@....com>
To: Gregory Price <gourry@...rry.net>
Cc: seanjc@...gle.com, david@...hat.com, vbabka@...e.cz, willy@...radead.org,
 akpm@...ux-foundation.org, shuah@...nel.org, pbonzini@...hat.com,
 brauner@...nel.org, viro@...iv.linux.org.uk, ackerleytng@...gle.com,
 paul@...l-moore.com, jmorris@...ei.org, serge@...lyn.com, pvorel@...e.cz,
 bfoster@...hat.com, tabba@...gle.com, vannapurve@...gle.com,
 chao.gao@...el.com, bharata@....com, nikunj@....com, michael.day@....com,
 yan.y.zhao@...el.com, Neeraj.Upadhyay@....com, thomas.lendacky@....com,
 michael.roth@....com, aik@....com, jgg@...dia.com, kalyazin@...zon.com,
 peterx@...hat.com, jack@...e.cz, rppt@...nel.org, hch@...radead.org,
 cgzones@...glemail.com, ira.weiny@...el.com, rientjes@...gle.com,
 roypat@...zon.co.uk, ziy@...dia.com, matthew.brost@...el.com,
 joshua.hahnjy@...il.com, rakie.kim@...com, byungchul@...com,
 kent.overstreet@...ux.dev, ying.huang@...ux.alibaba.com, apopple@...dia.com,
 chao.p.peng@...el.com, amit@...radead.org, ddutile@...hat.com,
 dan.j.williams@...el.com, ashish.kalra@....com, gshan@...hat.com,
 jgowans@...zon.com, pankaj.gupta@....com, papaluri@....com,
 yuzhao@...gle.com, suzuki.poulose@....com, quic_eberman@...cinc.com,
 aneeshkumar.kizhakeveetil@....com, linux-fsdevel@...r.kernel.org,
 linux-mm@...ck.org, linux-kernel@...r.kernel.org,
 linux-security-module@...r.kernel.org, kvm@...r.kernel.org,
 linux-kselftest@...r.kernel.org, linux-coco@...ts.linux.dev
Subject: Re: [RFC PATCH v8 4/7] mm/mempolicy: Export memory policy symbols



On 6/18/2025 8:42 PM, Gregory Price wrote:
> On Wed, Jun 18, 2025 at 11:29:32AM +0000, Shivank Garg wrote:
>> KVM guest_memfd wants to implement support for NUMA policies just like
>> shmem already does using the shared policy infrastructure. As
>> guest_memfd currently resides in KVM module code, we have to export the
>> relevant symbols.
>>
>> In the future, guest_memfd might be moved to core-mm, at which point the
>> symbols no longer would have to be exported. When/if that happens is
>> still unclear.
>>
>> Acked-by: David Hildenbrand <david@...hat.com>
>> Acked-by: Vlastimil Babka <vbabka@...e.cz>
>> Signed-off-by: Shivank Garg <shivankg@....com>
>> ---
>>  mm/mempolicy.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
>> index 3b1dfd08338b..d98243cdf090 100644
>> --- a/mm/mempolicy.c
>> +++ b/mm/mempolicy.c
>> @@ -354,6 +354,7 @@ struct mempolicy *get_task_policy(struct task_struct *p)
>>  
>>  	return &default_policy;
>>  }
>> +EXPORT_SYMBOL_GPL(get_task_policy);
>>  
>>  static const struct mempolicy_operations {
>>  	int (*create)(struct mempolicy *pol, const nodemask_t *nodes);
>> @@ -487,6 +488,7 @@ void __mpol_put(struct mempolicy *pol)
>>  		return;
>>  	kmem_cache_free(policy_cache, pol);
>>  }
>> +EXPORT_SYMBOL_GPL(__mpol_put);
>>  
> 
> I'm concerned that get_task_policy doesn't actually increment the policy
> refcount - and mpol_cond_put only decrements the refcount for shared
> policies (vma policies) - while __mpol_put decrements it unconditionally.
> 
> If you look at how get_task_policy is used internally to mempolicy,
> you'll find that it either completes the operation in the context of the
> task lock (allocation time) or it calls mpol_get afterwards.

I agree. But the semantics of my usage isn't new. shmem use this in same way.

I think the alloc_frozen_pages_noprof(), alloc_pages_bulk_mempolicy_noprof()
calls get_task_policy without task_lock or calling mpol_get.

> 
> Exporting this as-is creates a triping hazard, if only because get/put
> naming implies reference counting.

Since KVM is the only user, we could consider newly added EXPORT_SYMBOL_GPL_FOR_MODULES(..., "kvm")
to avoid wider exposure.
Does this solve your concern?
Or should we rename these functions.
What should be the preferred approach?

Thanks,
Shivank

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ