~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to debian/patches/features/all/fs-hardlink-creation-restriction-cleanup.patch

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings, Bastian Blank, Ben Hutchings, Uwe Kleine-König
  • Date: 2012-03-04 15:32:20 UTC
  • mfrom: (1.3.14)
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20120304153220-zbhqnmufx18yk6q4
* New upstream stable update:
  http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.2.8
  - [i386] i387: move TS_USEDFPU flag from thread_info to task_struct
  - [x86] additional refactoring of FPU/SSE state save and restore
  http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.2.9
  - vfs: fix d_inode_lookup() dentry ref leak
  - target: Allow control CDBs with data > 1 page
  - epoll: introduce POLLFREE to flush ->signalfd_wqh before kfree()
  - epoll: ep_unregister_pollwait() can use the freed pwq->whead
  - epoll: limit paths (CVE-2011-1083)
  - cdrom: use copy_to_user() without the underscores

[ Bastian Blank ]
* [mips,mipsel] Also remove ext4 modules from installer.

[ Ben Hutchings ]
* Update debconf template translations:
  - Update Dutch (Willem Kuyn) (Closes: #658736)
  - Add Polish (Michał Kułach) (Closes: #658912)
* Bump ABI to 2
* fs: Introduce and enable security restrictions on links:
  - Do not follow symlinks in /tmp that are owned by other users
    (sysctl: fs.protected_symlinks)
  - Do not allow unprivileged users to create hard links to sensitive files
    (sysctl: fs.protected_hardlinks) (Closes: #609455)
    + This breaks the 'at' package in stable, which will be fixed shortly
      (see #597130)
  The precise restrictions are specified in Documentation/sysctl/fs.txt in
  the linux-doc-3.2 and linux-source-3.2 packages.
* iwlwifi: fix key removal (Closes: #651199)
* cgroups: Set CGROUP_PERF
* hid: Enable HID_HOLTEK, HID_PRIMAX, HID_SPEEDLINK, HID_WIIMOTE as modules,
  HID_ACRUX_FF
* media/rc: Enable RC_ATI_REMOTE as module
* gspca: Enable USB_GSPCA_TOPRO as module
* dvb-usb: Enable DVB_USB_PCTV452E, DVB_USB_MXL111SF as modules

[ Uwe Kleine-König ]
* [x86] Update rt featureset to 3.2.9-rt15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From 52db90d0fa770e2277645eb34956820cec26b2cb Mon Sep 17 00:00:00 2001
 
2
From: Kees Cook <keescook@chromium.org>
 
3
Date: Sat, 25 Feb 2012 12:28:44 +1100
 
4
Subject: [PATCH 5/5] fs: hardlink creation restriction cleanup
 
5
 
 
6
Clean-up of hardlink restriction logic, as suggested by Andrew Morton.
 
7
 
 
8
Signed-off-by: Kees Cook <keescook@chromium.org>
 
9
Cc: Ingo Molnar <mingo@elte.hu>
 
10
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
 
11
---
 
12
 fs/namei.c |   62 ++++++++++++++++++++++++++++++++++++++++++-----------------
 
13
 1 files changed, 44 insertions(+), 18 deletions(-)
 
14
 
 
15
diff --git a/fs/namei.c b/fs/namei.c
 
16
index fe13533..1436fae 100644
 
17
--- a/fs/namei.c
 
18
+++ b/fs/namei.c
 
19
@@ -693,46 +693,72 @@ static inline int may_follow_link(struct path *link)
 
20
 }
 
21
 
 
22
 /**
 
23
+ * safe_hardlink_source - Check for safe hardlink conditions
 
24
+ * @inode: the source inode to hardlink from
 
25
+ *
 
26
+ * Return false if at least one of the following conditions:
 
27
+ *    - inode is not a regular file
 
28
+ *    - inode is setuid
 
29
+ *    - inode is setgid and group-exec
 
30
+ *    - access failure for read and write
 
31
+ *
 
32
+ * Otherwise returns true.
 
33
+ */
 
34
+static bool safe_hardlink_source(struct inode *inode)
 
35
+{
 
36
+       mode_t mode = inode->i_mode;
 
37
+
 
38
+       /* Special files should not get pinned to the filesystem. */
 
39
+       if (!S_ISREG(mode))
 
40
+               return false;
 
41
+
 
42
+       /* Setuid files should not get pinned to the filesystem. */
 
43
+       if (mode & S_ISUID)
 
44
+               return false;
 
45
+
 
46
+       /* Executable setgid files should not get pinned to the filesystem. */
 
47
+       if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
 
48
+               return false;
 
49
+
 
50
+       /* Hardlinking to unreadable or unwritable sources is dangerous. */
 
51
+       if (inode_permission(inode, MAY_READ | MAY_WRITE))
 
52
+               return false;
 
53
+
 
54
+       return true;
 
55
+}
 
56
+
 
57
+/**
 
58
  * may_linkat - Check permissions for creating a hardlink
 
59
  * @link: the source to hardlink from
 
60
  *
 
61
  * Block hardlink when all of:
 
62
  *  - sysctl_protected_hardlinks enabled
 
63
  *  - fsuid does not match inode
 
64
- *  - at least one of:
 
65
- *    - inode is not a regular file
 
66
- *    - inode is setuid
 
67
- *    - inode is setgid and group-exec
 
68
- *    - access failure for read and write
 
69
+ *  - hardlink source is unsafe (see safe_hardlink_source() above)
 
70
  *  - not CAP_FOWNER
 
71
  *
 
72
  * Returns 0 if successful, -ve on error.
 
73
  */
 
74
 static int may_linkat(struct path *link)
 
75
 {
 
76
-       int error = 0;
 
77
        const struct cred *cred;
 
78
        struct inode *inode;
 
79
-       int mode;
 
80
 
 
81
        if (!sysctl_protected_hardlinks)
 
82
                return 0;
 
83
 
 
84
        cred = current_cred();
 
85
        inode = link->dentry->d_inode;
 
86
-       mode = inode->i_mode;
 
87
-
 
88
-       if (cred->fsuid != inode->i_uid &&
 
89
-           (!S_ISREG(mode) || (mode & S_ISUID) ||
 
90
-            ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
 
91
-            (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
 
92
-           !capable(CAP_FOWNER))
 
93
-               error = -EPERM;
 
94
 
 
95
-       if (error)
 
96
-               audit_log_link_denied("linkat", link);
 
97
+       /* Source inode owner (or CAP_FOWNER) can hardlink all they like,
 
98
+        * otherwise, it must be a safe source.
 
99
+        */
 
100
+       if (cred->fsuid == inode->i_uid || safe_hardlink_source(inode) ||
 
101
+           capable(CAP_FOWNER))
 
102
+               return 0;
 
103
 
 
104
-       return error;
 
105
+       audit_log_link_denied("linkat", link);
 
106
+       return -EPERM;
 
107
 }
 
108
 #else
 
109
 static inline int may_follow_link(struct path *link)
 
110
-- 
 
111
1.7.9.1
 
112