CVE-2019-3870 pysmbd: Ensure a zero umask is set for smbd.mkdir()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 21 Mar 2019 04:24:14 +0000 (17:24 +1300)
committerKarolin Seeger <kseeger@samba.org>
Mon, 8 Apr 2019 10:27:34 +0000 (10:27 +0000)
mkdir() is the other call that requires a umask of 0 in Samba.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/pymkdir-umask [deleted file]
source3/smbd/pysmbd.c

diff --git a/selftest/knownfail.d/pymkdir-umask b/selftest/knownfail.d/pymkdir-umask
deleted file mode 100644 (file)
index 5af01be..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba.tests.ntacls_backup.samba.tests.ntacls_backup.NtaclsBackupRestoreTests.test_smbd_mkdir
\ No newline at end of file
index 52d49408906b71e3befa4d9387f6a38026dc0326..29db8eb01c4dbfb29843c7639925ff4cb04569f3 100644 (file)
@@ -782,6 +782,8 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject *args, PyObject *kwargs)
        TALLOC_CTX *frame = talloc_stackframe();
        struct connection_struct *conn = NULL;
        struct smb_filename *smb_fname = NULL;
+       int ret;
+       mode_t saved_umask;
 
        if (!PyArg_ParseTupleAndKeywords(args,
                                         kwargs,
@@ -812,8 +814,15 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject *args, PyObject *kwargs)
                return NULL;
        }
 
+       /* we want total control over the permissions on created files,
+          so set our umask to 0 */
+       saved_umask = umask(0);
+
+       ret = SMB_VFS_MKDIR(conn, smb_fname, 00755);
 
-       if (SMB_VFS_MKDIR(conn, smb_fname, 00755) == -1) {
+       umask(saved_umask);
+
+       if (ret == -1) {
                DBG_ERR("mkdir error=%d (%s)\n", errno, strerror(errno));
                TALLOC_FREE(frame);
                return NULL;