2021-03-12 11:50:24

by Rasmus Villemoes

[permalink] [raw]
Subject: [PATCH 1/2] devtmpfs: fix placement of complete() call

Calling complete() from within the __init function is wrong -
theoretically, the init process could proceed all the way to freeing
the init mem before the devtmpfsd thread gets to execute the return
instruction in devtmpfs_setup().

In practice, it seems to be harmless as gcc inlines devtmpfs_setup()
into devtmpfsd(). So the calls of the __init functions init_chdir()
etc. actually happen from devtmpfs_setup(), but the __ref on that one
silences modpost (it's all right, because those calls happen before
the complete()). But it does make the __init annotation of the setup
function moot, which we'll fix in a subsequent patch.

Fixes: bcbacc4909f1 ("devtmpfs: refactor devtmpfsd()")
Signed-off-by: Rasmus Villemoes <[email protected]>
---
drivers/base/devtmpfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 653c8c6ac7a7..aedeb2dc1a18 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -419,7 +419,6 @@ static int __init devtmpfs_setup(void *p)
init_chroot(".");
out:
*(int *)p = err;
- complete(&setup_done);
return err;
}

@@ -432,6 +431,7 @@ static int __ref devtmpfsd(void *p)
{
int err = devtmpfs_setup(p);

+ complete(&setup_done);
if (err)
return err;
devtmpfs_work_loop();
--
2.29.2


2021-03-12 16:28:46

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 1/2] devtmpfs: fix placement of complete() call

Looks fine:

Reviewed-by: Christoph Hellwig <[email protected]>

2021-03-18 12:48:14

by Rasmus Villemoes

[permalink] [raw]
Subject: Re: [PATCH 1/2] devtmpfs: fix placement of complete() call

On 12/03/2021 11.30, Rasmus Villemoes wrote:
> Calling complete() from within the __init function is wrong -
> theoretically, the init process could proceed all the way to freeing
> the init mem before the devtmpfsd thread gets to execute the return
> instruction in devtmpfs_setup().

Greg, ping? Also for the other one.

2021-03-18 12:55:07

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/2] devtmpfs: fix placement of complete() call

On Thu, Mar 18, 2021 at 01:44:04PM +0100, Rasmus Villemoes wrote:
> On 12/03/2021 11.30, Rasmus Villemoes wrote:
> > Calling complete() from within the __init function is wrong -
> > theoretically, the init process could proceed all the way to freeing
> > the init mem before the devtmpfsd thread gets to execute the return
> > instruction in devtmpfs_setup().
>
> Greg, ping? Also for the other one.

I'll pick this up for my tree, give me a chance to catch up, there's no
rush with this one :)

thanks,

greg k-h