public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
From: samba-bugs@samba.org
To: cifs-qa@samba.org
Subject: [Bug 14442] Shell command injection vulnerability in mount.cifs
Date: Thu, 16 Jul 2020 22:40:06 +0000	[thread overview]
Message-ID: <bug-14442-10630-ueNWUIRejS@https.bugzilla.samba.org/> (raw)
In-Reply-To: <bug-14442-10630@https.bugzilla.samba.org/>

https://bugzilla.samba.org/show_bug.cgi?id=14442

--- Comment #1 from Paulo Alcantara <palcantara@suse.de> ---
Hi Vadim,

Thanks for the report!

I was able to reproduce it and ended up with the following changes:

diff --git a/mount.cifs.c b/mount.cifs.c
index 40918c18649f..bb8a7e958898 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -1695,6 +1695,43 @@ drop_child_privs(void)
        return 0;
 }

+#ifdef ENABLE_SYSTEMD
+static int get_passwd_by_systemd(const char *prompt, char *input, int
capacity)
+{
+       int fd[2];
+       pid_t pid;
+       int rc;
+
+       if (pipe(fd) == -1) {
+               fprintf(stderr, "Failed to create pipe: %s\n",
strerror(errno));
+               return -1;
+       }
+
+       pid = fork();
+       if (pid == -1) {
+               fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
+               return -1;
+       }
+
+       if (pid == 0) {
+               close(fd[0]);
+               dup2(fd[1], STDOUT_FILENO);
+               execlp("systemd-ask-password", "systemd-ask-password", prompt,
NULL);
+       }
+
+       close(fd[1]);
+       wait(&rc);
+       if (!WIFEXITED(rc))
+               return 1;
+       if (read(fd[0], input, capacity) == -1) {
+               fprintf(stderr, "Failed to read from pipe: %s\n",
strerror(errno));
+               return 1;
+       }
+
+       return 0;
+}
+#endif
+
 /*
  * If systemd is running and systemd-ask-password --
  * is available, then use that else fallback on getpass(..)
@@ -1714,27 +1751,11 @@ get_password(const char *prompt, char *input, int
capacity)
                && (lstat("/sys/fs/cgroup/systemd", &b) == 0)
                && (a.st_dev != b.st_dev);

-       if (is_systemd_running) {
-               char *cmd, *ret;
-               FILE *ask_pass_fp = NULL;
-
-               cmd = ret = NULL;
-               if (asprintf(&cmd, "systemd-ask-password \"%s\"", prompt) >= 0)
{
-                       ask_pass_fp = popen (cmd, "re");
-                       free (cmd);
-               }
-
-               if (ask_pass_fp) {
-                       ret = fgets(input, capacity, ask_pass_fp);
-                       pclose(ask_pass_fp);
-               }
-
-               if (ret) {
-                       int len = strlen(input);
-                       if (input[len - 1] == '\n')
-                               input[len - 1] = '\0';
-                       return input;
-               }
+       if (is_systemd_running && !get_passwd_by_systemd(prompt, input,
capacity)) {
+               int len = strlen(input);
+               if (input[len - 1] == '\n')
+                       input[len - 1] = '\0';
+               return input;
        }
 #endif


---
Before the patch:

$ sudo ./mount.cifs -o username="test \$(id)" //1 /mnt
Password for test uid=0(root) gid=0(root) groups=0(root)@//1:  (press TAB for
no echo)

After the patch:

$ sudo ./mount.cifs -o username="test \$(id)" //1 /mnt
Password for test $(id)@//1:  (press TAB for no echo)

Let me know what you think.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

  reply	other threads:[~2020-07-16 23:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 17:50 [Bug 14442] New: Shell command injection vulnerability in mount.cifs samba-bugs
2020-07-16 22:40 ` samba-bugs [this message]
2020-07-17  3:50 ` [Bug 14442] " samba-bugs
2020-07-17 14:51 ` samba-bugs
2020-07-17 15:02 ` samba-bugs
2020-07-17 17:21 ` samba-bugs
2020-07-18 14:14 ` samba-bugs
2020-07-20 17:35 ` samba-bugs
2020-07-23  5:35 ` samba-bugs
2020-07-23  8:18 ` samba-bugs
2020-07-23  9:41 ` samba-bugs
2020-07-24 14:52 ` [Bug 14442] CVE-2020-14342: " samba-bugs
2020-07-27 11:33 ` samba-bugs
2020-07-27 11:33 ` samba-bugs
2020-07-27 11:41 ` samba-bugs
2020-07-27 11:47 ` samba-bugs
2020-07-27 21:54 ` samba-bugs
2020-07-28 15:56 ` samba-bugs
2020-07-28 15:56 ` samba-bugs

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=bug-14442-10630-ueNWUIRejS@https.bugzilla.samba.org/ \
    --to=samba-bugs@samba.org \
    --cc=cifs-qa@samba.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