]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
mount.cifs: check access of credential files before opening
authorJeff Layton <jlayton@redhat.com>
Fri, 25 Sep 2009 11:00:18 +0000 (07:00 -0400)
committerKarolin Seeger <kseeger@samba.org>
Thu, 1 Oct 2009 12:26:57 +0000 (14:26 +0200)
It's possible for an unprivileged user to pass a setuid mount.cifs a
credential or password file to which he does not have access. This can cause
mount.cifs to open the file on his behalf and possibly leak the info in the
first few lines of the file.

Check the access permissions of the file before opening it.

Reported-by: Ronald Volgers <r.c.volgers@student.utwente.nl>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Steve French <sfrench@us.ibm.com>
Part 1/2 of a fix for CVE-2009-2948.
(cherry picked from commit 8f0af2ed4f330be558987dd52c32b32e4b8ed95f)

source/client/mount.cifs.c

index 8b62ef73fe8407b9a1782b768498284a9d308f40..11019b7cde79519d716c1df452060b3799c8385d 100644 (file)
@@ -199,6 +199,11 @@ static int open_cred_file(char * file_name)
        char * temp_val;
        FILE * fs;
        int i, length;
+
+       i = access(file_name, R_OK);
+       if (i)
+               return i;
+
        fs = fopen(file_name,"r");
        if(fs == NULL)
                return errno;
@@ -321,6 +326,12 @@ static int get_password_from_file(int file_descript, char * filename)
        }
 
        if(filename != NULL) {
+               rc = access(filename, R_OK);
+               if (rc) {
+                       fprintf(stderr, "mount.cifs failed: access check of %s failed: %s\n",
+                                       filename, strerror(errno));
+                       exit(EX_SYSERR);
+               }
                file_descript = open(filename, O_RDONLY);
                if(file_descript < 0) {
                        printf("mount.cifs failed. %s attempting to open password file %s\n",