~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to kernel-patches/for-mainline/vfs-notify_change.diff

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Add a vfsmount parameter to notify_change()
2
 
 
3
 
The vfsmount parameter must be set appropriately for files visibile
4
 
outside the kernel. Files that are only used in a filesystem (e.g.,
5
 
reiserfs xattr files) will have a NULL vfsmount.
6
 
 
7
 
The kernel nfsd also doesn't have the necessary context for client
8
 
requests. We cannot put it under any pathname based policy, and
9
 
also set vfsmount to NULL there.
10
 
 
11
 
The next patch passes the vfsmount to the inode_setattr LSM hook.
12
 
 
13
 
Signed-off-by: Tony Jones <tonyj@suse.de>
14
 
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
15
 
 
16
 
Index: b/fs/attr.c
17
 
===================================================================
18
 
--- a/fs/attr.c
19
 
+++ b/fs/attr.c
20
 
@@ -101,7 +101,8 @@ int inode_setattr(struct inode * inode, 
21
 
 }
22
 
 EXPORT_SYMBOL(inode_setattr);
23
 
 
24
 
-int notify_change(struct dentry * dentry, struct iattr * attr)
25
 
+int notify_change(struct dentry *dentry, struct vfsmount *mnt,
26
 
+                 struct iattr *attr)
27
 
 {
28
 
        struct inode *inode = dentry->d_inode;
29
 
        mode_t mode;
30
 
Index: b/include/linux/fs.h
31
 
===================================================================
32
 
--- a/include/linux/fs.h
33
 
+++ b/include/linux/fs.h
34
 
@@ -1458,8 +1458,8 @@ static inline int break_lease(struct ino
35
 
 
36
 
 /* fs/open.c */
37
 
 
38
 
-extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
39
 
-                      struct file *filp);
40
 
+extern int do_truncate(struct dentry *, struct vfsmount *, loff_t start,
41
 
+                      unsigned int time_attrs, struct file *filp);
42
 
 extern long do_sys_open(int fdf, const char __user *filename, int flags,
43
 
                        int mode);
44
 
 extern struct file *filp_open(const char *, int, int);
45
 
@@ -1612,7 +1612,7 @@ extern int do_remount_sb(struct super_bl
46
 
 #ifdef CONFIG_BLOCK
47
 
 extern sector_t bmap(struct inode *, sector_t);
48
 
 #endif
49
 
-extern int notify_change(struct dentry *, struct iattr *);
50
 
+extern int notify_change(struct dentry *, struct vfsmount *, struct iattr *);
51
 
 extern int permission(struct inode *, int, struct nameidata *);
52
 
 extern int generic_permission(struct inode *, int,
53
 
                int (*check_acl)(struct inode *, int));
54
 
Index: b/fs/ecryptfs/inode.c
55
 
===================================================================
56
 
--- a/fs/ecryptfs/inode.c
57
 
+++ b/fs/ecryptfs/inode.c
58
 
@@ -873,12 +873,14 @@ static int ecryptfs_setattr(struct dentr
59
 
 {
60
 
        int rc = 0;
61
 
        struct dentry *lower_dentry;
62
 
+       struct vfsmount *lower_mnt;
63
 
        struct inode *inode;
64
 
        struct inode *lower_inode;
65
 
        struct ecryptfs_crypt_stat *crypt_stat;
66
 
 
67
 
        crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
68
 
        lower_dentry = ecryptfs_dentry_to_lower(dentry);
69
 
+       lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
70
 
        inode = dentry->d_inode;
71
 
        lower_inode = ecryptfs_inode_to_lower(inode);
72
 
        if (ia->ia_valid & ATTR_SIZE) {
73
 
@@ -893,7 +895,7 @@ static int ecryptfs_setattr(struct dentr
74
 
                if (rc < 0)
75
 
                        goto out;
76
 
        }
77
 
-       rc = notify_change(lower_dentry, ia);
78
 
+       rc = notify_change(lower_dentry, lower_mnt, ia);
79
 
 out:
80
 
        fsstack_copy_attr_all(inode, lower_inode, NULL);
81
 
        return rc;
82
 
Index: b/fs/fat/file.c
83
 
===================================================================
84
 
--- a/fs/fat/file.c
85
 
+++ b/fs/fat/file.c
86
 
@@ -92,7 +92,7 @@ int fat_generic_ioctl(struct inode *inod
87
 
                }
88
 
 
89
 
                /* This MUST be done before doing anything irreversible... */
90
 
-               err = notify_change(filp->f_path.dentry, &ia);
91
 
+               err = notify_change(filp->f_path.dentry, filp->f_path.mnt, &ia);
92
 
                if (err)
93
 
                        goto up;
94
 
 
95
 
Index: b/fs/hpfs/namei.c
96
 
===================================================================
97
 
--- a/fs/hpfs/namei.c
98
 
+++ b/fs/hpfs/namei.c
99
 
@@ -426,7 +426,7 @@ again:
100
 
                        /*printk("HPFS: truncating file before delete.\n");*/
101
 
                        newattrs.ia_size = 0;
102
 
                        newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
103
 
-                       err = notify_change(dentry, &newattrs);
104
 
+                       err = notify_change(dentry, NULL, &newattrs);
105
 
                        put_write_access(inode);
106
 
                        if (!err)
107
 
                                goto again;
108
 
Index: b/fs/nfsd/vfs.c
109
 
===================================================================
110
 
--- a/fs/nfsd/vfs.c
111
 
+++ b/fs/nfsd/vfs.c
112
 
@@ -358,7 +358,7 @@ nfsd_setattr(struct svc_rqst *rqstp, str
113
 
        err = nfserr_notsync;
114
 
        if (!check_guard || guardtime == inode->i_ctime.tv_sec) {
115
 
                fh_lock(fhp);
116
 
-               host_err = notify_change(dentry, iap);
117
 
+               host_err = notify_change(dentry, fhp->fh_export->ex_mnt, iap);
118
 
                err = nfserrno(host_err);
119
 
                fh_unlock(fhp);
120
 
        }
121
 
@@ -890,13 +890,13 @@ out:
122
 
        return err;
123
 
 }
124
 
 
125
 
-static void kill_suid(struct dentry *dentry)
126
 
+static void kill_suid(struct dentry *dentry, struct vfsmount *mnt)
127
 
 {
128
 
        struct iattr    ia;
129
 
        ia.ia_valid = ATTR_KILL_SUID | ATTR_KILL_SGID;
130
 
 
131
 
        mutex_lock(&dentry->d_inode->i_mutex);
132
 
-       notify_change(dentry, &ia);
133
 
+       notify_change(dentry, mnt, &ia);
134
 
        mutex_unlock(&dentry->d_inode->i_mutex);
135
 
 }
136
 
 
137
 
@@ -955,7 +955,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
138
 
 
139
 
        /* clear setuid/setgid flag after write */
140
 
        if (host_err >= 0 && (inode->i_mode & (S_ISUID | S_ISGID)))
141
 
-               kill_suid(dentry);
142
 
+               kill_suid(dentry, exp->ex_mnt);
143
 
 
144
 
        if (host_err >= 0 && stable) {
145
 
                static ino_t    last_ino;
146
 
Index: b/fs/open.c
147
 
===================================================================
148
 
--- a/fs/open.c
149
 
+++ b/fs/open.c
150
 
@@ -194,8 +194,8 @@ out:
151
 
        return error;
152
 
 }
153
 
 
154
 
-int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
155
 
-       struct file *filp)
156
 
+int do_truncate(struct dentry *dentry, struct vfsmount *mnt, loff_t length,
157
 
+               unsigned int time_attrs, struct file *filp)
158
 
 {
159
 
        int err;
160
 
        struct iattr newattrs;
161
 
@@ -212,7 +212,7 @@ int do_truncate(struct dentry *dentry, l
162
 
        }
163
 
 
164
 
        mutex_lock(&dentry->d_inode->i_mutex);
165
 
-       err = notify_change(dentry, &newattrs);
166
 
+       err = notify_change(dentry, mnt, &newattrs);
167
 
        mutex_unlock(&dentry->d_inode->i_mutex);
168
 
        return err;
169
 
 }
170
 
@@ -267,7 +267,7 @@ static long do_sys_truncate(const char _
171
 
        error = locks_verify_truncate(inode, NULL, length);
172
 
        if (!error) {
173
 
                DQUOT_INIT(inode);
174
 
-               error = do_truncate(nd.dentry, length, 0, NULL);
175
 
+               error = do_truncate(nd.dentry, nd.mnt, length, 0, NULL);
176
 
        }
177
 
        put_write_access(inode);
178
 
 
179
 
@@ -319,7 +319,8 @@ static long do_sys_ftruncate(unsigned in
180
 
 
181
 
        error = locks_verify_truncate(inode, file, length);
182
 
        if (!error)
183
 
-               error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
184
 
+               error = do_truncate(dentry, file->f_path.mnt, length,
185
 
+                                   ATTR_MTIME|ATTR_CTIME, file);
186
 
 out_putf:
187
 
        fput(file);
188
 
 out:
189
 
@@ -519,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
190
 
                mode = inode->i_mode;
191
 
        newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
192
 
        newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
193
 
-       err = notify_change(dentry, &newattrs);
194
 
+       err = notify_change(dentry, file->f_path.mnt, &newattrs);
195
 
        mutex_unlock(&inode->i_mutex);
196
 
 
197
 
 out_putf:
198
 
@@ -554,7 +555,7 @@ asmlinkage long sys_fchmodat(int dfd, co
199
 
                mode = inode->i_mode;
200
 
        newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
201
 
        newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
202
 
-       error = notify_change(nd.dentry, &newattrs);
203
 
+       error = notify_change(nd.dentry, nd.mnt, &newattrs);
204
 
        mutex_unlock(&inode->i_mutex);
205
 
 
206
 
 dput_and_out:
207
 
@@ -568,7 +569,8 @@ asmlinkage long sys_chmod(const char __u
208
 
        return sys_fchmodat(AT_FDCWD, filename, mode);
209
 
 }
210
 
 
211
 
-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
212
 
+static int chown_common(struct dentry * dentry, struct vfsmount *mnt,
213
 
+                       uid_t user, gid_t group)
214
 
 {
215
 
        struct inode * inode;
216
 
        int error;
217
 
@@ -597,7 +599,7 @@ static int chown_common(struct dentry * 
218
 
        if (!S_ISDIR(inode->i_mode))
219
 
                newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
220
 
        mutex_lock(&inode->i_mutex);
221
 
-       error = notify_change(dentry, &newattrs);
222
 
+       error = notify_change(dentry, mnt, &newattrs);
223
 
        mutex_unlock(&inode->i_mutex);
224
 
 out:
225
 
        return error;
226
 
@@ -611,7 +613,7 @@ asmlinkage long sys_chown(const char __u
227
 
        error = user_path_walk(filename, &nd);
228
 
        if (error)
229
 
                goto out;
230
 
-       error = chown_common(nd.dentry, user, group);
231
 
+       error = chown_common(nd.dentry, nd.mnt, user, group);
232
 
        path_release(&nd);
233
 
 out:
234
 
        return error;
235
 
@@ -631,7 +633,7 @@ asmlinkage long sys_fchownat(int dfd, co
236
 
        error = __user_walk_fd(dfd, filename, follow, &nd);
237
 
        if (error)
238
 
                goto out;
239
 
-       error = chown_common(nd.dentry, user, group);
240
 
+       error = chown_common(nd.dentry, nd.mnt, user, group);
241
 
        path_release(&nd);
242
 
 out:
243
 
        return error;
244
 
@@ -645,7 +647,7 @@ asmlinkage long sys_lchown(const char __
245
 
        error = user_path_walk_link(filename, &nd);
246
 
        if (error)
247
 
                goto out;
248
 
-       error = chown_common(nd.dentry, user, group);
249
 
+       error = chown_common(nd.dentry, nd.mnt, user, group);
250
 
        path_release(&nd);
251
 
 out:
252
 
        return error;
253
 
@@ -664,7 +666,7 @@ asmlinkage long sys_fchown(unsigned int 
254
 
 
255
 
        dentry = file->f_path.dentry;
256
 
        audit_inode(NULL, dentry->d_inode);
257
 
-       error = chown_common(dentry, user, group);
258
 
+       error = chown_common(dentry, file->f_path.mnt, user, group);
259
 
        fput(file);
260
 
 out:
261
 
        return error;
262
 
Index: b/fs/reiserfs/xattr.c
263
 
===================================================================
264
 
--- a/fs/reiserfs/xattr.c
265
 
+++ b/fs/reiserfs/xattr.c
266
 
@@ -527,7 +527,7 @@ reiserfs_xattr_set(struct inode *inode, 
267
 
        newattrs.ia_size = buffer_size;
268
 
        newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
269
 
        mutex_lock(&xinode->i_mutex);
270
 
-       err = notify_change(fp->f_path.dentry, &newattrs);
271
 
+       err = notify_change(fp->f_path.dentry, NULL, &newattrs);
272
 
        if (err)
273
 
                goto out_filp;
274
 
 
275
 
@@ -867,7 +867,7 @@ reiserfs_chown_xattrs_filler(void *buf, 
276
 
        }
277
 
 
278
 
        if (!S_ISDIR(xafile->d_inode->i_mode))
279
 
-               err = notify_change(xafile, attrs);
280
 
+               err = notify_change(xafile, NULL, attrs);
281
 
        dput(xafile);
282
 
 
283
 
        return err;
284
 
@@ -919,7 +919,7 @@ int reiserfs_chown_xattrs(struct inode *
285
 
                goto out_dir;
286
 
        }
287
 
 
288
 
-       err = notify_change(dir, attrs);
289
 
+       err = notify_change(dir, NULL, attrs);
290
 
        unlock_kernel();
291
 
 
292
 
       out_dir:
293
 
Index: b/fs/sysfs/file.c
294
 
===================================================================
295
 
--- a/fs/sysfs/file.c
296
 
+++ b/fs/sysfs/file.c
297
 
@@ -560,7 +560,7 @@ int sysfs_chmod_file(struct kobject *kob
298
 
                        newattrs.ia_mode = (mode & S_IALLUGO) |
299
 
                                                (inode->i_mode & ~S_IALLUGO);
300
 
                        newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
301
 
-                       res = notify_change(victim, &newattrs);
302
 
+                       res = notify_change(victim, NULL, &newattrs);
303
 
                        mutex_unlock(&inode->i_mutex);
304
 
                }
305
 
                dput(victim);
306
 
Index: b/fs/utimes.c
307
 
===================================================================
308
 
--- a/fs/utimes.c
309
 
+++ b/fs/utimes.c
310
 
@@ -62,7 +62,7 @@ asmlinkage long sys_utime(char __user * 
311
 
                        goto dput_and_out;
312
 
        }
313
 
        mutex_lock(&inode->i_mutex);
314
 
-       error = notify_change(nd.dentry, &newattrs);
315
 
+       error = notify_change(nd.dentry, nd.mnt, &newattrs);
316
 
        mutex_unlock(&inode->i_mutex);
317
 
 dput_and_out:
318
 
        path_release(&nd);
319
 
@@ -115,7 +115,7 @@ long do_utimes(int dfd, char __user *fil
320
 
                        goto dput_and_out;
321
 
        }
322
 
        mutex_lock(&inode->i_mutex);
323
 
-       error = notify_change(nd.dentry, &newattrs);
324
 
+       error = notify_change(nd.dentry, nd.mnt, &newattrs);
325
 
        mutex_unlock(&inode->i_mutex);
326
 
 dput_and_out:
327
 
        path_release(&nd);
328
 
Index: b/mm/filemap.c
329
 
===================================================================
330
 
--- a/mm/filemap.c
331
 
+++ b/mm/filemap.c
332
 
@@ -1877,7 +1877,7 @@ int __remove_suid(struct path *path, int
333
 
        struct iattr newattrs;
334
 
 
335
 
        newattrs.ia_valid = ATTR_FORCE | kill;
336
 
-       return notify_change(path->dentry, &newattrs);
337
 
+       return notify_change(path->dentry, path->mnt, &newattrs);
338
 
 }
339
 
 
340
 
 int remove_suid(struct path *path)
341
 
Index: b/fs/exec.c
342
 
===================================================================
343
 
--- a/fs/exec.c
344
 
+++ b/fs/exec.c
345
 
@@ -1532,7 +1532,8 @@ int do_coredump(long signr, int exit_cod
346
 
                goto close_fail;
347
 
        if (!file->f_op->write)
348
 
                goto close_fail;
349
 
-       if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
350
 
+       if (!ispipe &&
351
 
+           do_truncate(file->f_path.dentry, file->f_path.mnt, 0, 0, file) != 0)
352
 
                goto close_fail;
353
 
 
354
 
        retval = binfmt->core_dump(signr, regs, file);
355
 
Index: b/fs/namei.c
356
 
===================================================================
357
 
--- a/fs/namei.c
358
 
+++ b/fs/namei.c
359
 
@@ -1580,7 +1580,8 @@ int may_open(struct nameidata *nd, int a
360
 
                if (!error) {
361
 
                        DQUOT_INIT(inode);
362
 
                        
363
 
-                       error = do_truncate(dentry, 0, ATTR_MTIME|ATTR_CTIME, NULL);
364
 
+                       error = do_truncate(dentry, nd->mnt, 0,
365
 
+                                           ATTR_MTIME|ATTR_CTIME, NULL);
366
 
                }
367
 
                put_write_access(inode);
368
 
                if (error)
369
 
Index: b/mm/tiny-shmem.c
370
 
===================================================================
371
 
--- a/mm/tiny-shmem.c
372
 
+++ b/mm/tiny-shmem.c
373
 
@@ -86,7 +86,7 @@ struct file *shmem_file_setup(char *name
374
 
        file->f_mode = FMODE_WRITE | FMODE_READ;
375
 
 
376
 
        /* notify everyone as to the change of file size */
377
 
-       error = do_truncate(dentry, size, 0, file);
378
 
+       error = do_truncate(dentry, file->f_path.mnt, size, 0, file);
379
 
        if (error < 0)
380
 
                goto close_file;
381