diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2010-01-24 00:04:07 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-01-26 22:22:24 -0500 |
commit | 29333920a5a46edcc9b728e2cf0134d5a9b516ee (patch) | |
tree | 2991b9f6d82d43c712278d6364da4faad4a0180d /fs | |
parent | afc70ed05a07bfe171f7a5b8fdc80bdb073d314f (diff) |
Fix remount races with symlink handling in affs
A couple of fields in affs_sb_info is used in follow_link() and
symlink() for handling AFFS "absolute" symlinks. Need locking
against affs_remount() updates.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/affs/affs.h | 2 | ||||
-rw-r--r-- | fs/affs/namei.c | 7 | ||||
-rw-r--r-- | fs/affs/super.c | 17 | ||||
-rw-r--r-- | fs/affs/symlink.c | 7 |
4 files changed, 25 insertions, 8 deletions
diff --git a/fs/affs/affs.h b/fs/affs/affs.h index e511dc621a2e..0e40caaba456 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h | |||
@@ -106,8 +106,8 @@ struct affs_sb_info { | |||
106 | u32 s_last_bmap; | 106 | u32 s_last_bmap; |
107 | struct buffer_head *s_bmap_bh; | 107 | struct buffer_head *s_bmap_bh; |
108 | char *s_prefix; /* Prefix for volumes and assigns. */ | 108 | char *s_prefix; /* Prefix for volumes and assigns. */ |
109 | int s_prefix_len; /* Length of prefix. */ | ||
110 | char s_volume[32]; /* Volume prefix for absolute symlinks. */ | 109 | char s_volume[32]; /* Volume prefix for absolute symlinks. */ |
110 | spinlock_t symlink_lock; /* protects the previous two */ | ||
111 | }; | 111 | }; |
112 | 112 | ||
113 | #define SF_INTL 0x0001 /* International filesystem. */ | 113 | #define SF_INTL 0x0001 /* International filesystem. */ |
diff --git a/fs/affs/namei.c b/fs/affs/namei.c index 960d336ec694..d70bbbac6b7b 100644 --- a/fs/affs/namei.c +++ b/fs/affs/namei.c | |||
@@ -341,10 +341,13 @@ affs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |||
341 | p = (char *)AFFS_HEAD(bh)->table; | 341 | p = (char *)AFFS_HEAD(bh)->table; |
342 | lc = '/'; | 342 | lc = '/'; |
343 | if (*symname == '/') { | 343 | if (*symname == '/') { |
344 | struct affs_sb_info *sbi = AFFS_SB(sb); | ||
344 | while (*symname == '/') | 345 | while (*symname == '/') |
345 | symname++; | 346 | symname++; |
346 | while (AFFS_SB(sb)->s_volume[i]) /* Cannot overflow */ | 347 | spin_lock(&sbi->symlink_lock); |
347 | *p++ = AFFS_SB(sb)->s_volume[i++]; | 348 | while (sbi->s_volume[i]) /* Cannot overflow */ |
349 | *p++ = sbi->s_volume[i++]; | ||
350 | spin_unlock(&sbi->symlink_lock); | ||
348 | } | 351 | } |
349 | while (i < maxlen && (c = *symname++)) { | 352 | while (i < maxlen && (c = *symname++)) { |
350 | if (c == '.' && lc == '/' && *symname == '.' && symname[1] == '/') { | 353 | if (c == '.' && lc == '/' && *symname == '.' && symname[1] == '/') { |
diff --git a/fs/affs/super.c b/fs/affs/super.c index b2a5958c6191..be6a6e8ed7d6 100644 --- a/fs/affs/super.c +++ b/fs/affs/super.c | |||
@@ -221,8 +221,6 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s | |||
221 | *mount_opts |= SF_MUFS; | 221 | *mount_opts |= SF_MUFS; |
222 | break; | 222 | break; |
223 | case Opt_prefix: | 223 | case Opt_prefix: |
224 | /* Free any previous prefix */ | ||
225 | kfree(*prefix); | ||
226 | *prefix = match_strdup(&args[0]); | 224 | *prefix = match_strdup(&args[0]); |
227 | if (!*prefix) | 225 | if (!*prefix) |
228 | return 0; | 226 | return 0; |
@@ -311,6 +309,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent) | |||
311 | return -ENOMEM; | 309 | return -ENOMEM; |
312 | sb->s_fs_info = sbi; | 310 | sb->s_fs_info = sbi; |
313 | mutex_init(&sbi->s_bmlock); | 311 | mutex_init(&sbi->s_bmlock); |
312 | spin_lock_init(&sbi->symlink_lock); | ||
314 | 313 | ||
315 | if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, | 314 | if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, |
316 | &blocksize,&sbi->s_prefix, | 315 | &blocksize,&sbi->s_prefix, |
@@ -518,14 +517,18 @@ affs_remount(struct super_block *sb, int *flags, char *data) | |||
518 | unsigned long mount_flags; | 517 | unsigned long mount_flags; |
519 | int res = 0; | 518 | int res = 0; |
520 | char *new_opts = kstrdup(data, GFP_KERNEL); | 519 | char *new_opts = kstrdup(data, GFP_KERNEL); |
520 | char volume[32]; | ||
521 | char *prefix = NULL; | ||
521 | 522 | ||
522 | pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data); | 523 | pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data); |
523 | 524 | ||
524 | *flags |= MS_NODIRATIME; | 525 | *flags |= MS_NODIRATIME; |
525 | 526 | ||
527 | memcpy(volume, sbi->s_volume, 32); | ||
526 | if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block, | 528 | if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block, |
527 | &blocksize, &sbi->s_prefix, sbi->s_volume, | 529 | &blocksize, &prefix, volume, |
528 | &mount_flags)) { | 530 | &mount_flags)) { |
531 | kfree(prefix); | ||
529 | kfree(new_opts); | 532 | kfree(new_opts); |
530 | return -EINVAL; | 533 | return -EINVAL; |
531 | } | 534 | } |
@@ -536,6 +539,14 @@ affs_remount(struct super_block *sb, int *flags, char *data) | |||
536 | sbi->s_mode = mode; | 539 | sbi->s_mode = mode; |
537 | sbi->s_uid = uid; | 540 | sbi->s_uid = uid; |
538 | sbi->s_gid = gid; | 541 | sbi->s_gid = gid; |
542 | /* protect against readers */ | ||
543 | spin_lock(&sbi->symlink_lock); | ||
544 | if (prefix) { | ||
545 | kfree(sbi->s_prefix); | ||
546 | sbi->s_prefix = prefix; | ||
547 | } | ||
548 | memcpy(sbi->s_volume, volume, 32); | ||
549 | spin_unlock(&sbi->symlink_lock); | ||
539 | 550 | ||
540 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) { | 551 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) { |
541 | unlock_kernel(); | 552 | unlock_kernel(); |
diff --git a/fs/affs/symlink.c b/fs/affs/symlink.c index 41782539c907..ee00f08c4f53 100644 --- a/fs/affs/symlink.c +++ b/fs/affs/symlink.c | |||
@@ -20,7 +20,6 @@ static int affs_symlink_readpage(struct file *file, struct page *page) | |||
20 | int i, j; | 20 | int i, j; |
21 | char c; | 21 | char c; |
22 | char lc; | 22 | char lc; |
23 | char *pf; | ||
24 | 23 | ||
25 | pr_debug("AFFS: follow_link(ino=%lu)\n",inode->i_ino); | 24 | pr_debug("AFFS: follow_link(ino=%lu)\n",inode->i_ino); |
26 | 25 | ||
@@ -32,11 +31,15 @@ static int affs_symlink_readpage(struct file *file, struct page *page) | |||
32 | j = 0; | 31 | j = 0; |
33 | lf = (struct slink_front *)bh->b_data; | 32 | lf = (struct slink_front *)bh->b_data; |
34 | lc = 0; | 33 | lc = 0; |
35 | pf = AFFS_SB(inode->i_sb)->s_prefix ? AFFS_SB(inode->i_sb)->s_prefix : "/"; | ||
36 | 34 | ||
37 | if (strchr(lf->symname,':')) { /* Handle assign or volume name */ | 35 | if (strchr(lf->symname,':')) { /* Handle assign or volume name */ |
36 | struct affs_sb_info *sbi = AFFS_SB(inode->i_sb); | ||
37 | char *pf; | ||
38 | spin_lock(&sbi->symlink_lock); | ||
39 | pf = sbi->s_prefix ? sbi->s_prefix : "/"; | ||
38 | while (i < 1023 && (c = pf[i])) | 40 | while (i < 1023 && (c = pf[i])) |
39 | link[i++] = c; | 41 | link[i++] = c; |
42 | spin_unlock(&sbi->symlink_lock); | ||
40 | while (i < 1023 && lf->symname[j] != ':') | 43 | while (i < 1023 && lf->symname[j] != ':') |
41 | link[i++] = lf->symname[j++]; | 44 | link[i++] = lf->symname[j++]; |
42 | if (i < 1023) | 45 | if (i < 1023) |