public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arun Sharma <arun.sharma@intel.com>
To: linux-kernel@vger.kernel.org
Subject: binfmt handler searching issues
Date: Mon, 28 Jul 2003 14:11:49 -0700	[thread overview]
Message-ID: <3F259195.7070707@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

A script such as

#!/bin/foo.bar
...

where /bin/foo.bar is handled by binfmt_misc, is not handled correctly i.e. the interpreter of foo.bar doesn't receive the correct arguments.

The binfmt_misc handler requires that bprm->filename is appropriately filled so that the argv[1] could be correctly passed to the interpreter.

However, binfmt_script, as it exists today doesn't populate bprm->filename correctly.

Another motivation for this patch is the output of ps. Emulators which use binfmt_misc may want to keep the output of ps consistent with native execution. This requires preserving bprm->filename. The attached patch guarantees this even if we have to go through several binfmt handlers (think of finite loops involving  binfmt_script and binfmt_misc).

        -Arun

[-- Attachment #2: binfmt_interp.patch --]
[-- Type: text/plain, Size: 2349 bytes --]

--- linux/fs/exec.c-	Thu Mar 13 11:42:51 2003
+++ linux/fs/exec.c	Thu Mar 13 11:43:05 2003
@@ -882,6 +882,7 @@
 
 	bprm.file = file;
 	bprm.filename = filename;
+	bprm.interp = filename;
 	bprm.sh_bang = 0;
 	bprm.loader = 0;
 	bprm.exec = 0;
--- linux/fs/binfmt_script.c-	Thu Mar 13 12:09:28 2003
+++ linux/fs/binfmt_script.c	Thu Mar 13 12:09:46 2003
@@ -78,6 +78,8 @@
 	retval = copy_strings_kernel(1, &i_name, bprm);
 	if (retval) return retval; 
 	bprm->argc++;
+	bprm->interp = interp;
+	
 	/*
 	 * OK, now restart the process with the interpreter's dentry.
 	 */
--- linux/include/linux/binfmts.h-	Thu Mar 13 11:40:41 2003
+++ linux/include/linux/binfmts.h	Thu Mar 13 11:42:05 2003
@@ -30,7 +30,10 @@
 	int e_uid, e_gid;
 	kernel_cap_t cap_inheritable, cap_permitted, cap_effective;
 	int argc, envc;
-	char * filename;	/* Name of binary */
+	char * filename;	/* Name of binary as seen by procps */
+	char * interp;		/* Name of the binary really executed. Most
+				   of the time same as filename, but could be
+				   different for binfmt_{misc,script} */
 	unsigned long loader, exec;
 };

--- linux/fs/binfmt_script.c-	Mon Mar 17 08:10:56 2003
+++ linux/fs/binfmt_script.c	Mon Mar 17 08:13:07 2003
@@ -67,7 +67,7 @@
 	 * user environment and arguments are stored.
 	 */
 	remove_arg_zero(bprm);
-	retval = copy_strings_kernel(1, &bprm->filename, bprm);
+	retval = copy_strings_kernel(1, &bprm->interp, bprm);
 	if (retval < 0) return retval; 
 	bprm->argc++;
 	if (i_arg) {
 
--- linux/fs/binfmt_misc.c.orig	Wed Mar 19 15:45:34 2003
+++ linux/fs/binfmt_misc.c	Wed Mar 19 15:49:39 2003
@@ -58,7 +58,7 @@
  */
 static Node *check_file(struct linux_binprm *bprm)
 {
-	char *p = strrchr(bprm->filename, '.');
+	char *p = strrchr(bprm->interp, '.');
 	struct list_head *l;
 
 	for (l = entries.next; l != &entries; l = l->next) {
@@ -125,13 +125,13 @@
 	if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) {
 		remove_arg_zero(bprm);
 	}
-	retval = copy_strings_kernel(1, &bprm->filename, bprm);
+	retval = copy_strings_kernel(1, &bprm->interp, bprm);
 	if (retval < 0) goto _ret; 
 	bprm->argc++;
 	retval = copy_strings_kernel(1, &iname_addr, bprm);
 	if (retval < 0) goto _ret; 
 	bprm->argc++;
-	bprm->filename = iname;	/* for binfmt_script */
+	bprm->interp = iname;	/* for binfmt_script */
 
 	file = open_exec(iname);
 	retval = PTR_ERR(file);

                 reply	other threads:[~2003-07-28 21:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F259195.7070707@intel.com \
    --to=arun.sharma@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox