~ubuntu-branches/ubuntu/lucid/samba/lucid-security

« back to all changes in this revision

Viewing changes to debian/patches/CVE-2011-1678.patch

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2011-09-30 11:51:06 UTC
  • Revision ID: package-import@ubuntu.com-20110930115106-i2gtgkiwu0p1p3yu
Tags: 2:3.4.7~dfsg-1ubuntu3.8
* SECURITY UPDATE: denial of service via stale mtab lockfile
  - debian/patches/security-mask-signals.patch: mask signals while
    updating the mtab file in source3/client/mount.cifs.c.
  - CVE-2011-3585
* SECURITY UPDATE: mtab corruption via resource limits
  - debian/patches/CVE-2011-1678.patch: truncate mtab file if updating it
    failed in source3/client/{mount.cifs.c,mount.h,mtab.c}.
  - CVE-2011-1678
* SECURITY UPDATE: mtab corruption via incorrect new line check
  - debian/patches/CVE-2011-2724.patch: check proper return codes in
    source3/client/mount.cifs.c.
  - CVE-2011-2724

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: fix mtab corruption via resource limits
 
2
Origin: backport, http://git.samba.org/?p=cifs-utils.git;a=commitdiff;h=f6eae44a3d05b6515a59651e6bed8b6dde689aec
 
3
 
 
4
Index: samba-3.4.7~dfsg/source3/client/mount.cifs.c
 
5
===================================================================
 
6
--- samba-3.4.7~dfsg.orig/source3/client/mount.cifs.c   2011-09-29 09:27:30.269335212 -0400
 
7
+++ samba-3.4.7~dfsg/source3/client/mount.cifs.c        2011-09-29 09:31:01.057340608 -0400
 
8
@@ -1097,6 +1097,7 @@
 
9
        int gid = 0;
 
10
        int optlen = 0;
 
11
        int orgoptlen = 0;
 
12
+       int fd, tmprc;
 
13
        size_t options_size = 0;
 
14
        size_t current_len;
 
15
        int retry = 0; /* set when we have to retry mount with uppercase */
 
16
@@ -1578,6 +1580,23 @@
 
17
                rc = EX_FILEIO;
 
18
                goto mount_exit;
 
19
        }
 
20
+
 
21
+       fd = fileno(pmntfile);
 
22
+       if (fd < 0) {
 
23
+               fprintf(stderr, "mntent does not appear to be valid\n");
 
24
+               unlock_mtab();
 
25
+               rc = EX_FILEIO;
 
26
+               goto mount_exit;
 
27
+       }
 
28
+       rc = fstat(fd, &statbuf);
 
29
+       if (rc != 0) {
 
30
+               fprintf(stderr, "unable to fstat open mtab\n");
 
31
+               endmntent(pmntfile);
 
32
+               unlock_mtab();
 
33
+               rc = EX_FILEIO;
 
34
+               goto mount_exit;
 
35
+       }
 
36
+
 
37
        mountent.mnt_fsname = dev_name;
 
38
        mountent.mnt_dir = mountpoint;
 
39
        mountent.mnt_type = CONST_DISCARD(char *,"cifs");
 
40
@@ -1609,8 +1628,17 @@
 
41
        }
 
42
        mountent.mnt_freq = 0;
 
43
        mountent.mnt_passno = 0;
 
44
-       rc = addmntent(pmntfile,&mountent);
 
45
-       endmntent(pmntfile);
 
46
+       rc = addmntent(pmntfile, &mountent);
 
47
+       if (rc) {
 
48
+               fprintf(stderr, "unable to add mount entry to mtab\n");
 
49
+               ftruncate(fd, statbuf.st_size);
 
50
+               rc = EX_FILEIO;
 
51
+       }
 
52
+       tmprc = my_endmntent(pmntfile, statbuf.st_size);
 
53
+       if (tmprc) {
 
54
+               fprintf(stderr, "error %d detected on close of mtab\n", tmprc);
 
55
+               rc = EX_FILEIO;
 
56
+       }
 
57
        unlock_mtab();
 
58
        SAFE_FREE(mountent.mnt_opts);
 
59
        if (rc)
 
60
Index: samba-3.4.7~dfsg/source3/client/mount.h
 
61
===================================================================
 
62
--- samba-3.4.7~dfsg.orig/source3/client/mount.h        2011-09-29 09:27:32.797335278 -0400
 
63
+++ samba-3.4.7~dfsg/source3/client/mount.h     2011-09-29 09:31:09.457340826 -0400
 
64
@@ -34,5 +34,6 @@
 
65
 
 
66
 extern int lock_mtab(void);
 
67
 extern void unlock_mtab(void);
 
68
+extern int my_endmntent(FILE *stream, off_t size);
 
69
 
 
70
 #endif /* ! _MOUNT_H_ */
 
71
Index: samba-3.4.7~dfsg/source3/client/mtab.c
 
72
===================================================================
 
73
--- samba-3.4.7~dfsg.orig/source3/client/mtab.c 2011-09-29 09:27:36.725335379 -0400
 
74
+++ samba-3.4.7~dfsg/source3/client/mtab.c      2011-09-29 09:31:31.637341388 -0400
 
75
@@ -217,3 +217,30 @@
 
76
        return 0;
 
77
 }
 
78
 
 
79
+/*
 
80
+ * Call fflush and fsync on the mtab, and then endmntent. If either fflush
 
81
+ * or fsync fails, then truncate the file back to "size". endmntent is called
 
82
+ * unconditionally, and the errno (if any) from fflush and fsync are returned.
 
83
+ */
 
84
+int
 
85
+my_endmntent(FILE *stream, off_t size)
 
86
+{
 
87
+       int rc, fd;
 
88
+
 
89
+       fd = fileno(stream);
 
90
+       if (fd < 0)
 
91
+               return -EBADF;
 
92
+
 
93
+       rc = fflush(stream);
 
94
+       if (!rc)
 
95
+               rc = fsync(fd);
 
96
+
 
97
+       /* truncate file back to "size" -- best effort here */
 
98
+       if (rc) {
 
99
+               rc = errno;
 
100
+               ftruncate(fd, size);
 
101
+       }
 
102
+
 
103
+       endmntent(stream);
 
104
+       return rc;
 
105
+}