Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* Invoke binary from kernel space
@ 2020-04-23 19:53 hemanth nandish
  2020-04-23 20:58 ` Valdis Klētnieks
  0 siblings, 1 reply; 2+ messages in thread
From: hemanth nandish @ 2020-04-23 19:53 UTC (permalink / raw)
  To: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1127 bytes --]

Hello,

I came across the function: call_usermodehelper
This can be used to invoke exec a binary from the kernel space.
It ultimately calls:
call_usermodehelper_exec_async

Which internally does:
retval = do_execve <https://elixir.bootlin.com/linux/v4.7/ident/do_execve>(
getname_kernel <https://elixir.bootlin.com/linux/v4.7/ident/getname_kernel>(
sub_info->path <https://elixir.bootlin.com/linux/v4.7/ident/path>),(const
char __user <https://elixir.bootlin.com/linux/v4.7/ident/__user> *const
__user <https://elixir.bootlin.com/linux/v4.7/ident/__user> *)sub_info->argv
<https://elixir.bootlin.com/linux/v4.7/ident/argv>,(const char __user
<https://elixir.bootlin.com/linux/v4.7/ident/__user> *const __user
<https://elixir.bootlin.com/linux/v4.7/ident/__user> *)sub_info->envp
<https://elixir.bootlin.com/linux/v4.7/ident/envp>);

This function works as expected and a new thread is spawned.
Now when I try to directly call do_execve within my module by passing the
required arguments, I am getting  -EFAULT error.
This is happening in this function:

count(argv, MAX_ARG_STRINGS)

What am I missing here?

Thank you
Hemanth

[-- Attachment #1.2: Type: text/html, Size: 7664 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: Invoke binary from kernel space
  2020-04-23 19:53 Invoke binary from kernel space hemanth nandish
@ 2020-04-23 20:58 ` Valdis Klētnieks
  0 siblings, 0 replies; 2+ messages in thread
From: Valdis Klētnieks @ 2020-04-23 20:58 UTC (permalink / raw)
  To: hemanth nandish; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 427 bytes --]

On Fri, 24 Apr 2020 01:23:45 +0530, hemanth nandish said:

> This function works as expected and a new thread is spawned.
> Now when I try to directly call do_execve within my module by passing the
> required arguments, I am getting  -EFAULT error.
> This is happening in this function:
>
> count(argv, MAX_ARG_STRINGS)
>
> What am I missing here?

My first guess is "the NULL pointer that indicates the end of the argv list".

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 19:53 Invoke binary from kernel space hemanth nandish
2020-04-23 20:58 ` Valdis Klētnieks

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git