[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] standalone shell / prefer_applets: fix comm field problem
From:       Lukasz Serafin <Lukasz.Serafin () axis ! com>
Date:       2020-04-24 15:20:02
Message-ID: 0589fc2e0dc64b65b1c4548ed0c62f95 () XBOX04 ! axis ! com
[Download RAW message or body]

The output of /proc/self/comm shall only be changed to the applet name
if it is "exe". It shall not be changed if it is for example the name
of a shell script.

Signed-off-by: Lukasz Serafin <lukasz.serafin@axis.com>
---
 include/libbb.h            |  2 ++
 libbb/appletlib.c          | 11 +++++++++--
 libbb/vfork_daemon_rexec.c |  5 +++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 392c0443d..2e8d7f3d0 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1177,8 +1177,10 @@ void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_
 #endif
 #if defined(__linux__)
 void set_task_comm(const char *comm) FAST_FUNC;
+void get_task_comm(char *buffer) FAST_FUNC;
 #else
 # define set_task_comm(name) ((void)0)
+# define get_task_comm(name) ((void)0)
 #endif

 /* Helpers for daemonization.
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index f842e73cc..ad3affba4 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -33,6 +33,8 @@
 # include <malloc.h> /* for mallopt */
 #endif

+#define COMM_MAX_SIZE 16
+
 /* Declare <applet>_main() */
 #define PROTOTYPES
 #include "applets.h"
@@ -1115,8 +1117,13 @@ int main(int argc UNUSED_PARAM, char **argv)
      || ENABLE_FEATURE_PREFER_APPLETS
      || !BB_MMU
     ) {
-        if (NUM_APPLETS > 1)
-            set_task_comm(applet_name);
+        if (NUM_APPLETS > 1) {
+            char buffer[COMM_MAX_SIZE];
+            buffer[0] = '\0';
+            get_task_comm(buffer);
+            if (strcmp(buffer, "exe") == 0)
+                set_task_comm(applet_name);
+        }
     }

     parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 65271e84f..c12173cd0 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -33,6 +33,11 @@ void FAST_FUNC set_task_comm(const char *comm)
     /* okay if too long (truncates) */
     prctl(PR_SET_NAME, (long)comm, 0, 0, 0);
 }
+void FAST_FUNC get_task_comm(char* buffer)
+{
+    /* returned name can be up to 16 bytes long (including null byte) */
+    prctl(PR_GET_NAME, (long)buffer, 0, 0, 0);
+}
 #endif

 /*
--
2.11.0


[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} \
--></style> </head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
 <p>The output of /proc/self/comm shall only be changed to the applet name<br>
if it is &quot;exe&quot;. It shall not be changed if it is for example the name<br>
of a shell script.<br>
<br>
Signed-off-by: Lukasz Serafin &lt;lukasz.serafin@axis.com&gt;<br>
---<br>
&nbsp;include/libbb.h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
|&nbsp; 2 &#43;&#43;<br> \
&nbsp;libbb/appletlib.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11 \
&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;--<br> &nbsp;libbb/vfork_daemon_rexec.c \
|&nbsp; 5 &#43;&#43;&#43;&#43;&#43;<br> &nbsp;3 files changed, 16 insertions(&#43;), \
2 deletions(-)<br> <br>
diff --git a/include/libbb.h b/include/libbb.h<br>
index 392c0443d..2e8d7f3d0 100644<br>
--- a/include/libbb.h<br>
&#43;&#43;&#43; b/include/libbb.h<br>
@@ -1177,8 &#43;1177,10 @@ void run_applet_no_and_exit(int a, const char *name, char \
**argv) NORETURN FAST_<br> &nbsp;#endif<br>
&nbsp;#if defined(__linux__)<br>
&nbsp;void set_task_comm(const char *comm) FAST_FUNC;<br>
&#43;void get_task_comm(char *buffer) FAST_FUNC;<br>
&nbsp;#else<br>
&nbsp;# define set_task_comm(name) ((void)0)<br>
&#43;# define get_task_comm(name) ((void)0)<br>
&nbsp;#endif<br>
&nbsp;<br>
&nbsp;/* Helpers for daemonization.<br>
diff --git a/libbb/appletlib.c b/libbb/appletlib.c<br>
index f842e73cc..ad3affba4 100644<br>
--- a/libbb/appletlib.c<br>
&#43;&#43;&#43; b/libbb/appletlib.c<br>
@@ -33,6 &#43;33,8 @@<br>
&nbsp;# include &lt;malloc.h&gt; /* for mallopt */<br>
&nbsp;#endif<br>
&nbsp;<br>
&#43;#define COMM_MAX_SIZE 16<br>
&#43;<br>
&nbsp;/* Declare &lt;applet&gt;_main() */<br>
&nbsp;#define PROTOTYPES<br>
&nbsp;#include &quot;applets.h&quot;<br>
@@ -1115,8 &#43;1117,13 @@ int main(int argc UNUSED_PARAM, char **argv)<br>
&nbsp;&nbsp;&nbsp; &nbsp; || ENABLE_FEATURE_PREFER_APPLETS<br>
&nbsp;&nbsp;&nbsp; &nbsp; || !BB_MMU<br>
&nbsp;&nbsp;&nbsp; &nbsp;) {<br>
-&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (NUM_APPLETS &gt; 1)<br>
-&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;set_task_comm(applet_name);<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if \
(NUM_APPLETS &gt; 1) {<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;char buffer[COMM_MAX_SIZE];<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;buffer[0] = '\0';<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;get_task_comm(buffer);<br> &#43;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (strcmp(buffer, &quot;exe&quot;) == \
0)<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;set_task_comm(applet_name);<br> &#43;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;}<br> &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG \
                */<br>
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c<br>
index 65271e84f..c12173cd0 100644<br>
--- a/libbb/vfork_daemon_rexec.c<br>
&#43;&#43;&#43; b/libbb/vfork_daemon_rexec.c<br>
@@ -33,6 &#43;33,11 @@ void FAST_FUNC set_task_comm(const char *comm)<br>
&nbsp;&nbsp;&nbsp; &nbsp;/* okay if too long (truncates) */<br>
&nbsp;&nbsp;&nbsp; &nbsp;prctl(PR_SET_NAME, (long)comm, 0, 0, 0);<br>
&nbsp;}<br>
&#43;void FAST_FUNC get_task_comm(char* buffer)<br>
&#43;{<br>
&#43;&nbsp;&nbsp; &nbsp;/* returned name can be up to 16 bytes long (including null \
byte) */<br> &#43;&nbsp;&nbsp; &nbsp;prctl(PR_GET_NAME, (long)buffer, 0, 0, 0);<br>
&#43;}<br>
&nbsp;#endif<br>
&nbsp;<br>
&nbsp;/*<br>
-- <br>
2.11.0<br>
<br>
</p>
</body>
</html>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

--===============0503806619260815236==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic