[PATCH ubox] logd: fix priviledge dropping order

Giovanni Giacobbi giovanni at giacobbi.net
Tue Jul 27 05:39:28 PDT 2021


Fixes: 41664054b8b1 ("logd: fix ignored return values in set{gid,uid}")
Signed-off-by: Giovanni Giacobbi <giovanni at giacobbi.net>
---
 log/logd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/log/logd.c b/log/logd.c
index 5d6c458..594b1e0 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -243,37 +243,37 @@ main(int argc, char **argv)
 	struct passwd *p = NULL;
 
 	signal(SIGPIPE, SIG_IGN);
 	while ((ch = getopt(argc, argv, "S:")) != -1) {
 		switch (ch) {
 		case 'S':
 			log_size = atoi(optarg);
 			if (log_size < 1)
 				log_size = 16;
 			break;
 		}
 	}
 	log_size *= 1024;
 
 	uloop_init();
 	log_init(log_size);
 	conn.cb = ubus_connect_handler;
 	ubus_auto_connect(&conn);
 	p = getpwnam("logd");
 	if (p) {
-		if (setuid(p->pw_uid) < 0) {
-			fprintf(stderr, "setuid() failed: %s\n", strerror(errno));
+		if (setgid(p->pw_gid) < 0) {
+			fprintf(stderr, "setgid() failed: %s\n", strerror(errno));
 			exit(1);
 		}
 
-		if (setgid(p->pw_gid) < 0) {
-			fprintf(stderr, "setgid() failed: %s\n", strerror(errno));
+		if (setuid(p->pw_uid) < 0) {
+			fprintf(stderr, "setuid() failed: %s\n", strerror(errno));
 			exit(1);
 		}
 	}
 	uloop_run();
 	log_shutdown();
 	uloop_done();
 	ubus_auto_shutdown(&conn);
 
 	return 0;
 }
-- 
2.17.2




More information about the openwrt-devel mailing list