aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig.binfmt2
-rw-r--r--fs/Makefile3
-rw-r--r--fs/afs/file.c4
-rw-r--r--fs/afs/internal.h8
-rw-r--r--fs/afs/write.c131
-rw-r--r--fs/autofs4/Makefile2
-rw-r--r--fs/autofs4/autofs_i.h44
-rw-r--r--fs/autofs4/dev-ioctl.c863
-rw-r--r--fs/autofs4/expire.c18
-rw-r--r--fs/autofs4/init.c11
-rw-r--r--fs/autofs4/inode.c8
-rw-r--r--fs/autofs4/waitq.c42
-rw-r--r--fs/befs/befs_fs_types.h4
-rw-r--r--fs/befs/linuxvfs.c4
-rw-r--r--fs/befs/super.c6
-rw-r--r--fs/binfmt_elf.c6
-rw-r--r--fs/binfmt_elf_fdpic.c85
-rw-r--r--fs/binfmt_em86.c2
-rw-r--r--fs/binfmt_flat.c6
-rw-r--r--fs/binfmt_misc.c4
-rw-r--r--fs/binfmt_script.c5
-rw-r--r--fs/binfmt_som.c2
-rw-r--r--fs/compat.c41
-rw-r--r--fs/direct-io.c4
-rw-r--r--fs/dquot.c2
-rw-r--r--fs/ecryptfs/Makefile2
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h28
-rw-r--r--fs/ecryptfs/file.c17
-rw-r--r--fs/ecryptfs/keystore.c32
-rw-r--r--fs/ecryptfs/main.c19
-rw-r--r--fs/ecryptfs/messaging.c118
-rw-r--r--fs/ecryptfs/mmap.c81
-rw-r--r--fs/ecryptfs/netlink.c249
-rw-r--r--fs/eventpoll.c9
-rw-r--r--fs/exec.c6
-rw-r--r--fs/ext2/balloc.c3
-rw-r--r--fs/ext2/dir.c60
-rw-r--r--fs/fs-writeback.c2
-rw-r--r--fs/hfs/catalog.c4
-rw-r--r--fs/hfsplus/bitmap.c12
-rw-r--r--fs/hfsplus/catalog.c5
-rw-r--r--fs/hfsplus/super.c2
-rw-r--r--fs/mpage.c2
-rw-r--r--fs/partitions/acorn.c10
-rw-r--r--fs/partitions/check.c17
-rw-r--r--fs/proc/proc_misc.c26
-rw-r--r--fs/reiserfs/procfs.c3
-rw-r--r--fs/reiserfs/xattr.c2
48 files changed, 1345 insertions, 671 deletions
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index 17c9c5ec14c5..801db1341811 100644
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -25,7 +25,7 @@ config BINFMT_ELF
25 25
26config COMPAT_BINFMT_ELF 26config COMPAT_BINFMT_ELF
27 bool 27 bool
28 depends on COMPAT && MMU 28 depends on COMPAT && BINFMT_ELF
29 29
30config BINFMT_ELF_FDPIC 30config BINFMT_ELF_FDPIC
31 bool "Kernel support for FDPIC ELF binaries" 31 bool "Kernel support for FDPIC ELF binaries"
diff --git a/fs/Makefile b/fs/Makefile
index b6f27dc26b72..d0c69f57e5bf 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -8,7 +8,7 @@
8obj-y := open.o read_write.o file_table.o super.o \ 8obj-y := open.o read_write.o file_table.o super.o \
9 char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ 9 char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
10 ioctl.o readdir.o select.o fifo.o dcache.o inode.o \ 10 ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ 11 attr.o bad_inode.o file.o filesystems.o namespace.o \
12 seq_file.o xattr.o libfs.o fs-writeback.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o \
13 pnode.o drop_caches.o splice.o sync.o utimes.o \ 13 pnode.o drop_caches.o splice.o sync.o utimes.o \
14 stack.o 14 stack.o
@@ -27,6 +27,7 @@ obj-$(CONFIG_ANON_INODES) += anon_inodes.o
27obj-$(CONFIG_SIGNALFD) += signalfd.o 27obj-$(CONFIG_SIGNALFD) += signalfd.o
28obj-$(CONFIG_TIMERFD) += timerfd.o 28obj-$(CONFIG_TIMERFD) += timerfd.o
29obj-$(CONFIG_EVENTFD) += eventfd.o 29obj-$(CONFIG_EVENTFD) += eventfd.o
30obj-$(CONFIG_AIO) += aio.o
30obj-$(CONFIG_FILE_LOCKING) += locks.o 31obj-$(CONFIG_FILE_LOCKING) += locks.o
31obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o 32obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o
32 33
diff --git a/fs/afs/file.c b/fs/afs/file.c
index 525f7c56e068..a3901769a96c 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -50,8 +50,8 @@ const struct address_space_operations afs_fs_aops = {
50 .launder_page = afs_launder_page, 50 .launder_page = afs_launder_page,
51 .releasepage = afs_releasepage, 51 .releasepage = afs_releasepage,
52 .invalidatepage = afs_invalidatepage, 52 .invalidatepage = afs_invalidatepage,
53 .prepare_write = afs_prepare_write, 53 .write_begin = afs_write_begin,
54 .commit_write = afs_commit_write, 54 .write_end = afs_write_end,
55 .writepage = afs_writepage, 55 .writepage = afs_writepage,
56 .writepages = afs_writepages, 56 .writepages = afs_writepages,
57}; 57};
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 3cb6920ff30b..67f259d99cd6 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -728,8 +728,12 @@ extern int afs_volume_release_fileserver(struct afs_vnode *,
728 */ 728 */
729extern int afs_set_page_dirty(struct page *); 729extern int afs_set_page_dirty(struct page *);
730extern void afs_put_writeback(struct afs_writeback *); 730extern void afs_put_writeback(struct afs_writeback *);
731extern int afs_prepare_write(struct file *, struct page *, unsigned, unsigned); 731extern int afs_write_begin(struct file *file, struct address_space *mapping,
732extern int afs_commit_write(struct file *, struct page *, unsigned, unsigned); 732 loff_t pos, unsigned len, unsigned flags,
733 struct page **pagep, void **fsdata);
734extern int afs_write_end(struct file *file, struct address_space *mapping,
735 loff_t pos, unsigned len, unsigned copied,
736 struct page *page, void *fsdata);
733extern int afs_writepage(struct page *, struct writeback_control *); 737extern int afs_writepage(struct page *, struct writeback_control *);
734extern int afs_writepages(struct address_space *, struct writeback_control *); 738extern int afs_writepages(struct address_space *, struct writeback_control *);
735extern int afs_write_inode(struct inode *, int); 739extern int afs_write_inode(struct inode *, int);
diff --git a/fs/afs/write.c b/fs/afs/write.c
index 065b4e10681a..d6b85dab35fc 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -84,15 +84,23 @@ void afs_put_writeback(struct afs_writeback *wb)
84 * partly or wholly fill a page that's under preparation for writing 84 * partly or wholly fill a page that's under preparation for writing
85 */ 85 */
86static int afs_fill_page(struct afs_vnode *vnode, struct key *key, 86static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
87 unsigned start, unsigned len, struct page *page) 87 loff_t pos, unsigned len, struct page *page)
88{ 88{
89 loff_t i_size;
90 unsigned eof;
89 int ret; 91 int ret;
90 92
91 _enter(",,%u,%u", start, len); 93 _enter(",,%llu,%u", (unsigned long long)pos, len);
92 94
93 ASSERTCMP(start + len, <=, PAGE_SIZE); 95 ASSERTCMP(len, <=, PAGE_CACHE_SIZE);
94 96
95 ret = afs_vnode_fetch_data(vnode, key, start, len, page); 97 i_size = i_size_read(&vnode->vfs_inode);
98 if (pos + len > i_size)
99 eof = i_size;
100 else
101 eof = PAGE_CACHE_SIZE;
102
103 ret = afs_vnode_fetch_data(vnode, key, 0, eof, page);
96 if (ret < 0) { 104 if (ret < 0) {
97 if (ret == -ENOENT) { 105 if (ret == -ENOENT) {
98 _debug("got NOENT from server" 106 _debug("got NOENT from server"
@@ -107,109 +115,55 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
107} 115}
108 116
109/* 117/*
110 * prepare a page for being written to
111 */
112static int afs_prepare_page(struct afs_vnode *vnode, struct page *page,
113 struct key *key, unsigned offset, unsigned to)
114{
115 unsigned eof, tail, start, stop, len;
116 loff_t i_size, pos;
117 void *p;
118 int ret;
119
120 _enter("");
121
122 if (offset == 0 && to == PAGE_SIZE)
123 return 0;
124
125 p = kmap_atomic(page, KM_USER0);
126
127 i_size = i_size_read(&vnode->vfs_inode);
128 pos = (loff_t) page->index << PAGE_SHIFT;
129 if (pos >= i_size) {
130 /* partial write, page beyond EOF */
131 _debug("beyond");
132 if (offset > 0)
133 memset(p, 0, offset);
134 if (to < PAGE_SIZE)
135 memset(p + to, 0, PAGE_SIZE - to);
136 kunmap_atomic(p, KM_USER0);
137 return 0;
138 }
139
140 if (i_size - pos >= PAGE_SIZE) {
141 /* partial write, page entirely before EOF */
142 _debug("before");
143 tail = eof = PAGE_SIZE;
144 } else {
145 /* partial write, page overlaps EOF */
146 eof = i_size - pos;
147 _debug("overlap %u", eof);
148 tail = max(eof, to);
149 if (tail < PAGE_SIZE)
150 memset(p + tail, 0, PAGE_SIZE - tail);
151 if (offset > eof)
152 memset(p + eof, 0, PAGE_SIZE - eof);
153 }
154
155 kunmap_atomic(p, KM_USER0);
156
157 ret = 0;
158 if (offset > 0 || eof > to) {
159 /* need to fill one or two bits that aren't going to be written
160 * (cover both fillers in one read if there are two) */
161 start = (offset > 0) ? 0 : to;
162 stop = (eof > to) ? eof : offset;
163 len = stop - start;
164 _debug("wr=%u-%u av=0-%u rd=%u@%u",
165 offset, to, eof, start, len);
166 ret = afs_fill_page(vnode, key, start, len, page);
167 }
168
169 _leave(" = %d", ret);
170 return ret;
171}
172
173/*
174 * prepare to perform part of a write to a page 118 * prepare to perform part of a write to a page
175 * - the caller holds the page locked, preventing it from being written out or
176 * modified by anyone else
177 */ 119 */
178int afs_prepare_write(struct file *file, struct page *page, 120int afs_write_begin(struct file *file, struct address_space *mapping,
179 unsigned offset, unsigned to) 121 loff_t pos, unsigned len, unsigned flags,
122 struct page **pagep, void **fsdata)
180{ 123{
181 struct afs_writeback *candidate, *wb; 124 struct afs_writeback *candidate, *wb;
182 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode); 125 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
126 struct page *page;
183 struct key *key = file->private_data; 127 struct key *key = file->private_data;
184 pgoff_t index; 128 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
129 unsigned to = from + len;
130 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
185 int ret; 131 int ret;
186 132
187 _enter("{%x:%u},{%lx},%u,%u", 133 _enter("{%x:%u},{%lx},%u,%u",
188 vnode->fid.vid, vnode->fid.vnode, page->index, offset, to); 134 vnode->fid.vid, vnode->fid.vnode, index, from, to);
189 135
190 candidate = kzalloc(sizeof(*candidate), GFP_KERNEL); 136 candidate = kzalloc(sizeof(*candidate), GFP_KERNEL);
191 if (!candidate) 137 if (!candidate)
192 return -ENOMEM; 138 return -ENOMEM;
193 candidate->vnode = vnode; 139 candidate->vnode = vnode;
194 candidate->first = candidate->last = page->index; 140 candidate->first = candidate->last = index;
195 candidate->offset_first = offset; 141 candidate->offset_first = from;
196 candidate->to_last = to; 142 candidate->to_last = to;
197 candidate->usage = 1; 143 candidate->usage = 1;
198 candidate->state = AFS_WBACK_PENDING; 144 candidate->state = AFS_WBACK_PENDING;
199 init_waitqueue_head(&candidate->waitq); 145 init_waitqueue_head(&candidate->waitq);
200 146
147 page = __grab_cache_page(mapping, index);
148 if (!page) {
149 kfree(candidate);
150 return -ENOMEM;
151 }
152 *pagep = page;
153 /* page won't leak in error case: it eventually gets cleaned off LRU */
154
201 if (!PageUptodate(page)) { 155 if (!PageUptodate(page)) {
202 _debug("not up to date"); 156 _debug("not up to date");
203 ret = afs_prepare_page(vnode, page, key, offset, to); 157 ret = afs_fill_page(vnode, key, pos, len, page);
204 if (ret < 0) { 158 if (ret < 0) {
205 kfree(candidate); 159 kfree(candidate);
206 _leave(" = %d [prep]", ret); 160 _leave(" = %d [prep]", ret);
207 return ret; 161 return ret;
208 } 162 }
163 SetPageUptodate(page);
209 } 164 }
210 165
211try_again: 166try_again:
212 index = page->index;
213 spin_lock(&vnode->writeback_lock); 167 spin_lock(&vnode->writeback_lock);
214 168
215 /* see if this page is already pending a writeback under a suitable key 169 /* see if this page is already pending a writeback under a suitable key
@@ -242,8 +196,8 @@ try_again:
242subsume_in_current_wb: 196subsume_in_current_wb:
243 _debug("subsume"); 197 _debug("subsume");
244 ASSERTRANGE(wb->first, <=, index, <=, wb->last); 198 ASSERTRANGE(wb->first, <=, index, <=, wb->last);
245 if (index == wb->first && offset < wb->offset_first) 199 if (index == wb->first && from < wb->offset_first)
246 wb->offset_first = offset; 200 wb->offset_first = from;
247 if (index == wb->last && to > wb->to_last) 201 if (index == wb->last && to > wb->to_last)
248 wb->to_last = to; 202 wb->to_last = to;
249 spin_unlock(&vnode->writeback_lock); 203 spin_unlock(&vnode->writeback_lock);
@@ -289,17 +243,17 @@ flush_conflicting_wb:
289/* 243/*
290 * finalise part of a write to a page 244 * finalise part of a write to a page
291 */ 245 */
292int afs_commit_write(struct file *file, struct page *page, 246int afs_write_end(struct file *file, struct address_space *mapping,
293 unsigned offset, unsigned to) 247 loff_t pos, unsigned len, unsigned copied,
248 struct page *page, void *fsdata)
294{ 249{
295 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode); 250 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
296 loff_t i_size, maybe_i_size; 251 loff_t i_size, maybe_i_size;
297 252
298 _enter("{%x:%u},{%lx},%u,%u", 253 _enter("{%x:%u},{%lx}",
299 vnode->fid.vid, vnode->fid.vnode, page->index, offset, to); 254 vnode->fid.vid, vnode->fid.vnode, page->index);
300 255
301 maybe_i_size = (loff_t) page->index << PAGE_SHIFT; 256 maybe_i_size = pos + copied;
302 maybe_i_size += to;
303 257
304 i_size = i_size_read(&vnode->vfs_inode); 258 i_size = i_size_read(&vnode->vfs_inode);
305 if (maybe_i_size > i_size) { 259 if (maybe_i_size > i_size) {
@@ -310,12 +264,13 @@ int afs_commit_write(struct file *file, struct page *page,
310 spin_unlock(&vnode->writeback_lock); 264 spin_unlock(&vnode->writeback_lock);
311 } 265 }
312 266
313 SetPageUptodate(page);
314 set_page_dirty(page); 267 set_page_dirty(page);
315 if (PageDirty(page)) 268 if (PageDirty(page))
316 _debug("dirtied"); 269 _debug("dirtied");
270 unlock_page(page);
271 page_cache_release(page);
317 272
318 return 0; 273 return copied;
319} 274}
320 275
321/* 276/*
diff --git a/fs/autofs4/Makefile b/fs/autofs4/Makefile
index f2c3b79e94d2..a811c1f7d9ab 100644
--- a/fs/autofs4/Makefile
+++ b/fs/autofs4/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-$(CONFIG_AUTOFS4_FS) += autofs4.o 5obj-$(CONFIG_AUTOFS4_FS) += autofs4.o
6 6
7autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o 7autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o dev-ioctl.o
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index 69a2f5c92319..e0f16da00e54 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -14,6 +14,7 @@
14/* Internal header file for autofs */ 14/* Internal header file for autofs */
15 15
16#include <linux/auto_fs4.h> 16#include <linux/auto_fs4.h>
17#include <linux/auto_dev-ioctl.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
18#include <linux/list.h> 19#include <linux/list.h>
19 20
@@ -21,6 +22,11 @@
21#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY 22#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
22#define AUTOFS_IOC_COUNT 32 23#define AUTOFS_IOC_COUNT 32
23 24
25#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)
26#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11)
27
28#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)
29
24#include <linux/kernel.h> 30#include <linux/kernel.h>
25#include <linux/slab.h> 31#include <linux/slab.h>
26#include <linux/time.h> 32#include <linux/time.h>
@@ -35,11 +41,27 @@
35/* #define DEBUG */ 41/* #define DEBUG */
36 42
37#ifdef DEBUG 43#ifdef DEBUG
38#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __func__ , ##args); } while(0) 44#define DPRINTK(fmt, args...) \
45do { \
46 printk(KERN_DEBUG "pid %d: %s: " fmt "\n", \
47 current->pid, __func__, ##args); \
48} while (0)
39#else 49#else
40#define DPRINTK(fmt,args...) do {} while(0) 50#define DPRINTK(fmt, args...) do {} while (0)
41#endif 51#endif
42 52
53#define AUTOFS_WARN(fmt, args...) \
54do { \
55 printk(KERN_WARNING "pid %d: %s: " fmt "\n", \
56 current->pid, __func__, ##args); \
57} while (0)
58
59#define AUTOFS_ERROR(fmt, args...) \
60do { \
61 printk(KERN_ERR "pid %d: %s: " fmt "\n", \
62 current->pid, __func__, ##args); \
63} while (0)
64
43/* Unified info structure. This is pointed to by both the dentry and 65/* Unified info structure. This is pointed to by both the dentry and
44 inode structures. Each file in the filesystem has an instance of this 66 inode structures. Each file in the filesystem has an instance of this
45 structure. It holds a reference to the dentry, so dentries are never 67 structure. It holds a reference to the dentry, so dentries are never
@@ -61,6 +83,9 @@ struct autofs_info {
61 unsigned long last_used; 83 unsigned long last_used;
62 atomic_t count; 84 atomic_t count;
63 85
86 uid_t uid;
87 gid_t gid;
88
64 mode_t mode; 89 mode_t mode;
65 size_t size; 90 size_t size;
66 91
@@ -92,10 +117,6 @@ struct autofs_wait_queue {
92 117
93#define AUTOFS_SBI_MAGIC 0x6d4a556d 118#define AUTOFS_SBI_MAGIC 0x6d4a556d
94 119
95#define AUTOFS_TYPE_INDIRECT 0x0001
96#define AUTOFS_TYPE_DIRECT 0x0002
97#define AUTOFS_TYPE_OFFSET 0x0004
98
99struct autofs_sb_info { 120struct autofs_sb_info {
100 u32 magic; 121 u32 magic;
101 int pipefd; 122 int pipefd;
@@ -169,6 +190,17 @@ int autofs4_expire_run(struct super_block *, struct vfsmount *,
169 struct autofs_packet_expire __user *); 190 struct autofs_packet_expire __user *);
170int autofs4_expire_multi(struct super_block *, struct vfsmount *, 191int autofs4_expire_multi(struct super_block *, struct vfsmount *,
171 struct autofs_sb_info *, int __user *); 192 struct autofs_sb_info *, int __user *);
193struct dentry *autofs4_expire_direct(struct super_block *sb,
194 struct vfsmount *mnt,
195 struct autofs_sb_info *sbi, int how);
196struct dentry *autofs4_expire_indirect(struct super_block *sb,
197 struct vfsmount *mnt,
198 struct autofs_sb_info *sbi, int how);
199
200/* Device node initialization */
201
202int autofs_dev_ioctl_init(void);
203void autofs_dev_ioctl_exit(void);
172 204
173/* Operations structures */ 205/* Operations structures */
174 206
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
new file mode 100644
index 000000000000..625abf5422e2
--- /dev/null
+++ b/fs/autofs4/dev-ioctl.c
@@ -0,0 +1,863 @@
1/*
2 * Copyright 2008 Red Hat, Inc. All rights reserved.
3 * Copyright 2008 Ian Kent <raven@themaw.net>
4 *
5 * This file is part of the Linux kernel and is made available under
6 * the terms of the GNU General Public License, version 2, or at your
7 * option, any later version, incorporated herein by reference.
8 */
9
10#include <linux/module.h>
11#include <linux/vmalloc.h>
12#include <linux/miscdevice.h>
13#include <linux/init.h>
14#include <linux/wait.h>
15#include <linux/namei.h>
16#include <linux/fcntl.h>
17#include <linux/file.h>
18#include <linux/fdtable.h>
19#include <linux/sched.h>
20#include <linux/compat.h>
21#include <linux/syscalls.h>
22#include <linux/smp_lock.h>
23#include <linux/magic.h>
24#include <linux/dcache.h>
25#include <linux/uaccess.h>
26
27#include "autofs_i.h"
28
29/*
30 * This module implements an interface for routing autofs ioctl control
31 * commands via a miscellaneous device file.
32 *
33 * The alternate interface is needed because we need to be able open
34 * an ioctl file descriptor on an autofs mount that may be covered by
35 * another mount. This situation arises when starting automount(8)
36 * or other user space daemon which uses direct mounts or offset
37 * mounts (used for autofs lazy mount/umount of nested mount trees),
38 * which have been left busy at at service shutdown.
39 */
40
41#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
42
43typedef int (*ioctl_fn)(struct file *, struct autofs_sb_info *,
44 struct autofs_dev_ioctl *);
45
46static int check_name(const char *name)
47{
48 if (!strchr(name, '/'))
49 return -EINVAL;
50 return 0;
51}
52
53/*
54 * Check a string doesn't overrun the chunk of
55 * memory we copied from user land.
56 */
57static int invalid_str(char *str, void *end)
58{
59 while ((void *) str <= end)
60 if (!*str++)
61 return 0;
62 return -EINVAL;
63}
64
65/*
66 * Check that the user compiled against correct version of autofs
67 * misc device code.
68 *
69 * As well as checking the version compatibility this always copies
70 * the kernel interface version out.
71 */
72static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
73{
74 int err = 0;
75
76 if ((AUTOFS_DEV_IOCTL_VERSION_MAJOR != param->ver_major) ||
77 (AUTOFS_DEV_IOCTL_VERSION_MINOR < param->ver_minor)) {
78 AUTOFS_WARN("ioctl control interface version mismatch: "
79 "kernel(%u.%u), user(%u.%u), cmd(%d)",
80 AUTOFS_DEV_IOCTL_VERSION_MAJOR,
81 AUTOFS_DEV_IOCTL_VERSION_MINOR,
82 param->ver_major, param->ver_minor, cmd);
83 err = -EINVAL;
84 }
85
86 /* Fill in the kernel version. */
87 param->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
88 param->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
89
90 return err;
91}
92
93/*
94 * Copy parameter control struct, including a possible path allocated
95 * at the end of the struct.
96 */
97static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in)
98{
99 struct autofs_dev_ioctl tmp, *ads;
100
101 if (copy_from_user(&tmp, in, sizeof(tmp)))
102 return ERR_PTR(-EFAULT);
103
104 if (tmp.size < sizeof(tmp))
105 return ERR_PTR(-EINVAL);
106
107 ads = kmalloc(tmp.size, GFP_KERNEL);
108 if (!ads)
109 return ERR_PTR(-ENOMEM);
110
111 if (copy_from_user(ads, in, tmp.size)) {
112 kfree(ads);
113 return ERR_PTR(-EFAULT);
114 }
115
116 return ads;
117}
118
119static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)
120{
121 kfree(param);
122 return;
123}
124
125/*
126 * Check sanity of parameter control fields and if a path is present
127 * check that it has a "/" and is terminated.
128 */
129static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
130{
131 int err = -EINVAL;
132
133 if (check_dev_ioctl_version(cmd, param)) {
134 AUTOFS_WARN("invalid device control module version "
135 "supplied for cmd(0x%08x)", cmd);
136 goto out;
137 }
138
139 if (param->size > sizeof(*param)) {
140 err = check_name(param->path);
141 if (err) {
142 AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
143 cmd);
144 goto out;
145 }
146
147 err = invalid_str(param->path,
148 (void *) ((size_t) param + param->size));
149 if (err) {
150 AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
151 cmd);
152 goto out;
153 }
154 }
155
156 err = 0;
157out:
158 return err;
159}
160
161/*
162 * Get the autofs super block info struct from the file opened on
163 * the autofs mount point.
164 */
165static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
166{
167 struct autofs_sb_info *sbi = NULL;
168 struct inode *inode;
169
170 if (f) {
171 inode = f->f_path.dentry->d_inode;
172 sbi = autofs4_sbi(inode->i_sb);
173 }
174 return sbi;
175}
176
177/* Return autofs module protocol version */
178static int autofs_dev_ioctl_protover(struct file *fp,
179 struct autofs_sb_info *sbi,
180 struct autofs_dev_ioctl *param)
181{
182 param->arg1 = sbi->version;
183 return 0;
184}
185
186/* Return autofs module protocol sub version */
187static int autofs_dev_ioctl_protosubver(struct file *fp,
188 struct autofs_sb_info *sbi,
189 struct autofs_dev_ioctl *param)
190{
191 param->arg1 = sbi->sub_version;
192 return 0;
193}
194
195/*
196 * Walk down the mount stack looking for an autofs mount that
197 * has the requested device number (aka. new_encode_dev(sb->s_dev).
198 */
199static int autofs_dev_ioctl_find_super(struct nameidata *nd, dev_t devno)
200{
201 struct dentry *dentry;
202 struct inode *inode;
203 struct super_block *sb;
204 dev_t s_dev;
205 unsigned int err;
206
207 err = -ENOENT;
208
209 /* Lookup the dentry name at the base of our mount point */
210 dentry = d_lookup(nd->path.dentry, &nd->last);
211 if (!dentry)
212 goto out;
213
214 dput(nd->path.dentry);
215 nd->path.dentry = dentry;
216
217 /* And follow the mount stack looking for our autofs mount */
218 while (follow_down(&nd->path.mnt, &nd->path.dentry)) {
219 inode = nd->path.dentry->d_inode;
220 if (!inode)
221 break;
222
223 sb = inode->i_sb;
224 s_dev = new_encode_dev(sb->s_dev);
225 if (devno == s_dev) {
226 if (sb->s_magic == AUTOFS_SUPER_MAGIC) {
227 err = 0;
228 break;
229 }
230 }
231 }
232out:
233 return err;
234}
235
236/*
237 * Walk down the mount stack looking for an autofs mount that
238 * has the requested mount type (ie. indirect, direct or offset).
239 */
240static int autofs_dev_ioctl_find_sbi_type(struct nameidata *nd, unsigned int type)
241{
242 struct dentry *dentry;
243 struct autofs_info *ino;
244 unsigned int err;
245
246 err = -ENOENT;
247
248 /* Lookup the dentry name at the base of our mount point */
249 dentry = d_lookup(nd->path.dentry, &nd->last);
250 if (!dentry)
251 goto out;
252
253 dput(nd->path.dentry);
254 nd->path.dentry = dentry;
255
256 /* And follow the mount stack looking for our autofs mount */
257 while (follow_down(&nd->path.mnt, &nd->path.dentry)) {
258 ino = autofs4_dentry_ino(nd->path.dentry);
259 if (ino && ino->sbi->type & type) {
260 err = 0;
261 break;
262 }
263 }
264out:
265 return err;
266}
267
268static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file)
269{
270 struct files_struct *files = current->files;
271 struct fdtable *fdt;
272
273 spin_lock(&files->file_lock);
274 fdt = files_fdtable(files);
275 BUG_ON(fdt->fd[fd] != NULL);
276 rcu_assign_pointer(fdt->fd[fd], file);
277 FD_SET(fd, fdt->close_on_exec);
278 spin_unlock(&files->file_lock);
279}
280
281
282/*
283 * Open a file descriptor on the autofs mount point corresponding
284 * to the given path and device number (aka. new_encode_dev(sb->s_dev)).
285 */
286static int autofs_dev_ioctl_open_mountpoint(const char *path, dev_t devid)
287{
288 struct file *filp;
289 struct nameidata nd;
290 int err, fd;
291
292 fd = get_unused_fd();
293 if (likely(fd >= 0)) {
294 /* Get nameidata of the parent directory */
295 err = path_lookup(path, LOOKUP_PARENT, &nd);
296 if (err)
297 goto out;
298
299 /*
300 * Search down, within the parent, looking for an
301 * autofs super block that has the device number
302 * corresponding to the autofs fs we want to open.
303 */
304 err = autofs_dev_ioctl_find_super(&nd, devid);
305 if (err) {
306 path_put(&nd.path);
307 goto out;
308 }
309
310 filp = dentry_open(nd.path.dentry, nd.path.mnt, O_RDONLY);
311 if (IS_ERR(filp)) {
312 err = PTR_ERR(filp);
313 goto out;
314 }
315
316 autofs_dev_ioctl_fd_install(fd, filp);
317 }
318
319 return fd;
320
321out:
322 put_unused_fd(fd);
323 return err;
324}
325
326/* Open a file descriptor on an autofs mount point */
327static int autofs_dev_ioctl_openmount(struct file *fp,
328 struct autofs_sb_info *sbi,
329 struct autofs_dev_ioctl *param)
330{
331 const char *path;
332 dev_t devid;
333 int err, fd;
334
335 /* param->path has already been checked */
336 if (!param->arg1)
337 return -EINVAL;
338
339 param->ioctlfd = -1;
340
341 path = param->path;
342 devid = param->arg1;
343
344 err = 0;
345 fd = autofs_dev_ioctl_open_mountpoint(path, devid);
346 if (unlikely(fd < 0)) {
347 err = fd;
348 goto out;
349 }
350
351 param->ioctlfd = fd;
352out:
353 return err;
354}
355
356/* Close file descriptor allocated above (user can also use close(2)). */
357static int autofs_dev_ioctl_closemount(struct file *fp,
358 struct autofs_sb_info *sbi,
359 struct autofs_dev_ioctl *param)
360{
361 return sys_close(param->ioctlfd);
362}
363
364/*
365 * Send "ready" status for an existing wait (either a mount or an expire
366 * request).
367 */
368static int autofs_dev_ioctl_ready(struct file *fp,
369 struct autofs_sb_info *sbi,
370 struct autofs_dev_ioctl *param)
371{
372 autofs_wqt_t token;
373
374 token = (autofs_wqt_t) param->arg1;
375 return autofs4_wait_release(sbi, token, 0);
376}
377
378/*
379 * Send "fail" status for an existing wait (either a mount or an expire
380 * request).
381 */
382static int autofs_dev_ioctl_fail(struct file *fp,
383 struct autofs_sb_info *sbi,
384 struct autofs_dev_ioctl *param)
385{
386 autofs_wqt_t token;
387 int status;
388
389 token = (autofs_wqt_t) param->arg1;
390 status = param->arg2 ? param->arg2 : -ENOENT;
391 return autofs4_wait_release(sbi, token, status);
392}
393
394/*
395 * Set the pipe fd for kernel communication to the daemon.
396 *
397 * Normally this is set at mount using an option but if we
398 * are reconnecting to a busy mount then we need to use this
399 * to tell the autofs mount about the new kernel pipe fd. In
400 * order to protect mounts against incorrectly setting the
401 * pipefd we also require that the autofs mount be catatonic.
402 *
403 * This also sets the process group id used to identify the
404 * controlling process (eg. the owning automount(8) daemon).
405 */
406static int autofs_dev_ioctl_setpipefd(struct file *fp,
407 struct autofs_sb_info *sbi,
408 struct autofs_dev_ioctl *param)
409{
410 int pipefd;
411 int err = 0;
412
413 if (param->arg1 == -1)
414 return -EINVAL;
415
416 pipefd = param->arg1;
417
418 mutex_lock(&sbi->wq_mutex);
419 if (!sbi->catatonic) {
420 mutex_unlock(&sbi->wq_mutex);
421 return -EBUSY;
422 } else {
423 struct file *pipe = fget(pipefd);
424 if (!pipe->f_op || !pipe->f_op->write) {
425 err = -EPIPE;
426 fput(pipe);
427 goto out;
428 }
429 sbi->oz_pgrp = task_pgrp_nr(current);
430 sbi->pipefd = pipefd;
431 sbi->pipe = pipe;
432 sbi->catatonic = 0;
433 }
434out:
435 mutex_unlock(&sbi->wq_mutex);
436 return err;
437}
438
439/*
440 * Make the autofs mount point catatonic, no longer responsive to
441 * mount requests. Also closes the kernel pipe file descriptor.
442 */
443static int autofs_dev_ioctl_catatonic(struct file *fp,
444 struct autofs_sb_info *sbi,
445 struct autofs_dev_ioctl *param)
446{
447 autofs4_catatonic_mode(sbi);
448 return 0;
449}
450
451/* Set the autofs mount timeout */
452static int autofs_dev_ioctl_timeout(struct file *fp,
453 struct autofs_sb_info *sbi,
454 struct autofs_dev_ioctl *param)
455{
456 unsigned long timeout;
457
458 timeout = param->arg1;
459 param->arg1 = sbi->exp_timeout / HZ;
460 sbi->exp_timeout = timeout * HZ;
461 return 0;
462}
463
464/*
465 * Return the uid and gid of the last request for the mount
466 *
467 * When reconstructing an autofs mount tree with active mounts
468 * we need to re-connect to mounts that may have used the original
469 * process uid and gid (or string variations of them) for mount
470 * lookups within the map entry.
471 */
472static int autofs_dev_ioctl_requester(struct file *fp,
473 struct autofs_sb_info *sbi,
474 struct autofs_dev_ioctl *param)
475{
476 struct autofs_info *ino;
477 struct nameidata nd;
478 const char *path;
479 dev_t devid;
480 int err = -ENOENT;
481
482 if (param->size <= sizeof(*param)) {
483 err = -EINVAL;
484 goto out;
485 }
486
487 path = param->path;
488 devid = sbi->sb->s_dev;
489
490 param->arg1 = param->arg2 = -1;
491
492 /* Get nameidata of the parent directory */
493 err = path_lookup(path, LOOKUP_PARENT, &nd);
494 if (err)
495 goto out;
496
497 err = autofs_dev_ioctl_find_super(&nd, devid);
498 if (err)
499 goto out_release;
500
501 ino = autofs4_dentry_ino(nd.path.dentry);
502 if (ino) {
503 err = 0;
504 autofs4_expire_wait(nd.path.dentry);
505 spin_lock(&sbi->fs_lock);
506 param->arg1 = ino->uid;
507 param->arg2 = ino->gid;
508 spin_unlock(&sbi->fs_lock);
509 }
510
511out_release:
512 path_put(&nd.path);
513out:
514 return err;
515}
516
517/*
518 * Call repeatedly until it returns -EAGAIN, meaning there's nothing
519 * more that can be done.
520 */
521static int autofs_dev_ioctl_expire(struct file *fp,
522 struct autofs_sb_info *sbi,
523 struct autofs_dev_ioctl *param)
524{
525 struct dentry *dentry;
526 struct vfsmount *mnt;
527 int err = -EAGAIN;
528 int how;
529
530 how = param->arg1;
531 mnt = fp->f_path.mnt;
532
533 if (sbi->type & AUTOFS_TYPE_TRIGGER)
534 dentry = autofs4_expire_direct(sbi->sb, mnt, sbi, how);
535 else
536 dentry = autofs4_expire_indirect(sbi->sb, mnt, sbi, how);
537
538 if (dentry) {
539 struct autofs_info *ino = autofs4_dentry_ino(dentry);
540
541 /*
542 * This is synchronous because it makes the daemon a
543 * little easier
544 */
545 err = autofs4_wait(sbi, dentry, NFY_EXPIRE);
546
547 spin_lock(&sbi->fs_lock);
548 if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
549 ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
550 sbi->sb->s_root->d_mounted++;
551 }
552 ino->flags &= ~AUTOFS_INF_EXPIRING;
553 complete_all(&ino->expire_complete);
554 spin_unlock(&sbi->fs_lock);
555 dput(dentry);
556 }
557
558 return err;
559}
560
561/* Check if autofs mount point is in use */
562static int autofs_dev_ioctl_askumount(struct file *fp,
563 struct autofs_sb_info *sbi,
564 struct autofs_dev_ioctl *param)
565{
566 param->arg1 = 0;
567 if (may_umount(fp->f_path.mnt))
568 param->arg1 = 1;
569 return 0;
570}
571
572/*
573 * Check if the given path is a mountpoint.
574 *
575 * If we are supplied with the file descriptor of an autofs
576 * mount we're looking for a specific mount. In this case
577 * the path is considered a mountpoint if it is itself a
578 * mountpoint or contains a mount, such as a multi-mount
579 * without a root mount. In this case we return 1 if the
580 * path is a mount point and the super magic of the covering
581 * mount if there is one or 0 if it isn't a mountpoint.
582 *
583 * If we aren't supplied with a file descriptor then we
584 * lookup the nameidata of the path and check if it is the
585 * root of a mount. If a type is given we are looking for
586 * a particular autofs mount and if we don't find a match
587 * we return fail. If the located nameidata path is the
588 * root of a mount we return 1 along with the super magic
589 * of the mount or 0 otherwise.
590 *
591 * In both cases the the device number (as returned by
592 * new_encode_dev()) is also returned.
593 */
594static int autofs_dev_ioctl_ismountpoint(struct file *fp,
595 struct autofs_sb_info *sbi,
596 struct autofs_dev_ioctl *param)
597{
598 struct nameidata nd;
599 const char *path;
600 unsigned int type;
601 int err = -ENOENT;
602
603 if (param->size <= sizeof(*param)) {
604 err = -EINVAL;
605 goto out;
606 }
607
608 path = param->path;
609 type = param->arg1;
610
611 param->arg1 = 0;
612 param->arg2 = 0;
613
614 if (!fp || param->ioctlfd == -1) {
615 if (type == AUTOFS_TYPE_ANY) {
616 struct super_block *sb;
617
618 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
619 if (err)
620 goto out;
621
622 sb = nd.path.dentry->d_sb;
623 param->arg1 = new_encode_dev(sb->s_dev);
624 } else {
625 struct autofs_info *ino;
626
627 err = path_lookup(path, LOOKUP_PARENT, &nd);
628 if (err)
629 goto out;
630
631 err = autofs_dev_ioctl_find_sbi_type(&nd, type);
632 if (err)
633 goto out_release;
634
635 ino = autofs4_dentry_ino(nd.path.dentry);
636 param->arg1 = autofs4_get_dev(ino->sbi);
637 }
638
639 err = 0;
640 if (nd.path.dentry->d_inode &&
641 nd.path.mnt->mnt_root == nd.path.dentry) {
642 err = 1;
643 param->arg2 = nd.path.dentry->d_inode->i_sb->s_magic;
644 }
645 } else {
646 dev_t devid = new_encode_dev(sbi->sb->s_dev);
647
648 err = path_lookup(path, LOOKUP_PARENT, &nd);
649 if (err)
650 goto out;
651
652 err = autofs_dev_ioctl_find_super(&nd, devid);
653 if (err)
654 goto out_release;
655
656 param->arg1 = autofs4_get_dev(sbi);
657
658 err = have_submounts(nd.path.dentry);
659
660 if (nd.path.mnt->mnt_mountpoint != nd.path.mnt->mnt_root) {
661 if (follow_down(&nd.path.mnt, &nd.path.dentry)) {
662 struct inode *inode = nd.path.dentry->d_inode;
663 param->arg2 = inode->i_sb->s_magic;
664 }
665 }
666 }
667
668out_release:
669 path_put(&nd.path);
670out:
671 return err;
672}
673
674/*
675 * Our range of ioctl numbers isn't 0 based so we need to shift
676 * the array index by _IOC_NR(AUTOFS_CTL_IOC_FIRST) for the table
677 * lookup.
678 */
679#define cmd_idx(cmd) (cmd - _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST))
680
681static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
682{
683 static struct {
684 int cmd;
685 ioctl_fn fn;
686 } _ioctls[] = {
687 {cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD), NULL},
688 {cmd_idx(AUTOFS_DEV_IOCTL_PROTOVER_CMD),
689 autofs_dev_ioctl_protover},
690 {cmd_idx(AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD),
691 autofs_dev_ioctl_protosubver},
692 {cmd_idx(AUTOFS_DEV_IOCTL_OPENMOUNT_CMD),
693 autofs_dev_ioctl_openmount},
694 {cmd_idx(AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD),
695 autofs_dev_ioctl_closemount},
696 {cmd_idx(AUTOFS_DEV_IOCTL_READY_CMD),
697 autofs_dev_ioctl_ready},
698 {cmd_idx(AUTOFS_DEV_IOCTL_FAIL_CMD),
699 autofs_dev_ioctl_fail},
700 {cmd_idx(AUTOFS_DEV_IOCTL_SETPIPEFD_CMD),
701 autofs_dev_ioctl_setpipefd},
702 {cmd_idx(AUTOFS_DEV_IOCTL_CATATONIC_CMD),
703 autofs_dev_ioctl_catatonic},
704 {cmd_idx(AUTOFS_DEV_IOCTL_TIMEOUT_CMD),
705 autofs_dev_ioctl_timeout},
706 {cmd_idx(AUTOFS_DEV_IOCTL_REQUESTER_CMD),
707 autofs_dev_ioctl_requester},
708 {cmd_idx(AUTOFS_DEV_IOCTL_EXPIRE_CMD),
709 autofs_dev_ioctl_expire},
710 {cmd_idx(AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD),
711 autofs_dev_ioctl_askumount},
712 {cmd_idx(AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD),
713 autofs_dev_ioctl_ismountpoint}
714 };
715 unsigned int idx = cmd_idx(cmd);
716
717 return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx].fn;
718}
719
720/* ioctl dispatcher */
721static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __user *user)
722{
723 struct autofs_dev_ioctl *param;
724 struct file *fp;
725 struct autofs_sb_info *sbi;
726 unsigned int cmd_first, cmd;
727 ioctl_fn fn = NULL;
728 int err = 0;
729
730 /* only root can play with this */
731 if (!capable(CAP_SYS_ADMIN))
732 return -EPERM;
733
734 cmd_first = _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST);
735 cmd = _IOC_NR(command);
736
737 if (_IOC_TYPE(command) != _IOC_TYPE(AUTOFS_DEV_IOCTL_IOC_FIRST) ||
738 cmd - cmd_first >= AUTOFS_DEV_IOCTL_IOC_COUNT) {
739 return -ENOTTY;
740 }
741
742 /* Copy the parameters into kernel space. */
743 param = copy_dev_ioctl(user);
744 if (IS_ERR(param))
745 return PTR_ERR(param);
746
747 err = validate_dev_ioctl(command, param);
748 if (err)
749 goto out;
750
751 /* The validate routine above always sets the version */
752 if (cmd == AUTOFS_DEV_IOCTL_VERSION_CMD)
753 goto done;
754
755 fn = lookup_dev_ioctl(cmd);
756 if (!fn) {
757 AUTOFS_WARN("unknown command 0x%08x", command);
758 return -ENOTTY;
759 }
760
761 fp = NULL;
762 sbi = NULL;
763
764 /*
765 * For obvious reasons the openmount can't have a file
766 * descriptor yet. We don't take a reference to the
767 * file during close to allow for immediate release.
768 */
769 if (cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
770 cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
771 fp = fget(param->ioctlfd);
772 if (!fp) {
773 if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
774 goto cont;
775 err = -EBADF;
776 goto out;
777 }
778
779 if (!fp->f_op) {
780 err = -ENOTTY;
781 fput(fp);
782 goto out;
783 }
784
785 sbi = autofs_dev_ioctl_sbi(fp);
786 if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
787 err = -EINVAL;
788 fput(fp);
789 goto out;
790 }
791
792 /*
793 * Admin needs to be able to set the mount catatonic in
794 * order to be able to perform the re-open.
795 */
796 if (!autofs4_oz_mode(sbi) &&
797 cmd != AUTOFS_DEV_IOCTL_CATATONIC_CMD) {
798 err = -EACCES;
799 fput(fp);
800 goto out;
801 }
802 }
803cont:
804 err = fn(fp, sbi, param);
805
806 if (fp)
807 fput(fp);
808done:
809 if (err >= 0 && copy_to_user(user, param, AUTOFS_DEV_IOCTL_SIZE))
810 err = -EFAULT;
811out:
812 free_dev_ioctl(param);
813 return err;
814}
815
816static long autofs_dev_ioctl(struct file *file, uint command, ulong u)
817{
818 int err;
819 err = _autofs_dev_ioctl(command, (struct autofs_dev_ioctl __user *) u);
820 return (long) err;
821}
822
823#ifdef CONFIG_COMPAT
824static long autofs_dev_ioctl_compat(struct file *file, uint command, ulong u)
825{
826 return (long) autofs_dev_ioctl(file, command, (ulong) compat_ptr(u));
827}
828#else
829#define autofs_dev_ioctl_compat NULL
830#endif
831
832static const struct file_operations _dev_ioctl_fops = {
833 .unlocked_ioctl = autofs_dev_ioctl,
834 .compat_ioctl = autofs_dev_ioctl_compat,
835 .owner = THIS_MODULE,
836};
837
838static struct miscdevice _autofs_dev_ioctl_misc = {
839 .minor = MISC_DYNAMIC_MINOR,
840 .name = AUTOFS_DEVICE_NAME,
841 .fops = &_dev_ioctl_fops
842};
843
844/* Register/deregister misc character device */
845int autofs_dev_ioctl_init(void)
846{
847 int r;
848
849 r = misc_register(&_autofs_dev_ioctl_misc);
850 if (r) {
851 AUTOFS_ERROR("misc_register failed for control device");
852 return r;
853 }
854
855 return 0;
856}
857
858void autofs_dev_ioctl_exit(void)
859{
860 misc_deregister(&_autofs_dev_ioctl_misc);
861 return;
862}
863
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
index cdabb796ff01..cde2f8e8935a 100644
--- a/fs/autofs4/expire.c
+++ b/fs/autofs4/expire.c
@@ -244,10 +244,10 @@ cont:
244} 244}
245 245
246/* Check if we can expire a direct mount (possibly a tree) */ 246/* Check if we can expire a direct mount (possibly a tree) */
247static struct dentry *autofs4_expire_direct(struct super_block *sb, 247struct dentry *autofs4_expire_direct(struct super_block *sb,
248 struct vfsmount *mnt, 248 struct vfsmount *mnt,
249 struct autofs_sb_info *sbi, 249 struct autofs_sb_info *sbi,
250 int how) 250 int how)
251{ 251{
252 unsigned long timeout; 252 unsigned long timeout;
253 struct dentry *root = dget(sb->s_root); 253 struct dentry *root = dget(sb->s_root);
@@ -283,10 +283,10 @@ static struct dentry *autofs4_expire_direct(struct super_block *sb,
283 * - it is unused by any user process 283 * - it is unused by any user process
284 * - it has been unused for exp_timeout time 284 * - it has been unused for exp_timeout time
285 */ 285 */
286static struct dentry *autofs4_expire_indirect(struct super_block *sb, 286struct dentry *autofs4_expire_indirect(struct super_block *sb,
287 struct vfsmount *mnt, 287 struct vfsmount *mnt,
288 struct autofs_sb_info *sbi, 288 struct autofs_sb_info *sbi,
289 int how) 289 int how)
290{ 290{
291 unsigned long timeout; 291 unsigned long timeout;
292 struct dentry *root = sb->s_root; 292 struct dentry *root = sb->s_root;
@@ -479,7 +479,7 @@ int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,
479 if (arg && get_user(do_now, arg)) 479 if (arg && get_user(do_now, arg))
480 return -EFAULT; 480 return -EFAULT;
481 481
482 if (sbi->type & AUTOFS_TYPE_DIRECT) 482 if (sbi->type & AUTOFS_TYPE_TRIGGER)
483 dentry = autofs4_expire_direct(sb, mnt, sbi, do_now); 483 dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
484 else 484 else
485 dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now); 485 dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
diff --git a/fs/autofs4/init.c b/fs/autofs4/init.c
index 723a1c5e361b..9722e4bd8957 100644
--- a/fs/autofs4/init.c
+++ b/fs/autofs4/init.c
@@ -29,11 +29,20 @@ static struct file_system_type autofs_fs_type = {
29 29
30static int __init init_autofs4_fs(void) 30static int __init init_autofs4_fs(void)
31{ 31{
32 return register_filesystem(&autofs_fs_type); 32 int err;
33
34 err = register_filesystem(&autofs_fs_type);
35 if (err)
36 return err;
37
38 autofs_dev_ioctl_init();
39
40 return err;
33} 41}
34 42
35static void __exit exit_autofs4_fs(void) 43static void __exit exit_autofs4_fs(void)
36{ 44{
45 autofs_dev_ioctl_exit();
37 unregister_filesystem(&autofs_fs_type); 46 unregister_filesystem(&autofs_fs_type);
38} 47}
39 48
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 45d55819203d..c7e65bb30ba0 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -53,6 +53,8 @@ struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
53 atomic_set(&ino->count, 0); 53 atomic_set(&ino->count, 0);
54 } 54 }
55 55
56 ino->uid = 0;
57 ino->gid = 0;
56 ino->mode = mode; 58 ino->mode = mode;
57 ino->last_used = jiffies; 59 ino->last_used = jiffies;
58 60
@@ -288,7 +290,7 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
288 *type = AUTOFS_TYPE_DIRECT; 290 *type = AUTOFS_TYPE_DIRECT;
289 break; 291 break;
290 case Opt_offset: 292 case Opt_offset:
291 *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET; 293 *type = AUTOFS_TYPE_OFFSET;
292 break; 294 break;
293 default: 295 default:
294 return 1; 296 return 1;
@@ -336,7 +338,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
336 sbi->sb = s; 338 sbi->sb = s;
337 sbi->version = 0; 339 sbi->version = 0;
338 sbi->sub_version = 0; 340 sbi->sub_version = 0;
339 sbi->type = 0; 341 sbi->type = AUTOFS_TYPE_INDIRECT;
340 sbi->min_proto = 0; 342 sbi->min_proto = 0;
341 sbi->max_proto = 0; 343 sbi->max_proto = 0;
342 mutex_init(&sbi->wq_mutex); 344 mutex_init(&sbi->wq_mutex);
@@ -378,7 +380,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
378 } 380 }
379 381
380 root_inode->i_fop = &autofs4_root_operations; 382 root_inode->i_fop = &autofs4_root_operations;
381 root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ? 383 root_inode->i_op = sbi->type & AUTOFS_TYPE_TRIGGER ?
382 &autofs4_direct_root_inode_operations : 384 &autofs4_direct_root_inode_operations :
383 &autofs4_indirect_root_inode_operations; 385 &autofs4_indirect_root_inode_operations;
384 386
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 35216d18d8b5..4b67c2a2d77c 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -337,7 +337,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
337 * is very similar for indirect mounts except only dentrys 337 * is very similar for indirect mounts except only dentrys
338 * in the root of the autofs file system may be negative. 338 * in the root of the autofs file system may be negative.
339 */ 339 */
340 if (sbi->type & (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)) 340 if (sbi->type & AUTOFS_TYPE_TRIGGER)
341 return -ENOENT; 341 return -ENOENT;
342 else if (!IS_ROOT(dentry->d_parent)) 342 else if (!IS_ROOT(dentry->d_parent))
343 return -ENOENT; 343 return -ENOENT;
@@ -348,7 +348,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
348 return -ENOMEM; 348 return -ENOMEM;
349 349
350 /* If this is a direct mount request create a dummy name */ 350 /* If this is a direct mount request create a dummy name */
351 if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT)) 351 if (IS_ROOT(dentry) && sbi->type & AUTOFS_TYPE_TRIGGER)
352 qstr.len = sprintf(name, "%p", dentry); 352 qstr.len = sprintf(name, "%p", dentry);
353 else { 353 else {
354 qstr.len = autofs4_getpath(sbi, dentry, &name); 354 qstr.len = autofs4_getpath(sbi, dentry, &name);
@@ -406,11 +406,11 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
406 type = autofs_ptype_expire_multi; 406 type = autofs_ptype_expire_multi;
407 } else { 407 } else {
408 if (notify == NFY_MOUNT) 408 if (notify == NFY_MOUNT)
409 type = (sbi->type & AUTOFS_TYPE_DIRECT) ? 409 type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
410 autofs_ptype_missing_direct : 410 autofs_ptype_missing_direct :
411 autofs_ptype_missing_indirect; 411 autofs_ptype_missing_indirect;
412 else 412 else
413 type = (sbi->type & AUTOFS_TYPE_DIRECT) ? 413 type = (sbi->type & AUTOFS_TYPE_TRIGGER) ?
414 autofs_ptype_expire_direct : 414 autofs_ptype_expire_direct :
415 autofs_ptype_expire_indirect; 415 autofs_ptype_expire_indirect;
416 } 416 }
@@ -457,6 +457,40 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
457 457
458 status = wq->status; 458 status = wq->status;
459 459
460 /*
461 * For direct and offset mounts we need to track the requester's
462 * uid and gid in the dentry info struct. This is so it can be
463 * supplied, on request, by the misc device ioctl interface.
464 * This is needed during daemon resatart when reconnecting
465 * to existing, active, autofs mounts. The uid and gid (and
466 * related string values) may be used for macro substitution
467 * in autofs mount maps.
468 */
469 if (!status) {
470 struct autofs_info *ino;
471 struct dentry *de = NULL;
472
473 /* direct mount or browsable map */
474 ino = autofs4_dentry_ino(dentry);
475 if (!ino) {
476 /* If not lookup actual dentry used */
477 de = d_lookup(dentry->d_parent, &dentry->d_name);
478 if (de)
479 ino = autofs4_dentry_ino(de);
480 }
481
482 /* Set mount requester */
483 if (ino) {
484 spin_lock(&sbi->fs_lock);
485 ino->uid = wq->uid;
486 ino->gid = wq->gid;
487 spin_unlock(&sbi->fs_lock);
488 }
489
490 if (de)
491 dput(de);
492 }
493
460 /* Are we the last process to need status? */ 494 /* Are we the last process to need status? */
461 mutex_lock(&sbi->wq_mutex); 495 mutex_lock(&sbi->wq_mutex);
462 if (!--wq->wait_ctr) 496 if (!--wq->wait_ctr)
diff --git a/fs/befs/befs_fs_types.h b/fs/befs/befs_fs_types.h
index e2595c2c403a..7893eaa1e58c 100644
--- a/fs/befs/befs_fs_types.h
+++ b/fs/befs/befs_fs_types.h
@@ -55,8 +55,12 @@ enum super_flags {
55}; 55};
56 56
57#define BEFS_BYTEORDER_NATIVE 0x42494745 57#define BEFS_BYTEORDER_NATIVE 0x42494745
58#define BEFS_BYTEORDER_NATIVE_LE (__force fs32)cpu_to_le32(BEFS_BYTEORDER_NATIVE)
59#define BEFS_BYTEORDER_NATIVE_BE (__force fs32)cpu_to_be32(BEFS_BYTEORDER_NATIVE)
58 60
59#define BEFS_SUPER_MAGIC BEFS_SUPER_MAGIC1 61#define BEFS_SUPER_MAGIC BEFS_SUPER_MAGIC1
62#define BEFS_SUPER_MAGIC1_LE (__force fs32)cpu_to_le32(BEFS_SUPER_MAGIC1)
63#define BEFS_SUPER_MAGIC1_BE (__force fs32)cpu_to_be32(BEFS_SUPER_MAGIC1)
60 64
61/* 65/*
62 * Flags of inode 66 * Flags of inode
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 9286b2af893a..b6dfee37c7b7 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -809,8 +809,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
809 809
810 /* account for offset of super block on x86 */ 810 /* account for offset of super block on x86 */
811 disk_sb = (befs_super_block *) bh->b_data; 811 disk_sb = (befs_super_block *) bh->b_data;
812 if ((le32_to_cpu(disk_sb->magic1) == BEFS_SUPER_MAGIC1) || 812 if ((disk_sb->magic1 == BEFS_SUPER_MAGIC1_LE) ||
813 (be32_to_cpu(disk_sb->magic1) == BEFS_SUPER_MAGIC1)) { 813 (disk_sb->magic1 == BEFS_SUPER_MAGIC1_BE)) {
814 befs_debug(sb, "Using PPC superblock location"); 814 befs_debug(sb, "Using PPC superblock location");
815 } else { 815 } else {
816 befs_debug(sb, "Using x86 superblock location"); 816 befs_debug(sb, "Using x86 superblock location");
diff --git a/fs/befs/super.c b/fs/befs/super.c
index 8c3401ff6d6a..41f2b4d0093e 100644
--- a/fs/befs/super.c
+++ b/fs/befs/super.c
@@ -26,10 +26,10 @@ befs_load_sb(struct super_block *sb, befs_super_block * disk_sb)
26 befs_sb_info *befs_sb = BEFS_SB(sb); 26 befs_sb_info *befs_sb = BEFS_SB(sb);
27 27
28 /* Check the byte order of the filesystem */ 28 /* Check the byte order of the filesystem */
29 if (le32_to_cpu(disk_sb->fs_byte_order) == BEFS_BYTEORDER_NATIVE) 29 if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_LE)
30 befs_sb->byte_order = BEFS_BYTESEX_LE; 30 befs_sb->byte_order = BEFS_BYTESEX_LE;
31 else if (be32_to_cpu(disk_sb->fs_byte_order) == BEFS_BYTEORDER_NATIVE) 31 else if (disk_sb->fs_byte_order == BEFS_BYTEORDER_NATIVE_BE)
32 befs_sb->byte_order = BEFS_BYTESEX_BE; 32 befs_sb->byte_order = BEFS_BYTESEX_BE;
33 33
34 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1); 34 befs_sb->magic1 = fs32_to_cpu(sb, disk_sb->magic1);
35 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2); 35 befs_sb->magic2 = fs32_to_cpu(sb, disk_sb->magic2);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 655ed8d30a86..c76afa26edf7 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -683,7 +683,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
683 * switch really is going to happen - do this in 683 * switch really is going to happen - do this in
684 * flush_thread(). - akpm 684 * flush_thread(). - akpm
685 */ 685 */
686 SET_PERSONALITY(loc->elf_ex, 0); 686 SET_PERSONALITY(loc->elf_ex);
687 687
688 interpreter = open_exec(elf_interpreter); 688 interpreter = open_exec(elf_interpreter);
689 retval = PTR_ERR(interpreter); 689 retval = PTR_ERR(interpreter);
@@ -734,7 +734,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
734 goto out_free_dentry; 734 goto out_free_dentry;
735 } else { 735 } else {
736 /* Executables without an interpreter also need a personality */ 736 /* Executables without an interpreter also need a personality */
737 SET_PERSONALITY(loc->elf_ex, 0); 737 SET_PERSONALITY(loc->elf_ex);
738 } 738 }
739 739
740 /* Flush all traces of the currently running executable */ 740 /* Flush all traces of the currently running executable */
@@ -748,7 +748,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
748 748
749 /* Do this immediately, since STACK_TOP as used in setup_arg_pages 749 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
750 may depend on the personality. */ 750 may depend on the personality. */
751 SET_PERSONALITY(loc->elf_ex, 0); 751 SET_PERSONALITY(loc->elf_ex);
752 if (elf_read_implies_exec(loc->elf_ex, executable_stack)) 752 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
753 current->personality |= READ_IMPLIES_EXEC; 753 current->personality |= READ_IMPLIES_EXEC;
754 754
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 80c1f952ef78..0e8367c54624 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -25,6 +25,7 @@
25#include <linux/fcntl.h> 25#include <linux/fcntl.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/pagemap.h> 27#include <linux/pagemap.h>
28#include <linux/security.h>
28#include <linux/highmem.h> 29#include <linux/highmem.h>
29#include <linux/highuid.h> 30#include <linux/highuid.h>
30#include <linux/personality.h> 31#include <linux/personality.h>
@@ -455,8 +456,19 @@ error_kill:
455} 456}
456 457
457/*****************************************************************************/ 458/*****************************************************************************/
459
460#ifndef ELF_BASE_PLATFORM
458/* 461/*
459 * present useful information to the program 462 * AT_BASE_PLATFORM indicates the "real" hardware/microarchitecture.
463 * If the arch defines ELF_BASE_PLATFORM (in asm/elf.h), the value
464 * will be copied to the user stack in the same manner as AT_PLATFORM.
465 */
466#define ELF_BASE_PLATFORM NULL
467#endif
468
469/*
470 * present useful information to the program by shovelling it onto the new
471 * process's stack
460 */ 472 */
461static int create_elf_fdpic_tables(struct linux_binprm *bprm, 473static int create_elf_fdpic_tables(struct linux_binprm *bprm,
462 struct mm_struct *mm, 474 struct mm_struct *mm,
@@ -466,15 +478,19 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
466 unsigned long sp, csp, nitems; 478 unsigned long sp, csp, nitems;
467 elf_caddr_t __user *argv, *envp; 479 elf_caddr_t __user *argv, *envp;
468 size_t platform_len = 0, len; 480 size_t platform_len = 0, len;
469 char *k_platform; 481 char *k_platform, *k_base_platform;
470 char __user *u_platform, *p; 482 char __user *u_platform, *u_base_platform, *p;
471 long hwcap; 483 long hwcap;
472 int loop; 484 int loop;
473 int nr; /* reset for each csp adjustment */ 485 int nr; /* reset for each csp adjustment */
474 486
475 /* we're going to shovel a whole load of stuff onto the stack */
476#ifdef CONFIG_MMU 487#ifdef CONFIG_MMU
477 sp = bprm->p; 488 /* In some cases (e.g. Hyper-Threading), we want to avoid L1 evictions
489 * by the processes running on the same package. One thing we can do is
490 * to shuffle the initial stack for them, so we give the architecture
491 * an opportunity to do so here.
492 */
493 sp = arch_align_stack(bprm->p);
478#else 494#else
479 sp = mm->start_stack; 495 sp = mm->start_stack;
480 496
@@ -483,11 +499,14 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
483 return -EFAULT; 499 return -EFAULT;
484#endif 500#endif
485 501
486 /* get hold of platform and hardware capabilities masks for the machine
487 * we are running on. In some cases (Sparc), this info is impossible
488 * to get, in others (i386) it is merely difficult.
489 */
490 hwcap = ELF_HWCAP; 502 hwcap = ELF_HWCAP;
503
504 /*
505 * If this architecture has a platform capability string, copy it
506 * to userspace. In some cases (Sparc), this info is impossible
507 * for userspace to get any other way, in others (i386) it is
508 * merely difficult.
509 */
491 k_platform = ELF_PLATFORM; 510 k_platform = ELF_PLATFORM;
492 u_platform = NULL; 511 u_platform = NULL;
493 512
@@ -499,19 +518,20 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
499 return -EFAULT; 518 return -EFAULT;
500 } 519 }
501 520
502#if defined(__i386__) && defined(CONFIG_SMP) 521 /*
503 /* in some cases (e.g. Hyper-Threading), we want to avoid L1 evictions 522 * If this architecture has a "base" platform capability
504 * by the processes running on the same package. One thing we can do is 523 * string, copy it to userspace.
505 * to shuffle the initial stack for them.
506 *
507 * the conditionals here are unneeded, but kept in to make the code
508 * behaviour the same as pre change unless we have hyperthreaded
509 * processors. This keeps Mr Marcelo Person happier but should be
510 * removed for 2.5
511 */ 524 */
512 if (smp_num_siblings > 1) 525 k_base_platform = ELF_BASE_PLATFORM;
513 sp = sp - ((current->pid % 64) << 7); 526 u_base_platform = NULL;
514#endif 527
528 if (k_base_platform) {
529 platform_len = strlen(k_base_platform) + 1;
530 sp -= platform_len;
531 u_base_platform = (char __user *) sp;
532 if (__copy_to_user(u_base_platform, k_base_platform, platform_len) != 0)
533 return -EFAULT;
534 }
515 535
516 sp &= ~7UL; 536 sp &= ~7UL;
517 537
@@ -541,9 +561,13 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
541 } 561 }
542 562
543 /* force 16 byte _final_ alignment here for generality */ 563 /* force 16 byte _final_ alignment here for generality */
544#define DLINFO_ITEMS 13 564#define DLINFO_ITEMS 15
565
566 nitems = 1 + DLINFO_ITEMS + (k_platform ? 1 : 0) +
567 (k_base_platform ? 1 : 0) + AT_VECTOR_SIZE_ARCH;
545 568
546 nitems = 1 + DLINFO_ITEMS + (k_platform ? 1 : 0) + AT_VECTOR_SIZE_ARCH; 569 if (bprm->interp_flags & BINPRM_FLAGS_EXECFD)
570 nitems++;
547 571
548 csp = sp; 572 csp = sp;
549 sp -= nitems * 2 * sizeof(unsigned long); 573 sp -= nitems * 2 * sizeof(unsigned long);
@@ -575,6 +599,19 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
575 (elf_addr_t) (unsigned long) u_platform); 599 (elf_addr_t) (unsigned long) u_platform);
576 } 600 }
577 601
602 if (k_base_platform) {
603 nr = 0;
604 csp -= 2 * sizeof(unsigned long);
605 NEW_AUX_ENT(AT_BASE_PLATFORM,
606 (elf_addr_t) (unsigned long) u_base_platform);
607 }
608
609 if (bprm->interp_flags & BINPRM_FLAGS_EXECFD) {
610 nr = 0;
611 csp -= 2 * sizeof(unsigned long);
612 NEW_AUX_ENT(AT_EXECFD, bprm->interp_data);
613 }
614
578 nr = 0; 615 nr = 0;
579 csp -= DLINFO_ITEMS * 2 * sizeof(unsigned long); 616 csp -= DLINFO_ITEMS * 2 * sizeof(unsigned long);
580 NEW_AUX_ENT(AT_HWCAP, hwcap); 617 NEW_AUX_ENT(AT_HWCAP, hwcap);
@@ -590,6 +627,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
590 NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid); 627 NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid);
591 NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid); 628 NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid);
592 NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid); 629 NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid);
630 NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
631 NEW_AUX_ENT(AT_EXECFN, bprm->exec);
593 632
594#ifdef ARCH_DLINFO 633#ifdef ARCH_DLINFO
595 nr = 0; 634 nr = 0;
diff --git a/fs/binfmt_em86.c b/fs/binfmt_em86.c
index f9c88d0c8ced..32fb00b52cd0 100644
--- a/fs/binfmt_em86.c
+++ b/fs/binfmt_em86.c
@@ -43,7 +43,7 @@ static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
43 return -ENOEXEC; 43 return -ENOEXEC;
44 } 44 }
45 45
46 bprm->sh_bang = 1; /* Well, the bang-shell is implicit... */ 46 bprm->recursion_depth++; /* Well, the bang-shell is implicit... */
47 allow_write_access(bprm->file); 47 allow_write_access(bprm->file);
48 fput(bprm->file); 48 fput(bprm->file);
49 bprm->file = NULL; 49 bprm->file = NULL;
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index dfc0197905ca..ccb781a6a804 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -229,13 +229,13 @@ static int decompress_exec(
229 ret = 10; 229 ret = 10;
230 if (buf[3] & EXTRA_FIELD) { 230 if (buf[3] & EXTRA_FIELD) {
231 ret += 2 + buf[10] + (buf[11] << 8); 231 ret += 2 + buf[10] + (buf[11] << 8);
232 if (unlikely(LBUFSIZE == ret)) { 232 if (unlikely(LBUFSIZE <= ret)) {
233 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); 233 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n");
234 goto out_free_buf; 234 goto out_free_buf;
235 } 235 }
236 } 236 }
237 if (buf[3] & ORIG_NAME) { 237 if (buf[3] & ORIG_NAME) {
238 for (; ret < LBUFSIZE && (buf[ret] != 0); ret++) 238 while (ret < LBUFSIZE && buf[ret++] != 0)
239 ; 239 ;
240 if (unlikely(LBUFSIZE == ret)) { 240 if (unlikely(LBUFSIZE == ret)) {
241 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); 241 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n");
@@ -243,7 +243,7 @@ static int decompress_exec(
243 } 243 }
244 } 244 }
245 if (buf[3] & COMMENT) { 245 if (buf[3] & COMMENT) {
246 for (; ret < LBUFSIZE && (buf[ret] != 0); ret++) 246 while (ret < LBUFSIZE && buf[ret++] != 0)
247 ; 247 ;
248 if (unlikely(LBUFSIZE == ret)) { 248 if (unlikely(LBUFSIZE == ret)) {
249 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); 249 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n");
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 8d7e88e02e0f..f2744ab4e5b3 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -117,7 +117,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
117 goto _ret; 117 goto _ret;
118 118
119 retval = -ENOEXEC; 119 retval = -ENOEXEC;
120 if (bprm->misc_bang) 120 if (bprm->recursion_depth > BINPRM_MAX_RECURSION)
121 goto _ret; 121 goto _ret;
122 122
123 /* to keep locking time low, we copy the interpreter string */ 123 /* to keep locking time low, we copy the interpreter string */
@@ -197,7 +197,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs)
197 if (retval < 0) 197 if (retval < 0)
198 goto _error; 198 goto _error;
199 199
200 bprm->misc_bang = 1; 200 bprm->recursion_depth++;
201 201
202 retval = search_binary_handler (bprm, regs); 202 retval = search_binary_handler (bprm, regs);
203 if (retval < 0) 203 if (retval < 0)
diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c
index 9e3963f7ebf1..08343505e184 100644
--- a/fs/binfmt_script.c
+++ b/fs/binfmt_script.c
@@ -22,14 +22,15 @@ static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
22 char interp[BINPRM_BUF_SIZE]; 22 char interp[BINPRM_BUF_SIZE];
23 int retval; 23 int retval;
24 24
25 if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') || (bprm->sh_bang)) 25 if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') ||
26 (bprm->recursion_depth > BINPRM_MAX_RECURSION))
26 return -ENOEXEC; 27 return -ENOEXEC;
27 /* 28 /*
28 * This section does the #! interpretation. 29 * This section does the #! interpretation.
29 * Sorta complicated, but hopefully it will work. -TYT 30 * Sorta complicated, but hopefully it will work. -TYT
30 */ 31 */
31 32
32 bprm->sh_bang = 1; 33 bprm->recursion_depth++;
33 allow_write_access(bprm->file); 34 allow_write_access(bprm->file);
34 fput(bprm->file); 35 fput(bprm->file);
35 bprm->file = NULL; 36 bprm->file = NULL;
diff --git a/fs/binfmt_som.c b/fs/binfmt_som.c
index 68be580ba289..74e587a52796 100644
--- a/fs/binfmt_som.c
+++ b/fs/binfmt_som.c
@@ -306,3 +306,5 @@ static void __exit exit_som_binfmt(void)
306 306
307core_initcall(init_som_binfmt); 307core_initcall(init_som_binfmt);
308module_exit(exit_som_binfmt); 308module_exit(exit_som_binfmt);
309
310MODULE_LICENSE("GPL");
diff --git a/fs/compat.c b/fs/compat.c
index 075d0509970d..5f9ec449c799 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -137,6 +137,45 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
137 return compat_sys_futimesat(AT_FDCWD, filename, t); 137 return compat_sys_futimesat(AT_FDCWD, filename, t);
138} 138}
139 139
140static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
141{
142 compat_ino_t ino = stat->ino;
143 typeof(ubuf->st_uid) uid = 0;
144 typeof(ubuf->st_gid) gid = 0;
145 int err;
146
147 SET_UID(uid, stat->uid);
148 SET_GID(gid, stat->gid);
149
150 if ((u64) stat->size > MAX_NON_LFS ||
151 !old_valid_dev(stat->dev) ||
152 !old_valid_dev(stat->rdev))
153 return -EOVERFLOW;
154 if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
155 return -EOVERFLOW;
156
157 if (clear_user(ubuf, sizeof(*ubuf)))
158 return -EFAULT;
159
160 err = __put_user(old_encode_dev(stat->dev), &ubuf->st_dev);
161 err |= __put_user(ino, &ubuf->st_ino);
162 err |= __put_user(stat->mode, &ubuf->st_mode);
163 err |= __put_user(stat->nlink, &ubuf->st_nlink);
164 err |= __put_user(uid, &ubuf->st_uid);
165 err |= __put_user(gid, &ubuf->st_gid);
166 err |= __put_user(old_encode_dev(stat->rdev), &ubuf->st_rdev);
167 err |= __put_user(stat->size, &ubuf->st_size);
168 err |= __put_user(stat->atime.tv_sec, &ubuf->st_atime);
169 err |= __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec);
170 err |= __put_user(stat->mtime.tv_sec, &ubuf->st_mtime);
171 err |= __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec);
172 err |= __put_user(stat->ctime.tv_sec, &ubuf->st_ctime);
173 err |= __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec);
174 err |= __put_user(stat->blksize, &ubuf->st_blksize);
175 err |= __put_user(stat->blocks, &ubuf->st_blocks);
176 return err;
177}
178
140asmlinkage long compat_sys_newstat(char __user * filename, 179asmlinkage long compat_sys_newstat(char __user * filename,
141 struct compat_stat __user *statbuf) 180 struct compat_stat __user *statbuf)
142{ 181{
@@ -1239,7 +1278,7 @@ static int compat_count(compat_uptr_t __user *argv, int max)
1239 if (!p) 1278 if (!p)
1240 break; 1279 break;
1241 argv++; 1280 argv++;
1242 if(++i > max) 1281 if (i++ >= max)
1243 return -E2BIG; 1282 return -E2BIG;
1244 } 1283 }
1245 } 1284 }
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 9606ee848fd8..af0558dbe8b7 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -5,11 +5,11 @@
5 * 5 *
6 * O_DIRECT 6 * O_DIRECT
7 * 7 *
8 * 04Jul2002 akpm@zip.com.au 8 * 04Jul2002 Andrew Morton
9 * Initial version 9 * Initial version
10 * 11Sep2002 janetinc@us.ibm.com 10 * 11Sep2002 janetinc@us.ibm.com
11 * added readv/writev support. 11 * added readv/writev support.
12 * 29Oct2002 akpm@zip.com.au 12 * 29Oct2002 Andrew Morton
13 * rewrote bio_add_page() support. 13 * rewrote bio_add_page() support.
14 * 30Oct2002 pbadari@us.ibm.com 14 * 30Oct2002 pbadari@us.ibm.com
15 * added support for non-aligned IO. 15 * added support for non-aligned IO.
diff --git a/fs/dquot.c b/fs/dquot.c
index ad7e59003e04..da30a27f2242 100644
--- a/fs/dquot.c
+++ b/fs/dquot.c
@@ -9,8 +9,6 @@
9 * implementation is based on one of the several variants of the LINUX 9 * implementation is based on one of the several variants of the LINUX
10 * inode-subsystem with added complexity of the diskquota system. 10 * inode-subsystem with added complexity of the diskquota system.
11 * 11 *
12 * Version: $Id: dquot.c,v 6.3 1996/11/17 18:35:34 mvw Exp mvw $
13 *
14 * Author: Marco van Wieringen <mvw@planets.elm.net> 12 * Author: Marco van Wieringen <mvw@planets.elm.net>
15 * 13 *
16 * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96 14 * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96
diff --git a/fs/ecryptfs/Makefile b/fs/ecryptfs/Makefile
index b4755a85996e..2cc9ee4ad2eb 100644
--- a/fs/ecryptfs/Makefile
+++ b/fs/ecryptfs/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-$(CONFIG_ECRYPT_FS) += ecryptfs.o 5obj-$(CONFIG_ECRYPT_FS) += ecryptfs.o
6 6
7ecryptfs-objs := dentry.o file.o inode.o main.o super.o mmap.o read_write.o crypto.o keystore.o messaging.o netlink.o miscdev.o kthread.o debug.o 7ecryptfs-objs := dentry.o file.o inode.o main.o super.o mmap.o read_write.o crypto.o keystore.o messaging.o miscdev.o kthread.o debug.o
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index b73fb752c5f8..3504cf9df358 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -79,11 +79,6 @@
79#define ECRYPTFS_MAX_PKI_NAME_BYTES 16 79#define ECRYPTFS_MAX_PKI_NAME_BYTES 16
80#define ECRYPTFS_DEFAULT_NUM_USERS 4 80#define ECRYPTFS_DEFAULT_NUM_USERS 4
81#define ECRYPTFS_MAX_NUM_USERS 32768 81#define ECRYPTFS_MAX_NUM_USERS 32768
82#define ECRYPTFS_TRANSPORT_NETLINK 0
83#define ECRYPTFS_TRANSPORT_CONNECTOR 1
84#define ECRYPTFS_TRANSPORT_RELAYFS 2
85#define ECRYPTFS_TRANSPORT_MISCDEV 3
86#define ECRYPTFS_DEFAULT_TRANSPORT ECRYPTFS_TRANSPORT_MISCDEV
87#define ECRYPTFS_XATTR_NAME "user.ecryptfs" 82#define ECRYPTFS_XATTR_NAME "user.ecryptfs"
88 83
89#define RFC2440_CIPHER_DES3_EDE 0x02 84#define RFC2440_CIPHER_DES3_EDE 0x02
@@ -400,8 +395,6 @@ struct ecryptfs_msg_ctx {
400 struct mutex mux; 395 struct mutex mux;
401}; 396};
402 397
403extern unsigned int ecryptfs_transport;
404
405struct ecryptfs_daemon; 398struct ecryptfs_daemon;
406 399
407struct ecryptfs_daemon { 400struct ecryptfs_daemon {
@@ -627,31 +620,20 @@ int
627ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value, 620ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
628 size_t size, int flags); 621 size_t size, int flags);
629int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode); 622int ecryptfs_read_xattr_region(char *page_virt, struct inode *ecryptfs_inode);
630int ecryptfs_process_helo(unsigned int transport, uid_t euid, 623int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns,
631 struct user_namespace *user_ns, struct pid *pid); 624 struct pid *pid);
632int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns, 625int ecryptfs_process_quit(uid_t euid, struct user_namespace *user_ns,
633 struct pid *pid); 626 struct pid *pid);
634int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid, 627int ecryptfs_process_response(struct ecryptfs_message *msg, uid_t euid,
635 struct user_namespace *user_ns, struct pid *pid, 628 struct user_namespace *user_ns, struct pid *pid,
636 u32 seq); 629 u32 seq);
637int ecryptfs_send_message(unsigned int transport, char *data, int data_len, 630int ecryptfs_send_message(char *data, int data_len,
638 struct ecryptfs_msg_ctx **msg_ctx); 631 struct ecryptfs_msg_ctx **msg_ctx);
639int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx, 632int ecryptfs_wait_for_response(struct ecryptfs_msg_ctx *msg_ctx,
640 struct ecryptfs_message **emsg); 633 struct ecryptfs_message **emsg);
641int ecryptfs_init_messaging(unsigned int transport); 634int ecryptfs_init_messaging(void);
642void ecryptfs_release_messaging(unsigned int transport); 635void ecryptfs_release_messaging(void);
643 636
644int ecryptfs_send_netlink(char *data, int data_len,
645 struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
646 u16 msg_flags, struct pid *daemon_pid);
647int ecryptfs_init_netlink(void);
648void ecryptfs_release_netlink(void);
649
650int ecryptfs_send_connector(char *data, int data_len,
651 struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
652 u16 msg_flags, struct pid *daemon_pid);
653int ecryptfs_init_connector(void);
654void ecryptfs_release_connector(void);
655void 637void
656ecryptfs_write_header_metadata(char *virt, 638ecryptfs_write_header_metadata(char *virt,
657 struct ecryptfs_crypt_stat *crypt_stat, 639 struct ecryptfs_crypt_stat *crypt_stat,
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 9244d653743e..eb3dc4c7ac06 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -71,12 +71,11 @@ struct ecryptfs_getdents_callback {
71 void *dirent; 71 void *dirent;
72 struct dentry *dentry; 72 struct dentry *dentry;
73 filldir_t filldir; 73 filldir_t filldir;
74 int err;
75 int filldir_called; 74 int filldir_called;
76 int entries_written; 75 int entries_written;
77}; 76};
78 77
79/* Inspired by generic filldir in fs/readir.c */ 78/* Inspired by generic filldir in fs/readdir.c */
80static int 79static int
81ecryptfs_filldir(void *dirent, const char *name, int namelen, loff_t offset, 80ecryptfs_filldir(void *dirent, const char *name, int namelen, loff_t offset,
82 u64 ino, unsigned int d_type) 81 u64 ino, unsigned int d_type)
@@ -125,18 +124,18 @@ static int ecryptfs_readdir(struct file *file, void *dirent, filldir_t filldir)
125 buf.dirent = dirent; 124 buf.dirent = dirent;
126 buf.dentry = file->f_path.dentry; 125 buf.dentry = file->f_path.dentry;
127 buf.filldir = filldir; 126 buf.filldir = filldir;
128retry:
129 buf.filldir_called = 0; 127 buf.filldir_called = 0;
130 buf.entries_written = 0; 128 buf.entries_written = 0;
131 buf.err = 0;
132 rc = vfs_readdir(lower_file, ecryptfs_filldir, (void *)&buf); 129 rc = vfs_readdir(lower_file, ecryptfs_filldir, (void *)&buf);
133 if (buf.err)
134 rc = buf.err;
135 if (buf.filldir_called && !buf.entries_written)
136 goto retry;
137 file->f_pos = lower_file->f_pos; 130 file->f_pos = lower_file->f_pos;
131 if (rc < 0)
132 goto out;
133 if (buf.filldir_called && !buf.entries_written)
134 goto out;
138 if (rc >= 0) 135 if (rc >= 0)
139 fsstack_copy_attr_atime(inode, lower_file->f_path.dentry->d_inode); 136 fsstack_copy_attr_atime(inode,
137 lower_file->f_path.dentry->d_inode);
138out:
140 return rc; 139 return rc;
141} 140}
142 141
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index f5b76a331b9c..e22bc3961345 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -234,8 +234,8 @@ parse_tag_65_packet(struct ecryptfs_session_key *session_key, u8 *cipher_code,
234 } 234 }
235 i += data_len; 235 i += data_len;
236 if (message_len < (i + m_size)) { 236 if (message_len < (i + m_size)) {
237 ecryptfs_printk(KERN_ERR, "The received netlink message is " 237 ecryptfs_printk(KERN_ERR, "The message received from ecryptfsd "
238 "shorter than expected\n"); 238 "is shorter than expected\n");
239 rc = -EIO; 239 rc = -EIO;
240 goto out; 240 goto out;
241 } 241 }
@@ -438,8 +438,8 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
438 struct ecryptfs_msg_ctx *msg_ctx; 438 struct ecryptfs_msg_ctx *msg_ctx;
439 struct ecryptfs_message *msg = NULL; 439 struct ecryptfs_message *msg = NULL;
440 char *auth_tok_sig; 440 char *auth_tok_sig;
441 char *netlink_message; 441 char *payload;
442 size_t netlink_message_length; 442 size_t payload_len;
443 int rc; 443 int rc;
444 444
445 rc = ecryptfs_get_auth_tok_sig(&auth_tok_sig, auth_tok); 445 rc = ecryptfs_get_auth_tok_sig(&auth_tok_sig, auth_tok);
@@ -449,15 +449,15 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
449 goto out; 449 goto out;
450 } 450 }
451 rc = write_tag_64_packet(auth_tok_sig, &(auth_tok->session_key), 451 rc = write_tag_64_packet(auth_tok_sig, &(auth_tok->session_key),
452 &netlink_message, &netlink_message_length); 452 &payload, &payload_len);
453 if (rc) { 453 if (rc) {
454 ecryptfs_printk(KERN_ERR, "Failed to write tag 64 packet\n"); 454 ecryptfs_printk(KERN_ERR, "Failed to write tag 64 packet\n");
455 goto out; 455 goto out;
456 } 456 }
457 rc = ecryptfs_send_message(ecryptfs_transport, netlink_message, 457 rc = ecryptfs_send_message(payload, payload_len, &msg_ctx);
458 netlink_message_length, &msg_ctx);
459 if (rc) { 458 if (rc) {
460 ecryptfs_printk(KERN_ERR, "Error sending netlink message\n"); 459 ecryptfs_printk(KERN_ERR, "Error sending message to "
460 "ecryptfsd\n");
461 goto out; 461 goto out;
462 } 462 }
463 rc = ecryptfs_wait_for_response(msg_ctx, &msg); 463 rc = ecryptfs_wait_for_response(msg_ctx, &msg);
@@ -1333,23 +1333,22 @@ pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
1333 struct ecryptfs_key_record *key_rec) 1333 struct ecryptfs_key_record *key_rec)
1334{ 1334{
1335 struct ecryptfs_msg_ctx *msg_ctx = NULL; 1335 struct ecryptfs_msg_ctx *msg_ctx = NULL;
1336 char *netlink_payload; 1336 char *payload = NULL;
1337 size_t netlink_payload_length; 1337 size_t payload_len;
1338 struct ecryptfs_message *msg; 1338 struct ecryptfs_message *msg;
1339 int rc; 1339 int rc;
1340 1340
1341 rc = write_tag_66_packet(auth_tok->token.private_key.signature, 1341 rc = write_tag_66_packet(auth_tok->token.private_key.signature,
1342 ecryptfs_code_for_cipher_string(crypt_stat), 1342 ecryptfs_code_for_cipher_string(crypt_stat),
1343 crypt_stat, &netlink_payload, 1343 crypt_stat, &payload, &payload_len);
1344 &netlink_payload_length);
1345 if (rc) { 1344 if (rc) {
1346 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n"); 1345 ecryptfs_printk(KERN_ERR, "Error generating tag 66 packet\n");
1347 goto out; 1346 goto out;
1348 } 1347 }
1349 rc = ecryptfs_send_message(ecryptfs_transport, netlink_payload, 1348 rc = ecryptfs_send_message(payload, payload_len, &msg_ctx);
1350 netlink_payload_length, &msg_ctx);
1351 if (rc) { 1349 if (rc) {
1352 ecryptfs_printk(KERN_ERR, "Error sending netlink message\n"); 1350 ecryptfs_printk(KERN_ERR, "Error sending message to "
1351 "ecryptfsd\n");
1353 goto out; 1352 goto out;
1354 } 1353 }
1355 rc = ecryptfs_wait_for_response(msg_ctx, &msg); 1354 rc = ecryptfs_wait_for_response(msg_ctx, &msg);
@@ -1364,8 +1363,7 @@ pki_encrypt_session_key(struct ecryptfs_auth_tok *auth_tok,
1364 ecryptfs_printk(KERN_ERR, "Error parsing tag 67 packet\n"); 1363 ecryptfs_printk(KERN_ERR, "Error parsing tag 67 packet\n");
1365 kfree(msg); 1364 kfree(msg);
1366out: 1365out:
1367 if (netlink_payload) 1366 kfree(payload);
1368 kfree(netlink_payload);
1369 return rc; 1367 return rc;
1370} 1368}
1371/** 1369/**
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 8ebe9a5d1d99..046e027a4cb1 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -30,7 +30,6 @@
30#include <linux/namei.h> 30#include <linux/namei.h>
31#include <linux/skbuff.h> 31#include <linux/skbuff.h>
32#include <linux/crypto.h> 32#include <linux/crypto.h>
33#include <linux/netlink.h>
34#include <linux/mount.h> 33#include <linux/mount.h>
35#include <linux/pagemap.h> 34#include <linux/pagemap.h>
36#include <linux/key.h> 35#include <linux/key.h>
@@ -49,8 +48,7 @@ MODULE_PARM_DESC(ecryptfs_verbosity,
49 "0, which is Quiet)"); 48 "0, which is Quiet)");
50 49
51/** 50/**
52 * Module parameter that defines the number of netlink message buffer 51 * Module parameter that defines the number of message buffer elements
53 * elements
54 */ 52 */
55unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS; 53unsigned int ecryptfs_message_buf_len = ECRYPTFS_DEFAULT_MSG_CTX_ELEMS;
56 54
@@ -60,9 +58,9 @@ MODULE_PARM_DESC(ecryptfs_message_buf_len,
60 58
61/** 59/**
62 * Module parameter that defines the maximum guaranteed amount of time to wait 60 * Module parameter that defines the maximum guaranteed amount of time to wait
63 * for a response through netlink. The actual sleep time will be, more than 61 * for a response from ecryptfsd. The actual sleep time will be, more than
64 * likely, a small amount greater than this specified value, but only less if 62 * likely, a small amount greater than this specified value, but only less if
65 * the netlink message successfully arrives. 63 * the message successfully arrives.
66 */ 64 */
67signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ; 65signed long ecryptfs_message_wait_timeout = ECRYPTFS_MAX_MSG_CTX_TTL / HZ;
68 66
@@ -83,8 +81,6 @@ module_param(ecryptfs_number_of_users, uint, 0);
83MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of " 81MODULE_PARM_DESC(ecryptfs_number_of_users, "An estimate of the number of "
84 "concurrent users of eCryptfs"); 82 "concurrent users of eCryptfs");
85 83
86unsigned int ecryptfs_transport = ECRYPTFS_DEFAULT_TRANSPORT;
87
88void __ecryptfs_printk(const char *fmt, ...) 84void __ecryptfs_printk(const char *fmt, ...)
89{ 85{
90 va_list args; 86 va_list args;
@@ -779,10 +775,11 @@ static int __init ecryptfs_init(void)
779 "rc = [%d]\n", __func__, rc); 775 "rc = [%d]\n", __func__, rc);
780 goto out_do_sysfs_unregistration; 776 goto out_do_sysfs_unregistration;
781 } 777 }
782 rc = ecryptfs_init_messaging(ecryptfs_transport); 778 rc = ecryptfs_init_messaging();
783 if (rc) { 779 if (rc) {
784 printk(KERN_ERR "Failure occured while attempting to " 780 printk(KERN_ERR "Failure occured while attempting to "
785 "initialize the eCryptfs netlink socket\n"); 781 "initialize the communications channel to "
782 "ecryptfsd\n");
786 goto out_destroy_kthread; 783 goto out_destroy_kthread;
787 } 784 }
788 rc = ecryptfs_init_crypto(); 785 rc = ecryptfs_init_crypto();
@@ -797,7 +794,7 @@ static int __init ecryptfs_init(void)
797 794
798 goto out; 795 goto out;
799out_release_messaging: 796out_release_messaging:
800 ecryptfs_release_messaging(ecryptfs_transport); 797 ecryptfs_release_messaging();
801out_destroy_kthread: 798out_destroy_kthread:
802 ecryptfs_destroy_kthread(); 799 ecryptfs_destroy_kthread();
803out_do_sysfs_unregistration: 800out_do_sysfs_unregistration:
@@ -818,7 +815,7 @@ static void __exit ecryptfs_exit(void)
818 if (rc) 815 if (rc)
819 printk(KERN_ERR "Failure whilst attempting to destroy crypto; " 816 printk(KERN_ERR "Failure whilst attempting to destroy crypto; "
820 "rc = [%d]\n", rc); 817 "rc = [%d]\n", rc);
821 ecryptfs_release_messaging(ecryptfs_transport); 818 ecryptfs_release_messaging();
822 ecryptfs_destroy_kthread(); 819 ecryptfs_destroy_kthread();
823 do_sysfs_unregistration(); 820 do_sysfs_unregistration();
824 unregister_filesystem(&ecryptfs_fs_type); 821 unregister_filesystem(&ecryptfs_fs_type);
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c
index 1b5c20058acb..c6983978a31e 100644
--- a/fs/ecryptfs/messaging.c
+++ b/fs/ecryptfs/messaging.c
@@ -134,12 +134,11 @@ out:
134} 134}
135 135
136static int 136static int
137ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, 137ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type,
138 u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx); 138 struct ecryptfs_msg_ctx **msg_ctx);
139 139
140/** 140/**
141 * ecryptfs_send_raw_message 141 * ecryptfs_send_raw_message
142 * @transport: Transport type
143 * @msg_type: Message type 142 * @msg_type: Message type
144 * @daemon: Daemon struct for recipient of message 143 * @daemon: Daemon struct for recipient of message
145 * 144 *
@@ -150,38 +149,25 @@ ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len,
150 * 149 *
151 * Returns zero on success; non-zero otherwise 150 * Returns zero on success; non-zero otherwise
152 */ 151 */
153static int ecryptfs_send_raw_message(unsigned int transport, u8 msg_type, 152static int ecryptfs_send_raw_message(u8 msg_type,
154 struct ecryptfs_daemon *daemon) 153 struct ecryptfs_daemon *daemon)
155{ 154{
156 struct ecryptfs_msg_ctx *msg_ctx; 155 struct ecryptfs_msg_ctx *msg_ctx;
157 int rc; 156 int rc;
158 157
159 switch(transport) { 158 rc = ecryptfs_send_message_locked(NULL, 0, msg_type, &msg_ctx);
160 case ECRYPTFS_TRANSPORT_NETLINK: 159 if (rc) {
161 rc = ecryptfs_send_netlink(NULL, 0, NULL, msg_type, 0, 160 printk(KERN_ERR "%s: Error whilst attempting to send "
162 daemon->pid); 161 "message to ecryptfsd; rc = [%d]\n", __func__, rc);
163 break; 162 goto out;
164 case ECRYPTFS_TRANSPORT_MISCDEV:
165 rc = ecryptfs_send_message_locked(transport, NULL, 0, msg_type,
166 &msg_ctx);
167 if (rc) {
168 printk(KERN_ERR "%s: Error whilst attempting to send "
169 "message via procfs; rc = [%d]\n", __func__, rc);
170 goto out;
171 }
172 /* Raw messages are logically context-free (e.g., no
173 * reply is expected), so we set the state of the
174 * ecryptfs_msg_ctx object to indicate that it should
175 * be freed as soon as the transport sends out the message. */
176 mutex_lock(&msg_ctx->mux);
177 msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_NO_REPLY;
178 mutex_unlock(&msg_ctx->mux);
179 break;
180 case ECRYPTFS_TRANSPORT_CONNECTOR:
181 case ECRYPTFS_TRANSPORT_RELAYFS:
182 default:
183 rc = -ENOSYS;
184 } 163 }
164 /* Raw messages are logically context-free (e.g., no
165 * reply is expected), so we set the state of the
166 * ecryptfs_msg_ctx object to indicate that it should
167 * be freed as soon as the message is sent. */
168 mutex_lock(&msg_ctx->mux);
169 msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_NO_REPLY;
170 mutex_unlock(&msg_ctx->mux);
185out: 171out:
186 return rc; 172 return rc;
187} 173}
@@ -227,7 +213,6 @@ out:
227 213
228/** 214/**
229 * ecryptfs_process_helo 215 * ecryptfs_process_helo
230 * @transport: The underlying transport (netlink, etc.)
231 * @euid: The user ID owner of the message 216 * @euid: The user ID owner of the message
232 * @user_ns: The namespace in which @euid applies 217 * @user_ns: The namespace in which @euid applies
233 * @pid: The process ID for the userspace program that sent the 218 * @pid: The process ID for the userspace program that sent the
@@ -239,8 +224,8 @@ out:
239 * Returns zero after adding a new daemon to the hash list; 224 * Returns zero after adding a new daemon to the hash list;
240 * non-zero otherwise. 225 * non-zero otherwise.
241 */ 226 */
242int ecryptfs_process_helo(unsigned int transport, uid_t euid, 227int ecryptfs_process_helo(uid_t euid, struct user_namespace *user_ns,
243 struct user_namespace *user_ns, struct pid *pid) 228 struct pid *pid)
244{ 229{
245 struct ecryptfs_daemon *new_daemon; 230 struct ecryptfs_daemon *new_daemon;
246 struct ecryptfs_daemon *old_daemon; 231 struct ecryptfs_daemon *old_daemon;
@@ -252,8 +237,7 @@ int ecryptfs_process_helo(unsigned int transport, uid_t euid,
252 printk(KERN_WARNING "Received request from user [%d] " 237 printk(KERN_WARNING "Received request from user [%d] "
253 "to register daemon [0x%p]; unregistering daemon " 238 "to register daemon [0x%p]; unregistering daemon "
254 "[0x%p]\n", euid, pid, old_daemon->pid); 239 "[0x%p]\n", euid, pid, old_daemon->pid);
255 rc = ecryptfs_send_raw_message(transport, ECRYPTFS_MSG_QUIT, 240 rc = ecryptfs_send_raw_message(ECRYPTFS_MSG_QUIT, old_daemon);
256 old_daemon);
257 if (rc) 241 if (rc)
258 printk(KERN_WARNING "Failed to send QUIT " 242 printk(KERN_WARNING "Failed to send QUIT "
259 "message to daemon [0x%p]; rc = [%d]\n", 243 "message to daemon [0x%p]; rc = [%d]\n",
@@ -467,8 +451,6 @@ out:
467 451
468/** 452/**
469 * ecryptfs_send_message_locked 453 * ecryptfs_send_message_locked
470 * @transport: The transport over which to send the message (i.e.,
471 * netlink)
472 * @data: The data to send 454 * @data: The data to send
473 * @data_len: The length of data 455 * @data_len: The length of data
474 * @msg_ctx: The message context allocated for the send 456 * @msg_ctx: The message context allocated for the send
@@ -478,8 +460,8 @@ out:
478 * Returns zero on success; non-zero otherwise 460 * Returns zero on success; non-zero otherwise
479 */ 461 */
480static int 462static int
481ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len, 463ecryptfs_send_message_locked(char *data, int data_len, u8 msg_type,
482 u8 msg_type, struct ecryptfs_msg_ctx **msg_ctx) 464 struct ecryptfs_msg_ctx **msg_ctx)
483{ 465{
484 struct ecryptfs_daemon *daemon; 466 struct ecryptfs_daemon *daemon;
485 int rc; 467 int rc;
@@ -503,20 +485,8 @@ ecryptfs_send_message_locked(unsigned int transport, char *data, int data_len,
503 ecryptfs_msg_ctx_free_to_alloc(*msg_ctx); 485 ecryptfs_msg_ctx_free_to_alloc(*msg_ctx);
504 mutex_unlock(&(*msg_ctx)->mux); 486 mutex_unlock(&(*msg_ctx)->mux);
505 mutex_unlock(&ecryptfs_msg_ctx_lists_mux); 487 mutex_unlock(&ecryptfs_msg_ctx_lists_mux);
506 switch (transport) { 488 rc = ecryptfs_send_miscdev(data, data_len, *msg_ctx, msg_type, 0,
507 case ECRYPTFS_TRANSPORT_NETLINK: 489 daemon);
508 rc = ecryptfs_send_netlink(data, data_len, *msg_ctx, msg_type,
509 0, daemon->pid);
510 break;
511 case ECRYPTFS_TRANSPORT_MISCDEV:
512 rc = ecryptfs_send_miscdev(data, data_len, *msg_ctx, msg_type,
513 0, daemon);
514 break;
515 case ECRYPTFS_TRANSPORT_CONNECTOR:
516 case ECRYPTFS_TRANSPORT_RELAYFS:
517 default:
518 rc = -ENOSYS;
519 }
520 if (rc) 490 if (rc)
521 printk(KERN_ERR "%s: Error attempting to send message to " 491 printk(KERN_ERR "%s: Error attempting to send message to "
522 "userspace daemon; rc = [%d]\n", __func__, rc); 492 "userspace daemon; rc = [%d]\n", __func__, rc);
@@ -526,8 +496,6 @@ out:
526 496
527/** 497/**
528 * ecryptfs_send_message 498 * ecryptfs_send_message
529 * @transport: The transport over which to send the message (i.e.,
530 * netlink)
531 * @data: The data to send 499 * @data: The data to send
532 * @data_len: The length of data 500 * @data_len: The length of data
533 * @msg_ctx: The message context allocated for the send 501 * @msg_ctx: The message context allocated for the send
@@ -536,14 +504,14 @@ out:
536 * 504 *
537 * Returns zero on success; non-zero otherwise 505 * Returns zero on success; non-zero otherwise
538 */ 506 */
539int ecryptfs_send_message(unsigned int transport, char *data, int data_len, 507int ecryptfs_send_message(char *data, int data_len,
540 struct ecryptfs_msg_ctx **msg_ctx) 508 struct ecryptfs_msg_ctx **msg_ctx)
541{ 509{
542 int rc; 510 int rc;
543 511
544 mutex_lock(&ecryptfs_daemon_hash_mux); 512 mutex_lock(&ecryptfs_daemon_hash_mux);
545 rc = ecryptfs_send_message_locked(transport, data, data_len, 513 rc = ecryptfs_send_message_locked(data, data_len, ECRYPTFS_MSG_REQUEST,
546 ECRYPTFS_MSG_REQUEST, msg_ctx); 514 msg_ctx);
547 mutex_unlock(&ecryptfs_daemon_hash_mux); 515 mutex_unlock(&ecryptfs_daemon_hash_mux);
548 return rc; 516 return rc;
549} 517}
@@ -586,7 +554,7 @@ sleep:
586 return rc; 554 return rc;
587} 555}
588 556
589int ecryptfs_init_messaging(unsigned int transport) 557int ecryptfs_init_messaging(void)
590{ 558{
591 int i; 559 int i;
592 int rc = 0; 560 int rc = 0;
@@ -639,27 +607,14 @@ int ecryptfs_init_messaging(unsigned int transport)
639 mutex_unlock(&ecryptfs_msg_ctx_arr[i].mux); 607 mutex_unlock(&ecryptfs_msg_ctx_arr[i].mux);
640 } 608 }
641 mutex_unlock(&ecryptfs_msg_ctx_lists_mux); 609 mutex_unlock(&ecryptfs_msg_ctx_lists_mux);
642 switch(transport) { 610 rc = ecryptfs_init_ecryptfs_miscdev();
643 case ECRYPTFS_TRANSPORT_NETLINK: 611 if (rc)
644 rc = ecryptfs_init_netlink(); 612 ecryptfs_release_messaging();
645 if (rc)
646 ecryptfs_release_messaging(transport);
647 break;
648 case ECRYPTFS_TRANSPORT_MISCDEV:
649 rc = ecryptfs_init_ecryptfs_miscdev();
650 if (rc)
651 ecryptfs_release_messaging(transport);
652 break;
653 case ECRYPTFS_TRANSPORT_CONNECTOR:
654 case ECRYPTFS_TRANSPORT_RELAYFS:
655 default:
656 rc = -ENOSYS;
657 }
658out: 613out:
659 return rc; 614 return rc;
660} 615}
661 616
662void ecryptfs_release_messaging(unsigned int transport) 617void ecryptfs_release_messaging(void)
663{ 618{
664 if (ecryptfs_msg_ctx_arr) { 619 if (ecryptfs_msg_ctx_arr) {
665 int i; 620 int i;
@@ -698,17 +653,6 @@ void ecryptfs_release_messaging(unsigned int transport)
698 kfree(ecryptfs_daemon_hash); 653 kfree(ecryptfs_daemon_hash);
699 mutex_unlock(&ecryptfs_daemon_hash_mux); 654 mutex_unlock(&ecryptfs_daemon_hash_mux);
700 } 655 }
701 switch(transport) { 656 ecryptfs_destroy_ecryptfs_miscdev();
702 case ECRYPTFS_TRANSPORT_NETLINK:
703 ecryptfs_release_netlink();
704 break;
705 case ECRYPTFS_TRANSPORT_MISCDEV:
706 ecryptfs_destroy_ecryptfs_miscdev();
707 break;
708 case ECRYPTFS_TRANSPORT_CONNECTOR:
709 case ECRYPTFS_TRANSPORT_RELAYFS:
710 default:
711 break;
712 }
713 return; 657 return;
714} 658}
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 245c2dc02d5c..04d7b3fa1ac6 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -265,22 +265,34 @@ out:
265} 265}
266 266
267/** 267/**
268 * ecryptfs_prepare_write 268 * ecryptfs_write_begin
269 * @file: The eCryptfs file 269 * @file: The eCryptfs file
270 * @page: The eCryptfs page 270 * @mapping: The eCryptfs object
271 * @from: The start byte from which we will write 271 * @pos: The file offset at which to start writing
272 * @to: The end byte to which we will write 272 * @len: Length of the write
273 * @flags: Various flags
274 * @pagep: Pointer to return the page
275 * @fsdata: Pointer to return fs data (unused)
273 * 276 *
274 * This function must zero any hole we create 277 * This function must zero any hole we create
275 * 278 *
276 * Returns zero on success; non-zero otherwise 279 * Returns zero on success; non-zero otherwise
277 */ 280 */
278static int ecryptfs_prepare_write(struct file *file, struct page *page, 281static int ecryptfs_write_begin(struct file *file,
279 unsigned from, unsigned to) 282 struct address_space *mapping,
283 loff_t pos, unsigned len, unsigned flags,
284 struct page **pagep, void **fsdata)
280{ 285{
286 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
287 struct page *page;
281 loff_t prev_page_end_size; 288 loff_t prev_page_end_size;
282 int rc = 0; 289 int rc = 0;
283 290
291 page = __grab_cache_page(mapping, index);
292 if (!page)
293 return -ENOMEM;
294 *pagep = page;
295
284 if (!PageUptodate(page)) { 296 if (!PageUptodate(page)) {
285 struct ecryptfs_crypt_stat *crypt_stat = 297 struct ecryptfs_crypt_stat *crypt_stat =
286 &ecryptfs_inode_to_private( 298 &ecryptfs_inode_to_private(
@@ -289,8 +301,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
289 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED) 301 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
290 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) { 302 || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
291 rc = ecryptfs_read_lower_page_segment( 303 rc = ecryptfs_read_lower_page_segment(
292 page, page->index, 0, PAGE_CACHE_SIZE, 304 page, index, 0, PAGE_CACHE_SIZE, mapping->host);
293 page->mapping->host);
294 if (rc) { 305 if (rc) {
295 printk(KERN_ERR "%s: Error attemping to read " 306 printk(KERN_ERR "%s: Error attemping to read "
296 "lower page segment; rc = [%d]\n", 307 "lower page segment; rc = [%d]\n",
@@ -316,8 +327,8 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
316 SetPageUptodate(page); 327 SetPageUptodate(page);
317 } else { 328 } else {
318 rc = ecryptfs_read_lower_page_segment( 329 rc = ecryptfs_read_lower_page_segment(
319 page, page->index, 0, PAGE_CACHE_SIZE, 330 page, index, 0, PAGE_CACHE_SIZE,
320 page->mapping->host); 331 mapping->host);
321 if (rc) { 332 if (rc) {
322 printk(KERN_ERR "%s: Error reading " 333 printk(KERN_ERR "%s: Error reading "
323 "page; rc = [%d]\n", 334 "page; rc = [%d]\n",
@@ -339,10 +350,10 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
339 SetPageUptodate(page); 350 SetPageUptodate(page);
340 } 351 }
341 } 352 }
342 prev_page_end_size = ((loff_t)page->index << PAGE_CACHE_SHIFT); 353 prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT);
343 /* If creating a page or more of holes, zero them out via truncate. 354 /* If creating a page or more of holes, zero them out via truncate.
344 * Note, this will increase i_size. */ 355 * Note, this will increase i_size. */
345 if (page->index != 0) { 356 if (index != 0) {
346 if (prev_page_end_size > i_size_read(page->mapping->host)) { 357 if (prev_page_end_size > i_size_read(page->mapping->host)) {
347 rc = ecryptfs_truncate(file->f_path.dentry, 358 rc = ecryptfs_truncate(file->f_path.dentry,
348 prev_page_end_size); 359 prev_page_end_size);
@@ -357,8 +368,8 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
357 } 368 }
358 /* Writing to a new page, and creating a small hole from start 369 /* Writing to a new page, and creating a small hole from start
359 * of page? Zero it out. */ 370 * of page? Zero it out. */
360 if ((i_size_read(page->mapping->host) == prev_page_end_size) 371 if ((i_size_read(mapping->host) == prev_page_end_size)
361 && (from != 0)) 372 && (pos != 0))
362 zero_user(page, 0, PAGE_CACHE_SIZE); 373 zero_user(page, 0, PAGE_CACHE_SIZE);
363out: 374out:
364 return rc; 375 return rc;
@@ -445,21 +456,28 @@ int ecryptfs_write_inode_size_to_metadata(struct inode *ecryptfs_inode)
445} 456}
446 457
447/** 458/**
448 * ecryptfs_commit_write 459 * ecryptfs_write_end
449 * @file: The eCryptfs file object 460 * @file: The eCryptfs file object
461 * @mapping: The eCryptfs object
462 * @pos: The file position
463 * @len: The length of the data (unused)
464 * @copied: The amount of data copied
450 * @page: The eCryptfs page 465 * @page: The eCryptfs page
451 * @from: Ignored (we rotate the page IV on each write) 466 * @fsdata: The fsdata (unused)
452 * @to: Ignored
453 * 467 *
454 * This is where we encrypt the data and pass the encrypted data to 468 * This is where we encrypt the data and pass the encrypted data to
455 * the lower filesystem. In OpenPGP-compatible mode, we operate on 469 * the lower filesystem. In OpenPGP-compatible mode, we operate on
456 * entire underlying packets. 470 * entire underlying packets.
457 */ 471 */
458static int ecryptfs_commit_write(struct file *file, struct page *page, 472static int ecryptfs_write_end(struct file *file,
459 unsigned from, unsigned to) 473 struct address_space *mapping,
474 loff_t pos, unsigned len, unsigned copied,
475 struct page *page, void *fsdata)
460{ 476{
461 loff_t pos; 477 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
462 struct inode *ecryptfs_inode = page->mapping->host; 478 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
479 unsigned to = from + copied;
480 struct inode *ecryptfs_inode = mapping->host;
463 struct ecryptfs_crypt_stat *crypt_stat = 481 struct ecryptfs_crypt_stat *crypt_stat =
464 &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)->crypt_stat; 482 &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)->crypt_stat;
465 int rc; 483 int rc;
@@ -471,25 +489,22 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
471 } else 489 } else
472 ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); 490 ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
473 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" 491 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
474 "(page w/ index = [0x%.16x], to = [%d])\n", page->index, 492 "(page w/ index = [0x%.16x], to = [%d])\n", index, to);
475 to);
476 /* Fills in zeros if 'to' goes beyond inode size */ 493 /* Fills in zeros if 'to' goes beyond inode size */
477 rc = fill_zeros_to_end_of_page(page, to); 494 rc = fill_zeros_to_end_of_page(page, to);
478 if (rc) { 495 if (rc) {
479 ecryptfs_printk(KERN_WARNING, "Error attempting to fill " 496 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
480 "zeros in page with index = [0x%.16x]\n", 497 "zeros in page with index = [0x%.16x]\n", index);
481 page->index);
482 goto out; 498 goto out;
483 } 499 }
484 rc = ecryptfs_encrypt_page(page); 500 rc = ecryptfs_encrypt_page(page);
485 if (rc) { 501 if (rc) {
486 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " 502 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
487 "index [0x%.16x])\n", page->index); 503 "index [0x%.16x])\n", index);
488 goto out; 504 goto out;
489 } 505 }
490 pos = (((loff_t)page->index) << PAGE_CACHE_SHIFT) + to; 506 if (pos + copied > i_size_read(ecryptfs_inode)) {
491 if (pos > i_size_read(ecryptfs_inode)) { 507 i_size_write(ecryptfs_inode, pos + copied);
492 i_size_write(ecryptfs_inode, pos);
493 ecryptfs_printk(KERN_DEBUG, "Expanded file size to " 508 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
494 "[0x%.16x]\n", i_size_read(ecryptfs_inode)); 509 "[0x%.16x]\n", i_size_read(ecryptfs_inode));
495 } 510 }
@@ -497,7 +512,11 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
497 if (rc) 512 if (rc)
498 printk(KERN_ERR "Error writing inode size to metadata; " 513 printk(KERN_ERR "Error writing inode size to metadata; "
499 "rc = [%d]\n", rc); 514 "rc = [%d]\n", rc);
515 else
516 rc = copied;
500out: 517out:
518 unlock_page(page);
519 page_cache_release(page);
501 return rc; 520 return rc;
502} 521}
503 522
@@ -518,7 +537,7 @@ static sector_t ecryptfs_bmap(struct address_space *mapping, sector_t block)
518struct address_space_operations ecryptfs_aops = { 537struct address_space_operations ecryptfs_aops = {
519 .writepage = ecryptfs_writepage, 538 .writepage = ecryptfs_writepage,
520 .readpage = ecryptfs_readpage, 539 .readpage = ecryptfs_readpage,
521 .prepare_write = ecryptfs_prepare_write, 540 .write_begin = ecryptfs_write_begin,
522 .commit_write = ecryptfs_commit_write, 541 .write_end = ecryptfs_write_end,
523 .bmap = ecryptfs_bmap, 542 .bmap = ecryptfs_bmap,
524}; 543};
diff --git a/fs/ecryptfs/netlink.c b/fs/ecryptfs/netlink.c
deleted file mode 100644
index e0abad62b395..000000000000
--- a/fs/ecryptfs/netlink.c
+++ /dev/null
@@ -1,249 +0,0 @@
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
4 * Copyright (C) 2004-2006 International Business Machines Corp.
5 * Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com>
6 * Tyler Hicks <tyhicks@ou.edu>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <net/sock.h>
24#include <linux/hash.h>
25#include <linux/random.h>
26#include "ecryptfs_kernel.h"
27
28static struct sock *ecryptfs_nl_sock;
29
30/**
31 * ecryptfs_send_netlink
32 * @data: The data to include as the payload
33 * @data_len: The byte count of the data
34 * @msg_ctx: The netlink context that will be used to handle the
35 * response message
36 * @msg_type: The type of netlink message to send
37 * @msg_flags: The flags to include in the netlink header
38 * @daemon_pid: The process id of the daemon to send the message to
39 *
40 * Sends the data to the specified daemon pid and uses the netlink
41 * context element to store the data needed for validation upon
42 * receiving the response. The data and the netlink context can be
43 * null if just sending a netlink header is sufficient. Returns zero
44 * upon sending the message; non-zero upon error.
45 */
46int ecryptfs_send_netlink(char *data, int data_len,
47 struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
48 u16 msg_flags, struct pid *daemon_pid)
49{
50 struct sk_buff *skb;
51 struct nlmsghdr *nlh;
52 struct ecryptfs_message *msg;
53 size_t payload_len;
54 int rc;
55
56 payload_len = ((data && data_len) ? (sizeof(*msg) + data_len) : 0);
57 skb = alloc_skb(NLMSG_SPACE(payload_len), GFP_KERNEL);
58 if (!skb) {
59 rc = -ENOMEM;
60 ecryptfs_printk(KERN_ERR, "Failed to allocate socket buffer\n");
61 goto out;
62 }
63 nlh = NLMSG_PUT(skb, pid_nr(daemon_pid), msg_ctx ? msg_ctx->counter : 0,
64 msg_type, payload_len);
65 nlh->nlmsg_flags = msg_flags;
66 if (msg_ctx && payload_len) {
67 msg = (struct ecryptfs_message *)NLMSG_DATA(nlh);
68 msg->index = msg_ctx->index;
69 msg->data_len = data_len;
70 memcpy(msg->data, data, data_len);
71 }
72 rc = netlink_unicast(ecryptfs_nl_sock, skb, pid_nr(daemon_pid), 0);
73 if (rc < 0) {
74 ecryptfs_printk(KERN_ERR, "Failed to send eCryptfs netlink "
75 "message; rc = [%d]\n", rc);
76 goto out;
77 }
78 rc = 0;
79 goto out;
80nlmsg_failure:
81 rc = -EMSGSIZE;
82 kfree_skb(skb);
83out:
84 return rc;
85}
86
87/**
88 * ecryptfs_process_nl_reponse
89 * @skb: The socket buffer containing the netlink message of state
90 * RESPONSE
91 *
92 * Processes a response message after sending a operation request to
93 * userspace. Attempts to assign the msg to a netlink context element
94 * at the index specified in the msg. The sk_buff and nlmsghdr must
95 * be validated before this function. Returns zero upon delivery to
96 * desired context element; non-zero upon delivery failure or error.
97 */
98static int ecryptfs_process_nl_response(struct sk_buff *skb)
99{
100 struct nlmsghdr *nlh = nlmsg_hdr(skb);
101 struct ecryptfs_message *msg = NLMSG_DATA(nlh);
102 struct pid *pid;
103 int rc;
104
105 if (skb->len - NLMSG_HDRLEN - sizeof(*msg) != msg->data_len) {
106 rc = -EINVAL;
107 ecryptfs_printk(KERN_ERR, "Received netlink message with "
108 "incorrectly specified data length\n");
109 goto out;
110 }
111 pid = find_get_pid(NETLINK_CREDS(skb)->pid);
112 rc = ecryptfs_process_response(msg, NETLINK_CREDS(skb)->uid, NULL,
113 pid, nlh->nlmsg_seq);
114 put_pid(pid);
115 if (rc)
116 printk(KERN_ERR
117 "Error processing response message; rc = [%d]\n", rc);
118out:
119 return rc;
120}
121
122/**
123 * ecryptfs_process_nl_helo
124 * @skb: The socket buffer containing the nlmsghdr in HELO state
125 *
126 * Gets uid and pid of the skb and adds the values to the daemon id
127 * hash. Returns zero after adding a new daemon id to the hash list;
128 * non-zero otherwise.
129 */
130static int ecryptfs_process_nl_helo(struct sk_buff *skb)
131{
132 struct pid *pid;
133 int rc;
134
135 pid = find_get_pid(NETLINK_CREDS(skb)->pid);
136 rc = ecryptfs_process_helo(ECRYPTFS_TRANSPORT_NETLINK,
137 NETLINK_CREDS(skb)->uid, NULL, pid);
138 put_pid(pid);
139 if (rc)
140 printk(KERN_WARNING "Error processing HELO; rc = [%d]\n", rc);
141 return rc;
142}
143
144/**
145 * ecryptfs_process_nl_quit
146 * @skb: The socket buffer containing the nlmsghdr in QUIT state
147 *
148 * Gets uid and pid of the skb and deletes the corresponding daemon
149 * id, if it is the registered that is requesting the
150 * deletion. Returns zero after deleting the desired daemon id;
151 * non-zero otherwise.
152 */
153static int ecryptfs_process_nl_quit(struct sk_buff *skb)
154{
155 struct pid *pid;
156 int rc;
157
158 pid = find_get_pid(NETLINK_CREDS(skb)->pid);
159 rc = ecryptfs_process_quit(NETLINK_CREDS(skb)->uid, NULL, pid);
160 put_pid(pid);
161 if (rc)
162 printk(KERN_WARNING
163 "Error processing QUIT message; rc = [%d]\n", rc);
164 return rc;
165}
166
167/**
168 * ecryptfs_receive_nl_message
169 *
170 * Callback function called by netlink system when a message arrives.
171 * If the message looks to be valid, then an attempt is made to assign
172 * it to its desired netlink context element and wake up the process
173 * that is waiting for a response.
174 */
175static void ecryptfs_receive_nl_message(struct sk_buff *skb)
176{
177 struct nlmsghdr *nlh;
178
179 nlh = nlmsg_hdr(skb);
180 if (!NLMSG_OK(nlh, skb->len)) {
181 ecryptfs_printk(KERN_ERR, "Received corrupt netlink "
182 "message\n");
183 goto free;
184 }
185 switch (nlh->nlmsg_type) {
186 case ECRYPTFS_MSG_RESPONSE:
187 if (ecryptfs_process_nl_response(skb)) {
188 ecryptfs_printk(KERN_WARNING, "Failed to "
189 "deliver netlink response to "
190 "requesting operation\n");
191 }
192 break;
193 case ECRYPTFS_MSG_HELO:
194 if (ecryptfs_process_nl_helo(skb)) {
195 ecryptfs_printk(KERN_WARNING, "Failed to "
196 "fulfill HELO request\n");
197 }
198 break;
199 case ECRYPTFS_MSG_QUIT:
200 if (ecryptfs_process_nl_quit(skb)) {
201 ecryptfs_printk(KERN_WARNING, "Failed to "
202 "fulfill QUIT request\n");
203 }
204 break;
205 default:
206 ecryptfs_printk(KERN_WARNING, "Dropping netlink "
207 "message of unrecognized type [%d]\n",
208 nlh->nlmsg_type);
209 break;
210 }
211free:
212 kfree_skb(skb);
213}
214
215/**
216 * ecryptfs_init_netlink
217 *
218 * Initializes the daemon id hash list, netlink context array, and
219 * necessary locks. Returns zero upon success; non-zero upon error.
220 */
221int ecryptfs_init_netlink(void)
222{
223 int rc;
224
225 ecryptfs_nl_sock = netlink_kernel_create(&init_net, NETLINK_ECRYPTFS, 0,
226 ecryptfs_receive_nl_message,
227 NULL, THIS_MODULE);
228 if (!ecryptfs_nl_sock) {
229 rc = -EIO;
230 ecryptfs_printk(KERN_ERR, "Failed to create netlink socket\n");
231 goto out;
232 }
233 ecryptfs_nl_sock->sk_sndtimeo = ECRYPTFS_DEFAULT_SEND_TIMEOUT;
234 rc = 0;
235out:
236 return rc;
237}
238
239/**
240 * ecryptfs_release_netlink
241 *
242 * Frees all memory used by the netlink context array and releases the
243 * netlink socket.
244 */
245void ecryptfs_release_netlink(void)
246{
247 netlink_kernel_release(ecryptfs_nl_sock);
248 ecryptfs_nl_sock = NULL;
249}
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 7cc0eb756b55..99368bda0261 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -927,14 +927,11 @@ errxit:
927 /* 927 /*
928 * During the time we spent in the loop above, some other events 928 * During the time we spent in the loop above, some other events
929 * might have been queued by the poll callback. We re-insert them 929 * might have been queued by the poll callback. We re-insert them
930 * here (in case they are not already queued, or they're one-shot). 930 * inside the main ready-list here.
931 */ 931 */
932 for (nepi = ep->ovflist; (epi = nepi) != NULL; 932 for (nepi = ep->ovflist; (epi = nepi) != NULL;
933 nepi = epi->next, epi->next = EP_UNACTIVE_PTR) { 933 nepi = epi->next, epi->next = EP_UNACTIVE_PTR)
934 if (!ep_is_linked(&epi->rdllink) && 934 list_add_tail(&epi->rdllink, &ep->rdllist);
935 (epi->event.events & ~EP_PRIVATE_BITS))
936 list_add_tail(&epi->rdllink, &ep->rdllist);
937 }
938 /* 935 /*
939 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after 936 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after
940 * releasing the lock, events will be queued in the normal way inside 937 * releasing the lock, events will be queued in the normal way inside
diff --git a/fs/exec.c b/fs/exec.c
index 9811679b0695..a41e7902ed0b 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -388,7 +388,7 @@ static int count(char __user * __user * argv, int max)
388 if (!p) 388 if (!p)
389 break; 389 break;
390 argv++; 390 argv++;
391 if(++i > max) 391 if (i++ >= max)
392 return -E2BIG; 392 return -E2BIG;
393 cond_resched(); 393 cond_resched();
394 } 394 }
@@ -822,8 +822,6 @@ static int de_thread(struct task_struct *tsk)
822 schedule(); 822 schedule();
823 } 823 }
824 824
825 if (unlikely(task_child_reaper(tsk) == leader))
826 task_active_pid_ns(tsk)->child_reaper = tsk;
827 /* 825 /*
828 * The only record we have of the real-time age of a 826 * The only record we have of the real-time age of a
829 * process, regardless of execs it's done, is start_time. 827 * process, regardless of execs it's done, is start_time.
@@ -1186,7 +1184,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1186 return retval; 1184 return retval;
1187 1185
1188 /* Remember if the application is TASO. */ 1186 /* Remember if the application is TASO. */
1189 bprm->sh_bang = eh->ah.entry < 0x100000000UL; 1187 bprm->taso = eh->ah.entry < 0x100000000UL;
1190 1188
1191 bprm->file = file; 1189 bprm->file = file;
1192 bprm->loader = loader; 1190 bprm->loader = loader;
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 10bb02c3f25c..6dac7ba2d22d 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -1295,6 +1295,7 @@ retry_alloc:
1295 * turn off reservation for this allocation 1295 * turn off reservation for this allocation
1296 */ 1296 */
1297 if (my_rsv && (free_blocks < windowsz) 1297 if (my_rsv && (free_blocks < windowsz)
1298 && (free_blocks > 0)
1298 && (rsv_is_empty(&my_rsv->rsv_window))) 1299 && (rsv_is_empty(&my_rsv->rsv_window)))
1299 my_rsv = NULL; 1300 my_rsv = NULL;
1300 1301
@@ -1332,7 +1333,7 @@ retry_alloc:
1332 * free blocks is less than half of the reservation 1333 * free blocks is less than half of the reservation
1333 * window size. 1334 * window size.
1334 */ 1335 */
1335 if (free_blocks <= (windowsz/2)) 1336 if (my_rsv && (free_blocks <= (windowsz/2)))
1336 continue; 1337 continue;
1337 1338
1338 brelse(bitmap_bh); 1339 brelse(bitmap_bh);
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index a78c6b4af060..11a49ce84392 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -103,7 +103,7 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
103 return err; 103 return err;
104} 104}
105 105
106static void ext2_check_page(struct page *page) 106static void ext2_check_page(struct page *page, int quiet)
107{ 107{
108 struct inode *dir = page->mapping->host; 108 struct inode *dir = page->mapping->host;
109 struct super_block *sb = dir->i_sb; 109 struct super_block *sb = dir->i_sb;
@@ -146,10 +146,10 @@ out:
146 /* Too bad, we had an error */ 146 /* Too bad, we had an error */
147 147
148Ebadsize: 148Ebadsize:
149 ext2_error(sb, "ext2_check_page", 149 if (!quiet)
150 "size of directory #%lu is not a multiple of chunk size", 150 ext2_error(sb, __func__,
151 dir->i_ino 151 "size of directory #%lu is not a multiple "
152 ); 152 "of chunk size", dir->i_ino);
153 goto fail; 153 goto fail;
154Eshort: 154Eshort:
155 error = "rec_len is smaller than minimal"; 155 error = "rec_len is smaller than minimal";
@@ -166,32 +166,36 @@ Espan:
166Einumber: 166Einumber:
167 error = "inode out of bounds"; 167 error = "inode out of bounds";
168bad_entry: 168bad_entry:
169 ext2_error (sb, "ext2_check_page", "bad entry in directory #%lu: %s - " 169 if (!quiet)
170 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d", 170 ext2_error(sb, __func__, "bad entry in directory #%lu: : %s - "
171 dir->i_ino, error, (page->index<<PAGE_CACHE_SHIFT)+offs, 171 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
172 (unsigned long) le32_to_cpu(p->inode), 172 dir->i_ino, error, (page->index<<PAGE_CACHE_SHIFT)+offs,
173 rec_len, p->name_len); 173 (unsigned long) le32_to_cpu(p->inode),
174 rec_len, p->name_len);
174 goto fail; 175 goto fail;
175Eend: 176Eend:
176 p = (ext2_dirent *)(kaddr + offs); 177 if (!quiet) {
177 ext2_error (sb, "ext2_check_page", 178 p = (ext2_dirent *)(kaddr + offs);
178 "entry in directory #%lu spans the page boundary" 179 ext2_error(sb, "ext2_check_page",
179 "offset=%lu, inode=%lu", 180 "entry in directory #%lu spans the page boundary"
180 dir->i_ino, (page->index<<PAGE_CACHE_SHIFT)+offs, 181 "offset=%lu, inode=%lu",
181 (unsigned long) le32_to_cpu(p->inode)); 182 dir->i_ino, (page->index<<PAGE_CACHE_SHIFT)+offs,
183 (unsigned long) le32_to_cpu(p->inode));
184 }
182fail: 185fail:
183 SetPageChecked(page); 186 SetPageChecked(page);
184 SetPageError(page); 187 SetPageError(page);
185} 188}
186 189
187static struct page * ext2_get_page(struct inode *dir, unsigned long n) 190static struct page * ext2_get_page(struct inode *dir, unsigned long n,
191 int quiet)
188{ 192{
189 struct address_space *mapping = dir->i_mapping; 193 struct address_space *mapping = dir->i_mapping;
190 struct page *page = read_mapping_page(mapping, n, NULL); 194 struct page *page = read_mapping_page(mapping, n, NULL);
191 if (!IS_ERR(page)) { 195 if (!IS_ERR(page)) {
192 kmap(page); 196 kmap(page);
193 if (!PageChecked(page)) 197 if (!PageChecked(page))
194 ext2_check_page(page); 198 ext2_check_page(page, quiet);
195 if (PageError(page)) 199 if (PageError(page))
196 goto fail; 200 goto fail;
197 } 201 }
@@ -292,7 +296,7 @@ ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
292 for ( ; n < npages; n++, offset = 0) { 296 for ( ; n < npages; n++, offset = 0) {
293 char *kaddr, *limit; 297 char *kaddr, *limit;
294 ext2_dirent *de; 298 ext2_dirent *de;
295 struct page *page = ext2_get_page(inode, n); 299 struct page *page = ext2_get_page(inode, n, 0);
296 300
297 if (IS_ERR(page)) { 301 if (IS_ERR(page)) {
298 ext2_error(sb, __func__, 302 ext2_error(sb, __func__,
@@ -361,6 +365,7 @@ struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
361 struct page *page = NULL; 365 struct page *page = NULL;
362 struct ext2_inode_info *ei = EXT2_I(dir); 366 struct ext2_inode_info *ei = EXT2_I(dir);
363 ext2_dirent * de; 367 ext2_dirent * de;
368 int dir_has_error = 0;
364 369
365 if (npages == 0) 370 if (npages == 0)
366 goto out; 371 goto out;
@@ -374,7 +379,7 @@ struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
374 n = start; 379 n = start;
375 do { 380 do {
376 char *kaddr; 381 char *kaddr;
377 page = ext2_get_page(dir, n); 382 page = ext2_get_page(dir, n, dir_has_error);
378 if (!IS_ERR(page)) { 383 if (!IS_ERR(page)) {
379 kaddr = page_address(page); 384 kaddr = page_address(page);
380 de = (ext2_dirent *) kaddr; 385 de = (ext2_dirent *) kaddr;
@@ -391,7 +396,9 @@ struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
391 de = ext2_next_entry(de); 396 de = ext2_next_entry(de);
392 } 397 }
393 ext2_put_page(page); 398 ext2_put_page(page);
394 } 399 } else
400 dir_has_error = 1;
401
395 if (++n >= npages) 402 if (++n >= npages)
396 n = 0; 403 n = 0;
397 /* next page is past the blocks we've got */ 404 /* next page is past the blocks we've got */
@@ -414,7 +421,7 @@ found:
414 421
415struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p) 422struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
416{ 423{
417 struct page *page = ext2_get_page(dir, 0); 424 struct page *page = ext2_get_page(dir, 0, 0);
418 ext2_dirent *de = NULL; 425 ext2_dirent *de = NULL;
419 426
420 if (!IS_ERR(page)) { 427 if (!IS_ERR(page)) {
@@ -487,7 +494,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
487 for (n = 0; n <= npages; n++) { 494 for (n = 0; n <= npages; n++) {
488 char *dir_end; 495 char *dir_end;
489 496
490 page = ext2_get_page(dir, n); 497 page = ext2_get_page(dir, n, 0);
491 err = PTR_ERR(page); 498 err = PTR_ERR(page);
492 if (IS_ERR(page)) 499 if (IS_ERR(page))
493 goto out; 500 goto out;
@@ -655,14 +662,17 @@ int ext2_empty_dir (struct inode * inode)
655{ 662{
656 struct page *page = NULL; 663 struct page *page = NULL;
657 unsigned long i, npages = dir_pages(inode); 664 unsigned long i, npages = dir_pages(inode);
665 int dir_has_error = 0;
658 666
659 for (i = 0; i < npages; i++) { 667 for (i = 0; i < npages; i++) {
660 char *kaddr; 668 char *kaddr;
661 ext2_dirent * de; 669 ext2_dirent * de;
662 page = ext2_get_page(inode, i); 670 page = ext2_get_page(inode, i, dir_has_error);
663 671
664 if (IS_ERR(page)) 672 if (IS_ERR(page)) {
673 dir_has_error = 1;
665 continue; 674 continue;
675 }
666 676
667 kaddr = page_address(page); 677 kaddr = page_address(page);
668 de = (ext2_dirent *)kaddr; 678 de = (ext2_dirent *)kaddr;
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 25adfc3c693a..d0ff0b8cf309 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -8,7 +8,7 @@
8 * pages against inodes. ie: data writeback. Writeout of the 8 * pages against inodes. ie: data writeback. Writeout of the
9 * inode itself is not handled here. 9 * inode itself is not handled here.
10 * 10 *
11 * 10Apr2002 akpm@zip.com.au 11 * 10Apr2002 Andrew Morton
12 * Split out of fs/inode.c 12 * Split out of fs/inode.c
13 * Additions for address_space-based writeback 13 * Additions for address_space-based writeback
14 */ 14 */
diff --git a/fs/hfs/catalog.c b/fs/hfs/catalog.c
index ba851576ebb1..6d98f116ca03 100644
--- a/fs/hfs/catalog.c
+++ b/fs/hfs/catalog.c
@@ -190,6 +190,10 @@ int hfs_cat_find_brec(struct super_block *sb, u32 cnid,
190 190
191 fd->search_key->cat.ParID = rec.thread.ParID; 191 fd->search_key->cat.ParID = rec.thread.ParID;
192 len = fd->search_key->cat.CName.len = rec.thread.CName.len; 192 len = fd->search_key->cat.CName.len = rec.thread.CName.len;
193 if (len > HFS_NAMELEN) {
194 printk(KERN_ERR "hfs: bad catalog namelength\n");
195 return -EIO;
196 }
193 memcpy(fd->search_key->cat.CName.name, rec.thread.CName.name, len); 197 memcpy(fd->search_key->cat.CName.name, rec.thread.CName.name, len);
194 return hfs_brec_find(fd); 198 return hfs_brec_find(fd);
195} 199}
diff --git a/fs/hfsplus/bitmap.c b/fs/hfsplus/bitmap.c
index d128a25b74d2..ea30afc2a03c 100644
--- a/fs/hfsplus/bitmap.c
+++ b/fs/hfsplus/bitmap.c
@@ -32,6 +32,10 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
32 mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex); 32 mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex);
33 mapping = HFSPLUS_SB(sb).alloc_file->i_mapping; 33 mapping = HFSPLUS_SB(sb).alloc_file->i_mapping;
34 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, NULL); 34 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, NULL);
35 if (IS_ERR(page)) {
36 start = size;
37 goto out;
38 }
35 pptr = kmap(page); 39 pptr = kmap(page);
36 curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32; 40 curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
37 i = offset % 32; 41 i = offset % 32;
@@ -73,6 +77,10 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, u32 *ma
73 break; 77 break;
74 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, 78 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS,
75 NULL); 79 NULL);
80 if (IS_ERR(page)) {
81 start = size;
82 goto out;
83 }
76 curr = pptr = kmap(page); 84 curr = pptr = kmap(page);
77 if ((size ^ offset) / PAGE_CACHE_BITS) 85 if ((size ^ offset) / PAGE_CACHE_BITS)
78 end = pptr + PAGE_CACHE_BITS / 32; 86 end = pptr + PAGE_CACHE_BITS / 32;
@@ -120,6 +128,10 @@ found:
120 offset += PAGE_CACHE_BITS; 128 offset += PAGE_CACHE_BITS;
121 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, 129 page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS,
122 NULL); 130 NULL);
131 if (IS_ERR(page)) {
132 start = size;
133 goto out;
134 }
123 pptr = kmap(page); 135 pptr = kmap(page);
124 curr = pptr; 136 curr = pptr;
125 end = pptr + PAGE_CACHE_BITS / 32; 137 end = pptr + PAGE_CACHE_BITS / 32;
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index ba117c445e78..f6874acb2cf2 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -168,6 +168,11 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
168 return -EIO; 168 return -EIO;
169 } 169 }
170 170
171 if (be16_to_cpu(tmp.thread.nodeName.length) > 255) {
172 printk(KERN_ERR "hfs: catalog name length corrupted\n");
173 return -EIO;
174 }
175
171 hfsplus_cat_build_key_uni(fd->search_key, be32_to_cpu(tmp.thread.parentID), 176 hfsplus_cat_build_key_uni(fd->search_key, be32_to_cpu(tmp.thread.parentID),
172 &tmp.thread.nodeName); 177 &tmp.thread.nodeName);
173 return hfs_brec_find(fd); 178 return hfs_brec_find(fd);
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index e834e578c93f..eb74531a0a8e 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -356,7 +356,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
356 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) { 356 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
357 printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n"); 357 printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
358 sb->s_flags |= MS_RDONLY; 358 sb->s_flags |= MS_RDONLY;
359 } else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) { 359 } else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) && !(sb->s_flags & MS_RDONLY)) {
360 printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, " 360 printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, "
361 "use the force option at your own risk, mounting read-only.\n"); 361 "use the force option at your own risk, mounting read-only.\n");
362 sb->s_flags |= MS_RDONLY; 362 sb->s_flags |= MS_RDONLY;
diff --git a/fs/mpage.c b/fs/mpage.c
index dbcc7af76a15..552b80b3facc 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -6,7 +6,7 @@
6 * Contains functions related to preparing and submitting BIOs which contain 6 * Contains functions related to preparing and submitting BIOs which contain
7 * multiple pagecache pages. 7 * multiple pagecache pages.
8 * 8 *
9 * 15May2002 akpm@zip.com.au 9 * 15May2002 Andrew Morton
10 * Initial version 10 * Initial version
11 * 27Jun2002 axboe@suse.de 11 * 27Jun2002 axboe@suse.de
12 * use bio_add_page() to build bio's just the right size 12 * use bio_add_page() to build bio's just the right size
diff --git a/fs/partitions/acorn.c b/fs/partitions/acorn.c
index 3d3e16631472..a97b477ac0fc 100644
--- a/fs/partitions/acorn.c
+++ b/fs/partitions/acorn.c
@@ -275,16 +275,6 @@ adfspart_check_ADFS(struct parsed_partitions *state, struct block_device *bdev)
275 id = data[0x1fc] & 15; 275 id = data[0x1fc] & 15;
276 put_dev_sector(sect); 276 put_dev_sector(sect);
277 277
278#ifdef CONFIG_BLK_DEV_MFM
279 if (MAJOR(bdev->bd_dev) == MFM_ACORN_MAJOR) {
280 extern void xd_set_geometry(struct block_device *,
281 unsigned char, unsigned char, unsigned int);
282 xd_set_geometry(bdev, dr->secspertrack, heads, 1);
283 invalidate_bh_lrus();
284 truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
285 }
286#endif
287
288 /* 278 /*
289 * Work out start of non-adfs partition. 279 * Work out start of non-adfs partition.
290 */ 280 */
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 7408227c49c9..fbeb2f372a93 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -538,10 +538,23 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
538 sector_t from = state->parts[p].from; 538 sector_t from = state->parts[p].from;
539 if (!size) 539 if (!size)
540 continue; 540 continue;
541 if (from >= get_capacity(disk)) {
542 printk(KERN_WARNING
543 "%s: p%d ignored, start %llu is behind the end of the disk\n",
544 disk->disk_name, p, (unsigned long long) from);
545 continue;
546 }
541 if (from + size > get_capacity(disk)) { 547 if (from + size > get_capacity(disk)) {
548 /*
549 * we can not ignore partitions of broken tables
550 * created by for example camera firmware, but we
551 * limit them to the end of the disk to avoid
552 * creating invalid block devices
553 */
542 printk(KERN_WARNING 554 printk(KERN_WARNING
543 "%s: p%d exceeds device capacity\n", 555 "%s: p%d size %llu limited to end of disk\n",
544 disk->disk_name, p); 556 disk->disk_name, p, (unsigned long long) size);
557 size = get_capacity(disk) - from;
545 } 558 }
546 res = add_partition(disk, p, from, size, state->parts[p].flags); 559 res = add_partition(disk, p, from, size, state->parts[p].flags);
547 if (res) { 560 if (res) {
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index b675a49c1823..59ea42e1ef03 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -45,7 +45,6 @@
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/hugetlb.h> 46#include <linux/hugetlb.h>
47#include <linux/jiffies.h> 47#include <linux/jiffies.h>
48#include <linux/sysrq.h>
49#include <linux/vmalloc.h> 48#include <linux/vmalloc.h>
50#include <linux/crash_dump.h> 49#include <linux/crash_dump.h>
51#include <linux/pid_namespace.h> 50#include <linux/pid_namespace.h>
@@ -704,28 +703,6 @@ static int execdomains_read_proc(char *page, char **start, off_t off,
704 return proc_calc_metrics(page, start, off, count, eof, len); 703 return proc_calc_metrics(page, start, off, count, eof, len);
705} 704}
706 705
707#ifdef CONFIG_MAGIC_SYSRQ
708/*
709 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
710 */
711static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
712 size_t count, loff_t *ppos)
713{
714 if (count) {
715 char c;
716
717 if (get_user(c, buf))
718 return -EFAULT;
719 __handle_sysrq(c, NULL, 0);
720 }
721 return count;
722}
723
724static const struct file_operations proc_sysrq_trigger_operations = {
725 .write = write_sysrq_trigger,
726};
727#endif
728
729#ifdef CONFIG_PROC_PAGE_MONITOR 706#ifdef CONFIG_PROC_PAGE_MONITOR
730#define KPMSIZE sizeof(u64) 707#define KPMSIZE sizeof(u64)
731#define KPMMASK (KPMSIZE - 1) 708#define KPMMASK (KPMSIZE - 1)
@@ -934,7 +911,4 @@ void __init proc_misc_init(void)
934#ifdef CONFIG_PROC_VMCORE 911#ifdef CONFIG_PROC_VMCORE
935 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations); 912 proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
936#endif 913#endif
937#ifdef CONFIG_MAGIC_SYSRQ
938 proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations);
939#endif
940} 914}
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index b9dbeeca7049..37173fa07d15 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -8,8 +8,6 @@
8 8
9/* proc info support a la one created by Sizif@Botik.RU for PGC */ 9/* proc info support a la one created by Sizif@Botik.RU for PGC */
10 10
11/* $Id: procfs.c,v 1.1.8.2 2001/07/15 17:08:42 god Exp $ */
12
13#include <linux/module.h> 11#include <linux/module.h>
14#include <linux/time.h> 12#include <linux/time.h>
15#include <linux/seq_file.h> 13#include <linux/seq_file.h>
@@ -621,7 +619,6 @@ int reiserfs_global_version_in_proc(char *buffer, char **start,
621#endif 619#endif
622 620
623/* 621/*
624 * $Log: procfs.c,v $
625 * Revision 1.1.8.2 2001/07/15 17:08:42 god 622 * Revision 1.1.8.2 2001/07/15 17:08:42 god
626 * . use get_super() in procfs.c 623 * . use get_super() in procfs.c
627 * . remove remove_save_link() from reiserfs_do_truncate() 624 * . remove remove_save_link() from reiserfs_do_truncate()
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index bb3cb5b7cdb2..ad92461cbfc3 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -155,7 +155,7 @@ static struct dentry *get_xa_file_dentry(const struct inode *inode,
155 xadir = open_xa_dir(inode, flags); 155 xadir = open_xa_dir(inode, flags);
156 if (IS_ERR(xadir)) { 156 if (IS_ERR(xadir)) {
157 return ERR_CAST(xadir); 157 return ERR_CAST(xadir);
158 } else if (xadir && !xadir->d_inode) { 158 } else if (!xadir->d_inode) {
159 dput(xadir); 159 dput(xadir);
160 return ERR_PTR(-ENODATA); 160 return ERR_PTR(-ENODATA);
161 } 161 }