[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZMGJGlJ7XSG+2vjY@bombadil.infradead.org>
Date: Wed, 26 Jul 2023 13:59:06 -0700
From: Luis Chamberlain <mcgrof@...nel.org>
To: Michal Hocko <mhocko@...e.com>
Cc: Jean Delvare <jdelvare@...e.de>, linux-modules@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] module: print module name on refcount error
On Mon, Jul 10, 2023 at 07:43:01AM +0200, Michal Hocko wrote:
> On Fri 07-07-23 11:56:49, Luis Chamberlain wrote:
> > On Mon, Jul 03, 2023 at 03:47:22PM +0200, Michal Hocko wrote:
> > > On Fri 30-06-23 16:05:33, Luis Chamberlain wrote:
> > > [...]
> > > > What prevents code from racing the free with a random module_put()
> > > > called by some other piece of code?
> > >
> > > Wouldn't be ref count a garbage already? How can you race when freeing
> > > if module_put fail?
> >
> > It could yes, ie, so this risks at all being junk.
>
> Could you be more specific please? I still do not see a scenario where
> module string name would be junk while refcount itself would be a valid
> memory.
That is true, but if refcount is invalid so will the memory for the
string.
> > So best IMHO is
> > to tidy up all the get / puts and add respective tests to fix all
> > this mess with proper messages as needed. My cursory review of the
> > refcnt stuf is I see some races possible.
>
> It would likely be better to use refcount_t instead of atomic_t.
Patches welcomed.
> > While I'd be happy to help debugging aids, adding accesses to random
> > memory for a string seems more risk prone.
>
> If there is really a scenario when module could be unloaded leaving
> dangling struct module behind then we have a real problem as this is
> exported to userspace IIRC. Not to mention module_get/put calls
> modifying memory (UAF).
That doesn't mean issues could not exist, given its all protected under
privileged execution. All I'm suggesting is I look at this code and
don't trust it, and think it could use some love. The selftests for kmod
could be used to stress test but also stress-ng now also has module load
and unloading so if there are races we can likely exploit them with
either the kmod selftest or stress-ng module loading.
Luis
Powered by blists - more mailing lists