[git commit master 1/1] FAQ: add example kernel patch for "magic /proc/self/exe"

Denys Vlasenko vda.linux at googlemail.com
Sat Oct 30 02:38:44 UTC 2010


commit: http://git.busybox.net/busybox-website/commit/?id=34077574a34a99cebf9336820330065e9b8d4ff3
branch: http://git.busybox.net/busybox-website/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 FAQ.html |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/FAQ.html b/FAQ.html
index 70e0c0c..b7a5139 100644
--- a/FAQ.html
+++ b/FAQ.html
@@ -144,14 +144,48 @@ have additions to this FAQ document, we would love to add them,
     your rootfs, you must mount /proc beforehand.)
 </p>
 <p>
-    A typical indication that you set CONFIG_BUSYBOX_EXEC_PATH to proc but
-    forgot to mount proc is:
+    A typical indication that you set CONFIG_BUSYBOX_EXEC_PATH to
+    /proc/self/exe but /proc is not mounted:
+</p>
 <pre>
 $ /bin/echo $PATH
 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
 $ echo $PATH
 /bin/sh: echo: not found
 </pre>
+<p>
+    If this is a serious limitation for you, you may patch the kernel
+    so that it always understands exec("/proc/self/exe"), even if /proc
+    is not mounted. For example, in linux-2.6.30, you need to patch
+    open_exec() function in fs/exec.c file:
+</p>
+<pre>
+        file = do_filp_open(AT_FDCWD, name,
+                                O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
+                                MAY_EXEC | MAY_OPEN);
+-       if (IS_ERR(file))
+-               goto out;
++       if (IS_ERR(file)) {
++               if ((PTR_ERR(file) == -ENOENT || PTR_ERR(file) == -EACCES)
++                && strcmp(name, "/proc/self/exe") == 0
++               ) {
++                       struct file *sv = file;
++                       struct mm_struct *mm;
+
++                       mm = get_task_mm(current);
++                       if (!mm)
++                               goto out;
++                       file = get_mm_exe_file(mm);
++                       mmput(mm);
++                       if (file)
++                               goto ok;
++                       file = sv;
++               }
++               goto out;
++       }
++ok:
+        err = -EACCES;
+</pre>
 
 <hr />
 <h2><a name="configure">How do I configure busybox?</a></h2>
-- 
1.7.1



More information about the busybox-cvs mailing list