From nobody Mon May 15 06:59:12 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QKVbP09MKz4BG6j; Mon, 15 May 2023 06:59:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QKVbN5cGvz3NsZ; Mon, 15 May 2023 06:59:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684133952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KFx0NxyZWGuEmt1rlHADi93w9ODwUpmVrqr2H5aeL3g=; b=VrfUxK+Touvx8nGEv07ZaSVLW85d/wPKVHIZPHRBOGhAvXx/iJ/jLjIg9bj2Gs2o1DCGXG tusg3cjhrj880+z+mHk6zL1Fq2segEe7avPpd0vImZY7vemXM6xwH4gyDZ57Kay/60FZ6B 029CrC7dlut1kALEARkDtBkvAOcAw2sIGhrH6LBTjvvc6es/NF8FJoKAREuVnVSYG/JEDR 49/VKZ3jC1mnRVFz0IvJVfxu7nWIkdmRb8YUGmrFPNDo3R2FAMSbjCetgIQqc+xCHKj+aG HU9G4WTDl2CH+ZsMzueHn2Ds0f+WP1AlcbJjSNkf3YFHQ0t7Ek1Zru0n5LUGrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684133952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KFx0NxyZWGuEmt1rlHADi93w9ODwUpmVrqr2H5aeL3g=; b=gFPqm7RMmNiwXh6OuwME/giKZDB9i2xS6XCZLpa/zEnR5vP+AnuQi/REZCDDtCqwP7+HFT IYGEzfNNg15OSDHUsiVbX50uO17DWwFSQJo0wQAEwsisgGQXlCqReldEQVRRMEH9k5zmei TjkZLJLOI95moJL+SisMPjEWY2PYgFb2AP2pbMsIKAvpzT/cdnCLGhYxVd4x7OMEx01WF5 5W6952JxNC9PwkueZqjb1UCzWmJs1xsqySypFXM/L7In3yAO26kYglhgBUM9o+PzjfOh1q Yth6ZzkxMEXU/oZJn3+JNetid58bMZ+0ZWZxyVkOb0WxTaj3JBfUdxZBiDDARA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684133952; a=rsa-sha256; cv=none; b=uvYQ9jW7uWeWlGg3MpwiT7YeJz1h7On0De5Jy8wo6fMFffE5jEORuQ2ck9c3v67IEj6Idg OkQlOylYG+5ooB+vmSprQWiOd1gyVbrRlAIJHPO0KZn8DE30PzHkZJEHfzEsbCiGw8NbCO 3bXaPDwRfGilV3sqMMAKRbYk6LzvO0XZHPaTbQx5ccirnjVhyRp0bAYy7+OwAxTEKBlbI4 iyH5dVfIl108ibfm077jwLBNLKJA9BRTv5lWw1WjIcs5QY2+urM4cU0bKGompXVFCV/q0Q MOsdGZHZn0fNeSjylRwq6Pr0y+FRXrVUZam+j5y7AxXbQmH7WXa7qRM+n0I1Dg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QKVbN4hznzWNr; Mon, 15 May 2023 06:59:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34F6xCf4001954; Mon, 15 May 2023 06:59:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34F6xCIs001953; Mon, 15 May 2023 06:59:12 GMT (envelope-from git) Date: Mon, 15 May 2023 06:59:12 GMT Message-Id: <202305150659.34F6xCIs001953@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: ef7d0eb9489f - main - pw: do not call system() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ef7d0eb9489f39169a1ae83c576fe74e40d126ad Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ef7d0eb9489f39169a1ae83c576fe74e40d126ad commit ef7d0eb9489f39169a1ae83c576fe74e40d126ad Author: Baptiste Daroussin AuthorDate: 2023-05-15 06:55:08 +0000 Commit: Baptiste Daroussin CommitDate: 2023-05-15 06:59:08 +0000 pw: do not call system() Calling system makes pw(8) spawn a shell, which can then be abused. MFC After: 3 days --- usr.sbin/pw/pw_user.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 52b37eae4ff1..c0002f985bfb 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -50,6 +50,7 @@ static const char rcsid[] = #include #include #include +#include #include "pw.h" #include "bitmap.h" @@ -57,6 +58,7 @@ static const char rcsid[] = #define LOGNAMESIZE (MAXLOGNAME-1) +extern char **environ; static char locked_str[] = "*LOCKED*"; static struct passwd fakeuser = { @@ -694,11 +696,16 @@ rmat(uid_t uid) stat(e->d_name, &st) == 0 && !S_ISDIR(st.st_mode) && st.st_uid == uid) { - char tmp[MAXPATHLEN]; - - snprintf(tmp, sizeof(tmp), "/usr/bin/atrm %s", - e->d_name); - system(tmp); + const char *argv[] = { + "/usr/sbin/atrm", + e->d_name, + NULL + }; + if (posix_spawn(NULL, argv[0], NULL, NULL, + (char *const *) argv, environ)) { + warn("Failed to execute '%s %s'", + argv[0], argv[1]); + } } } closedir(d); @@ -915,9 +922,18 @@ pw_user_del(int argc, char **argv, char *arg1) /* Remove crontabs */ snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name); if (access(file, F_OK) == 0) { - snprintf(file, sizeof(file), "crontab -u %s -r", - pwd->pw_name); - system(file); + const char *argv[] = { + "crontab", + "-u", + pwd->pw_name, + "-r", + NULL + }; + if (posix_spawnp(NULL, argv[0], NULL, NULL, + (char *const *) argv, environ)) { + warn("Failed to execute '%s %s'", + argv[0], argv[1]); + } } }