Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 29780
b: refs/heads/master
c: 9c8ef56
h: refs/heads/master
v: v3
  • Loading branch information
Miklos Szeredi authored and Linus Torvalds committed Jun 25, 2006
1 parent fb34825 commit 71f81b7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a4d27e75ffb7b8ecb7eed0c7db0df975525f3fd7
refs/heads/master: 9c8ef5614da22666e339b125263d315cfaa89109
29 changes: 20 additions & 9 deletions trunk/fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,25 @@ static int fuse_release(struct inode *inode, struct file *file)
}

/*
* It would be nice to scramble the ID space, so that the value of the
* files_struct pointer is not exposed to userspace. Symmetric crypto
* functions are overkill, since the inverse function doesn't need to
* be implemented (though it does have to exist). Is there something
* simpler?
* Scramble the ID space with XTEA, so that the value of the files_struct
* pointer is not exposed to userspace.
*/
static inline u64 fuse_lock_owner_id(fl_owner_t id)
static u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id)
{
return (unsigned long) id;
u32 *k = fc->scramble_key;
u64 v = (unsigned long) id;
u32 v0 = v;
u32 v1 = v >> 32;
u32 sum = 0;
int i;

for (i = 0; i < 32; i++) {
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
sum += 0x9E3779B9;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
}

return (u64) v0 + ((u64) v1 << 32);
}

static int fuse_flush(struct file *file, fl_owner_t id)
Expand All @@ -190,7 +200,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)
req = fuse_get_req_nofail(fc, file);
memset(&inarg, 0, sizeof(inarg));
inarg.fh = ff->fh;
inarg.lock_owner = fuse_lock_owner_id(id);
inarg.lock_owner = fuse_lock_owner_id(fc, id);
req->in.h.opcode = FUSE_FLUSH;
req->in.h.nodeid = get_node_id(inode);
req->in.numargs = 1;
Expand Down Expand Up @@ -644,11 +654,12 @@ static void fuse_lk_fill(struct fuse_req *req, struct file *file,
const struct file_lock *fl, int opcode, pid_t pid)
{
struct inode *inode = file->f_dentry->d_inode;
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_file *ff = file->private_data;
struct fuse_lk_in *arg = &req->misc.lk_in;

arg->fh = ff->fh;
arg->owner = fuse_lock_owner_id(fl->fl_owner);
arg->owner = fuse_lock_owner_id(fc, fl->fl_owner);
arg->lk.start = fl->fl_start;
arg->lk.end = fl->fl_end;
arg->lk.type = fl->fl_type;
Expand Down
3 changes: 3 additions & 0 deletions trunk/fs/fuse/fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ struct fuse_conn {

/** O_ASYNC requests */
struct fasync_struct *fasync;

/** Key for lock owner ID scrambling */
u32 scramble_key[4];
};

static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
Expand Down
2 changes: 2 additions & 0 deletions trunk/fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/parser.h>
#include <linux/statfs.h>
#include <linux/random.h>

MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
MODULE_DESCRIPTION("Filesystem in Userspace");
Expand Down Expand Up @@ -387,6 +388,7 @@ static struct fuse_conn *new_conn(void)
fc->bdi.unplug_io_fn = default_unplug_io_fn;
fc->reqctr = 0;
fc->blocked = 1;
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
}
return fc;
}
Expand Down

0 comments on commit 71f81b7

Please sign in to comment.