linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs
@ 2017-01-24  5:36 Lokesh Vutla
  2017-02-01  9:24 ` Lokesh Vutla
  2017-02-01 12:28 ` Al Viro
  0 siblings, 2 replies; 4+ messages in thread
From: Lokesh Vutla @ 2017-01-24  5:36 UTC (permalink / raw)
  To: Al Viro, linux-kernel
  Cc: Linux ARM Mailing List, Tero Kristo, Sekhar Nori, Nishanth Menon,
	Muralidharan Karicheri, Lokesh Vutla

commit 4a9d4b024a31 ("switch fput to task_work_add") implements a
schedule_work() for completing fput(), but did not guarantee calling
__fput() after unpacking initramfs. Because of this, there is a
possibility that during boot a driver can see ETXTBSY when it tries
to load a binary from initramfs as fput() is still pending on that
binary. This patch makes sure that fput() is completed after unpacking
initramfs.

Reported-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
Link to RFC: https://patchwork.kernel.org/patch/9520539/
Changes since v1:
- Moved flush_delayed_fput() before loading default modules.

Note: Reproduced on TI K2HK EVM. K2HK Queue Manager subsystem driver[1] tries
to load a firmware from initramfs during boot. Sometimes loading of this
firmware fails with error ETXTBSY. Digging a bit more observed that
deny_write_access() is returning ETXTBSY as inode->i_writecount is > 0
for that file. This is because Unpacking initramfs does a
get_write_access(from open) but hasn't done put_write_access(from fput)
as it hasn't been scheduled yet.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/ti/knav_qmss_queue.c

 init/initramfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/init/initramfs.c b/init/initramfs.c
index b32ad7d97ac9..981f286c1d16 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -18,6 +18,7 @@
 #include <linux/dirent.h>
 #include <linux/syscalls.h>
 #include <linux/utime.h>
+#include <linux/file.h>
 
 static ssize_t __init xwrite(int fd, const char *p, size_t count)
 {
@@ -647,6 +648,7 @@ static int __init populate_rootfs(void)
 			printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
 		free_initrd();
 #endif
+		flush_delayed_fput();
 		/*
 		 * Try loading default modules from initramfs.  This gives
 		 * us a chance to load before device_initcalls.
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs
  2017-01-24  5:36 [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs Lokesh Vutla
@ 2017-02-01  9:24 ` Lokesh Vutla
  2017-02-01 12:28 ` Al Viro
  1 sibling, 0 replies; 4+ messages in thread
From: Lokesh Vutla @ 2017-02-01  9:24 UTC (permalink / raw)
  To: Al Viro, linux-kernel, akpm
  Cc: Linux ARM Mailing List, Tero Kristo, Sekhar Nori, Nishanth Menon,
	Muralidharan Karicheri

Hi All,

On Tuesday 24 January 2017 11:06 AM, Lokesh Vutla wrote:
> commit 4a9d4b024a31 ("switch fput to task_work_add") implements a
> schedule_work() for completing fput(), but did not guarantee calling
> __fput() after unpacking initramfs. Because of this, there is a
> possibility that during boot a driver can see ETXTBSY when it tries
> to load a binary from initramfs as fput() is still pending on that
> binary. This patch makes sure that fput() is completed after unpacking
> initramfs.
> 
> Reported-by: Murali Karicheri <m-karicheri2@ti.com>
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
> ---
> Link to RFC: https://patchwork.kernel.org/patch/9520539/
> Changes since v1:
> - Moved flush_delayed_fput() before loading default modules.
> 
> Note: Reproduced on TI K2HK EVM. K2HK Queue Manager subsystem driver[1] tries
> to load a firmware from initramfs during boot. Sometimes loading of this
> firmware fails with error ETXTBSY. Digging a bit more observed that
> deny_write_access() is returning ETXTBSY as inode->i_writecount is > 0
> for that file. This is because Unpacking initramfs does a
> get_write_access(from open) but hasn't done put_write_access(from fput)
> as it hasn't been scheduled yet.
> 
> [1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/soc/ti/knav_qmss_queue.c
> 
>  init/initramfs.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/init/initramfs.c b/init/initramfs.c
> index b32ad7d97ac9..981f286c1d16 100644
> --- a/init/initramfs.c
> +++ b/init/initramfs.c
> @@ -18,6 +18,7 @@
>  #include <linux/dirent.h>
>  #include <linux/syscalls.h>
>  #include <linux/utime.h>
> +#include <linux/file.h>
>  
>  static ssize_t __init xwrite(int fd, const char *p, size_t count)
>  {
> @@ -647,6 +648,7 @@ static int __init populate_rootfs(void)
>  			printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
>  		free_initrd();
>  #endif
> +		flush_delayed_fput();
>  		/*
>  		 * Try loading default modules from initramfs.  This gives
>  		 * us a chance to load before device_initcalls.
> 

Not sure who else to cc here, get_maintainer.pl gives only LKML.
Are there any comments on this patch?

Thanks and regards,
Lokesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs
  2017-01-24  5:36 [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs Lokesh Vutla
  2017-02-01  9:24 ` Lokesh Vutla
@ 2017-02-01 12:28 ` Al Viro
  2017-02-01 13:45   ` Lokesh Vutla
  1 sibling, 1 reply; 4+ messages in thread
From: Al Viro @ 2017-02-01 12:28 UTC (permalink / raw)
  To: Lokesh Vutla
  Cc: linux-kernel, Linux ARM Mailing List, Tero Kristo, Sekhar Nori,
	Nishanth Menon, Muralidharan Karicheri

On Tue, Jan 24, 2017 at 11:06:36AM +0530, Lokesh Vutla wrote:
> commit 4a9d4b024a31 ("switch fput to task_work_add") implements a
> schedule_work() for completing fput(), but did not guarantee calling
> __fput() after unpacking initramfs. Because of this, there is a
> possibility that during boot a driver can see ETXTBSY when it tries
> to load a binary from initramfs as fput() is still pending on that
> binary. This patch makes sure that fput() is completed after unpacking
> initramfs.

Umm...  Do we want it done in kernel_init(), then?  I have no objections
against calling it in populate_rootfs(), and it looks like a sane place
for that, but I wonder if the old callsite would remain needed after that...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs
  2017-02-01 12:28 ` Al Viro
@ 2017-02-01 13:45   ` Lokesh Vutla
  0 siblings, 0 replies; 4+ messages in thread
From: Lokesh Vutla @ 2017-02-01 13:45 UTC (permalink / raw)
  To: Al Viro
  Cc: linux-kernel, Linux ARM Mailing List, Tero Kristo, Sekhar Nori,
	Nishanth Menon, Muralidharan Karicheri



On Wednesday 01 February 2017 05:58 PM, Al Viro wrote:
> On Tue, Jan 24, 2017 at 11:06:36AM +0530, Lokesh Vutla wrote:
>> commit 4a9d4b024a31 ("switch fput to task_work_add") implements a
>> schedule_work() for completing fput(), but did not guarantee calling
>> __fput() after unpacking initramfs. Because of this, there is a
>> possibility that during boot a driver can see ETXTBSY when it tries
>> to load a binary from initramfs as fput() is still pending on that
>> binary. This patch makes sure that fput() is completed after unpacking
>> initramfs.
> 
> Umm...  Do we want it done in kernel_init(), then?  I have no objections
> against calling it in populate_rootfs(), and it looks like a sane place
> for that, but I wonder if the old callsite would remain needed after that...
> 

Hmm..You are right, the call in kernel_init() is unnecessary. Will post
an updated version.

Thanks and regards,
Lokesh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-01 13:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-24  5:36 [PATCH v2] initramfs: finish fput() before accessing any binary from initramfs Lokesh Vutla
2017-02-01  9:24 ` Lokesh Vutla
2017-02-01 12:28 ` Al Viro
2017-02-01 13:45   ` Lokesh Vutla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).