Re: [PATCHv2] mm: do not export const kfree and kstrdup variants
From: Sergey Senozhatsky
Date: Tue Sep 24 2024 - 02:57:06 EST
On (24/09/23 23:43), Christoph Hellwig wrote:
> On Tue, Sep 24, 2024 at 02:08:37PM +0900, Sergey Senozhatsky wrote:
> > Both kfree_const() and kstrdup_const() use __start_rodata
> > and __end_rodata, which do not work for modules. This is
> > especially important for kfree_const(). Stop exporting
> > these functions, as they cannot be used in the modules.
>
> Well, they do work when called from modules, they just don't work
> on constant data that is in modules. There's also plenty of
> existing callers in modules.
>
> So just unexporting them is going to break. The API is kinda
> horrible, but an implementation to check for constants in modules
> would also be quite horrible. So I don't have a good answer here,
> but simply unexporting them is not going to cut it.
Totally agree with all the points, I haven't looked at how
popular that API was before sending out the patch. Is there
some sort of "built time const" but for strings that we, perhaps,
can add to kfree_const() (and make kfree_const() always inline)?
So that we can turn this
str = "boom";
...
kfree_const(str);
into a safe scenario for modules.