Skip to content

Commit be88751

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull misc filesystem updates from Jan Kara: "udf, ext2, quota, fsnotify fixes & cleanups: - udf fixes for handling of media without uid/gid - udf fixes for some corner cases in parsing of volume recognition sequence - improvements of fsnotify handling of ENOMEM - new ioctl to allow setting of watch descriptor id for inotify (for checkpoint - restart) - small ext2, reiserfs, quota cleanups" * 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: quota: Kill an unused extern entry form quota.h reiserfs: Remove VLA from fs/reiserfs/reiserfs.h udf: fix potential refcnt problem of nls module ext2: change return code to -ENOMEM when failing memory allocation udf: Do not mark possibly inconsistent filesystems as closed fsnotify: Let userspace know about lost events due to ENOMEM fanotify: Avoid lost events due to ENOMEM for unlimited queues udf: Remove never implemented mount options udf: Update mount option documentation udf: Provide saner default for invalid uid / gid udf: Clean up handling of invalid uid/gid udf: Apply uid/gid mount options also to new inodes & chown udf: Ignore [ug]id=ignore mount options udf: Fix handling of Partition Descriptors udf: Unify common handling of descriptors udf: Convert descriptor index definitions to enum udf: Allow volume descriptor sequence to be terminated by unrecorded block udf: Simplify handling of Volume Descriptor Pointers udf: Fix off-by-one in volume descriptor sequence length inotify: Extend ioctl to allow to request id of new watch descriptor
2 parents 5e4d659 + b91ed9d commit be88751

File tree

18 files changed

+240
-179
lines changed

18 files changed

+240
-179
lines changed

Documentation/filesystems/udf.txt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ The following mount options are supported:
3636
iocharset= Set the NLS character set
3737

3838
The uid= and gid= options need a bit more explaining. They will accept a
39-
decimal numeric value which will be used as the default ID for that mount.
40-
They will also accept the string "ignore" and "forget". For files on the disk
41-
that are owned by nobody ( -1 ), they will instead look as if they are owned
42-
by the default ID. The ignore option causes the default ID to override all
43-
IDs on the disk, not just -1. The forget option causes all IDs to be written
44-
to disk as -1, so when the media is later remounted, they will appear to be
45-
owned by whatever default ID it is mounted with at that time.
39+
decimal numeric value and all inodes on that mount will then appear as
40+
belonging to that uid and gid. Mount options also accept the string "forget".
41+
The forget option causes all IDs to be written to disk as -1 which is a way
42+
of UDF standard to indicate that IDs are not supported for these files .
4643

47-
For typical desktop use of removable media, you should set the ID to that
48-
of the interactively logged on user, and also specify both the forget and
49-
ignore options. This way the interactive user will always see the files
50-
on the disk as belonging to him.
44+
For typical desktop use of removable media, you should set the ID to that of
45+
the interactively logged on user, and also specify the forget option. This way
46+
the interactive user will always see the files on the disk as belonging to him.
5147

5248
The remaining are for debugging and disaster recovery:
5349

@@ -57,16 +53,8 @@ The following expect a offset from 0.
5753

5854
session= Set the CDROM session (default= last session)
5955
anchor= Override standard anchor location. (default= 256)
60-
volume= Override the VolumeDesc location. (unused)
61-
partition= Override the PartitionDesc location. (unused)
6256
lastblock= Set the last block of the filesystem/
6357

64-
The following expect a offset from the partition root.
65-
66-
fileset= Override the fileset block location. (unused)
67-
rootdir= Override the root directory location. (unused)
68-
WARNING: overriding the rootdir to a non-directory may
69-
yield highly unpredictable results.
7058
-------------------------------------------------------------------------------
7159

7260

fs/ext2/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,15 +827,14 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
827827
unsigned long logic_sb_block;
828828
unsigned long offset = 0;
829829
unsigned long def_mount_opts;
830-
long ret = -EINVAL;
830+
long ret = -ENOMEM;
831831
int blocksize = BLOCK_SIZE;
832832
int db_count;
833833
int i, j;
834834
__le32 features;
835835
int err;
836836
struct ext2_mount_options opts;
837837

838-
err = -ENOMEM;
839838
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
840839
if (!sbi)
841840
goto failed;
@@ -851,6 +850,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
851850
sbi->s_daxdev = dax_dev;
852851

853852
spin_lock_init(&sbi->s_lock);
853+
ret = -EINVAL;
854854

855855
/*
856856
* See what the current blocksize for the device is, and

fs/notify/fanotify/fanotify.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,32 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
139139
return false;
140140
}
141141

142-
struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
142+
struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group,
143+
struct inode *inode, u32 mask,
143144
const struct path *path)
144145
{
145146
struct fanotify_event_info *event;
147+
gfp_t gfp = GFP_KERNEL;
148+
149+
/*
150+
* For queues with unlimited length lost events are not expected and
151+
* can possibly have security implications. Avoid losing events when
152+
* memory is short.
153+
*/
154+
if (group->max_events == UINT_MAX)
155+
gfp |= __GFP_NOFAIL;
146156

147157
if (fanotify_is_perm_event(mask)) {
148158
struct fanotify_perm_event_info *pevent;
149159

150-
pevent = kmem_cache_alloc(fanotify_perm_event_cachep,
151-
GFP_KERNEL);
160+
pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp);
152161
if (!pevent)
153162
return NULL;
154163
event = &pevent->fae;
155164
pevent->response = 0;
156165
goto init;
157166
}
158-
event = kmem_cache_alloc(fanotify_event_cachep, GFP_KERNEL);
167+
event = kmem_cache_alloc(fanotify_event_cachep, gfp);
159168
if (!event)
160169
return NULL;
161170
init: __maybe_unused
@@ -210,10 +219,17 @@ static int fanotify_handle_event(struct fsnotify_group *group,
210219
return 0;
211220
}
212221

213-
event = fanotify_alloc_event(inode, mask, data);
222+
event = fanotify_alloc_event(group, inode, mask, data);
214223
ret = -ENOMEM;
215-
if (unlikely(!event))
224+
if (unlikely(!event)) {
225+
/*
226+
* We don't queue overflow events for permission events as
227+
* there the access is denied and so no event is in fact lost.
228+
*/
229+
if (!fanotify_is_perm_event(mask))
230+
fsnotify_queue_overflow(group);
216231
goto finish;
232+
}
217233

218234
fsn_event = &event->fse;
219235
ret = fsnotify_add_event(group, fsn_event, fanotify_merge);

fs/notify/fanotify/fanotify.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse)
5252
return container_of(fse, struct fanotify_event_info, fse);
5353
}
5454

55-
struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
55+
struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group,
56+
struct inode *inode, u32 mask,
5657
const struct path *path);

fs/notify/fanotify/fanotify_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
757757
group->fanotify_data.user = user;
758758
atomic_inc(&user->fanotify_listeners);
759759

760-
oevent = fanotify_alloc_event(NULL, FS_Q_OVERFLOW, NULL);
760+
oevent = fanotify_alloc_event(group, NULL, FS_Q_OVERFLOW, NULL);
761761
if (unlikely(!oevent)) {
762762
fd = -ENOMEM;
763763
goto out_destroy_group;

fs/notify/inotify/inotify_fsnotify.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ int inotify_handle_event(struct fsnotify_group *group,
9999
fsn_mark);
100100

101101
event = kmalloc(alloc_len, GFP_KERNEL);
102-
if (unlikely(!event))
102+
if (unlikely(!event)) {
103+
/*
104+
* Treat lost event due to ENOMEM the same way as queue
105+
* overflow to let userspace know event was lost.
106+
*/
107+
fsnotify_queue_overflow(group);
103108
return -ENOMEM;
109+
}
104110

105111
fsn_event = &event->fse;
106112
fsnotify_init_event(fsn_event, inode, mask);

fs/notify/inotify/inotify_user.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,20 @@ static long inotify_ioctl(struct file *file, unsigned int cmd,
307307
spin_unlock(&group->notification_lock);
308308
ret = put_user(send_len, (int __user *) p);
309309
break;
310+
#ifdef CONFIG_CHECKPOINT_RESTORE
311+
case INOTIFY_IOC_SETNEXTWD:
312+
ret = -EINVAL;
313+
if (arg >= 1 && arg <= INT_MAX) {
314+
struct inotify_group_private_data *data;
315+
316+
data = &group->inotify_data;
317+
spin_lock(&data->idr_lock);
318+
idr_set_cursor(&data->idr, (unsigned int)arg);
319+
spin_unlock(&data->idr_lock);
320+
ret = 0;
321+
}
322+
break;
323+
#endif /* CONFIG_CHECKPOINT_RESTORE */
310324
}
311325

312326
return ret;

fs/notify/notification.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ int fsnotify_add_event(struct fsnotify_group *group,
111111
return 2;
112112
}
113113

114-
if (group->q_len >= group->max_events) {
114+
if (event == group->overflow_event ||
115+
group->q_len >= group->max_events) {
115116
ret = 2;
116117
/* Queue overflow event only if it isn't already queued */
117118
if (!list_empty(&group->overflow_event->list)) {

fs/reiserfs/reiserfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ struct reiserfs_de_head {
19161916

19171917
/* empty directory contains two entries "." and ".." and their headers */
19181918
#define EMPTY_DIR_SIZE \
1919-
(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen ("..")))
1919+
(DEH_SIZE * 2 + ROUND_UP (sizeof(".") - 1) + ROUND_UP (sizeof("..") - 1))
19201920

19211921
/* old format directories have this size when empty */
19221922
#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)

fs/udf/file.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,22 @@ const struct file_operations udf_file_operations = {
257257
static int udf_setattr(struct dentry *dentry, struct iattr *attr)
258258
{
259259
struct inode *inode = d_inode(dentry);
260+
struct super_block *sb = inode->i_sb;
260261
int error;
261262

262263
error = setattr_prepare(dentry, attr);
263264
if (error)
264265
return error;
265266

267+
if ((attr->ia_valid & ATTR_UID) &&
268+
UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET) &&
269+
!uid_eq(attr->ia_uid, UDF_SB(sb)->s_uid))
270+
return -EPERM;
271+
if ((attr->ia_valid & ATTR_GID) &&
272+
UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET) &&
273+
!gid_eq(attr->ia_gid, UDF_SB(sb)->s_gid))
274+
return -EPERM;
275+
266276
if ((attr->ia_valid & ATTR_SIZE) &&
267277
attr->ia_size != i_size_read(inode)) {
268278
error = udf_setsize(inode, attr->ia_size);

fs/udf/ialloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode)
104104
}
105105

106106
inode_init_owner(inode, dir, mode);
107+
if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
108+
inode->i_uid = sbi->s_uid;
109+
if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
110+
inode->i_gid = sbi->s_gid;
107111

108112
iinfo->i_location.logicalBlockNum = block;
109113
iinfo->i_location.partitionReferenceNum =

fs/udf/inode.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
12751275
unsigned int indirections = 0;
12761276
int bs = inode->i_sb->s_blocksize;
12771277
int ret = -EIO;
1278+
uint32_t uid, gid;
12781279

12791280
reread:
12801281
if (iloc->partitionReferenceNum >= sbi->s_partitions) {
@@ -1400,17 +1401,19 @@ static int udf_read_inode(struct inode *inode, bool hidden_inode)
14001401

14011402
ret = -EIO;
14021403
read_lock(&sbi->s_cred_lock);
1403-
i_uid_write(inode, le32_to_cpu(fe->uid));
1404-
if (!uid_valid(inode->i_uid) ||
1405-
UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
1404+
uid = le32_to_cpu(fe->uid);
1405+
if (uid == UDF_INVALID_ID ||
14061406
UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
1407-
inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1407+
inode->i_uid = sbi->s_uid;
1408+
else
1409+
i_uid_write(inode, uid);
14081410

1409-
i_gid_write(inode, le32_to_cpu(fe->gid));
1410-
if (!gid_valid(inode->i_gid) ||
1411-
UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
1411+
gid = le32_to_cpu(fe->gid);
1412+
if (gid == UDF_INVALID_ID ||
14121413
UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
1413-
inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1414+
inode->i_gid = sbi->s_gid;
1415+
else
1416+
i_gid_write(inode, gid);
14141417

14151418
if (fe->icbTag.fileType != ICBTAG_FILE_TYPE_DIRECTORY &&
14161419
sbi->s_fmode != UDF_INVALID_MODE)
@@ -1655,12 +1658,12 @@ static int udf_update_inode(struct inode *inode, int do_sync)
16551658
}
16561659

16571660
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1658-
fe->uid = cpu_to_le32(-1);
1661+
fe->uid = cpu_to_le32(UDF_INVALID_ID);
16591662
else
16601663
fe->uid = cpu_to_le32(i_uid_read(inode));
16611664

16621665
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1663-
fe->gid = cpu_to_le32(-1);
1666+
fe->gid = cpu_to_le32(UDF_INVALID_ID);
16641667
else
16651668
fe->gid = cpu_to_le32(i_gid_read(inode));
16661669

0 commit comments

Comments
 (0)