Skip to content

Commit 0d9cf33

Browse files
committed
Merge tag 'for_v4.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
- isofs memory leak fix - two fsnotify fixes of event mask handling - udf fix of UTF-16 handling - couple other smaller cleanups * tag 'for_v4.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: udf: Fix leak of UTF-16 surrogates into encoded strings fs: ext2: Adding new return type vm_fault_t isofs: fix potential memory leak in mount option parsing MAINTAINERS: add an entry for FSNOTIFY infrastructure fsnotify: fix typo in a comment about mark->g_list fsnotify: fix ignore mask logic in send_to_group() isofs compress: Remove VLA usage fs: quota: Replace GFP_ATOMIC with GFP_KERNEL in dquot_init fanotify: fix logic of events on child
2 parents 4d18905 + 44f06ba commit 0d9cf33

9 files changed

Lines changed: 63 additions & 40 deletions

File tree

‎MAINTAINERS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5784,6 +5784,14 @@ F: fs/crypto/
57845784
F: include/linux/fscrypt*.h
57855785
F: Documentation/filesystems/fscrypt.rst
57865786

5787+
FSNOTIFY: FILESYSTEM NOTIFICATION INFRASTRUCTURE
5788+
M: Jan Kara <jack@suse.cz>
5789+
R: Amir Goldstein <amir73il@gmail.com>
5790+
L: linux-fsdevel@vger.kernel.org
5791+
S: Maintained
5792+
F: fs/notify/
5793+
F: include/linux/fsnotify*.h
5794+
57875795
FUJITSU LAPTOP EXTRAS
57885796
M: Jonathan Woithe <jwoithe@just42.net>
57895797
L: platform-driver-x86@vger.kernel.org

‎fs/ext2/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ static ssize_t ext2_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
8888
* The default page_lock and i_size verification done by non-DAX fault paths
8989
* is sufficient because ext2 doesn't support hole punching.
9090
*/
91-
static int ext2_dax_fault(struct vm_fault *vmf)
91+
static vm_fault_t ext2_dax_fault(struct vm_fault *vmf)
9292
{
9393
struct inode *inode = file_inode(vmf->vma->vm_file);
9494
struct ext2_inode_info *ei = EXT2_I(inode);
95-
int ret;
95+
vm_fault_t ret;
9696

9797
if (vmf->flags & FAULT_FLAG_WRITE) {
9898
sb_start_pagefault(inode->i_sb);

‎fs/isofs/compress.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/init.h>
2121
#include <linux/bio.h>
2222

23+
#include <linux/slab.h>
2324
#include <linux/vmalloc.h>
2425
#include <linux/zlib.h>
2526

@@ -59,7 +60,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
5960
>> bufshift;
6061
int haveblocks;
6162
blkcnt_t blocknum;
62-
struct buffer_head *bhs[needblocks + 1];
63+
struct buffer_head **bhs;
6364
int curbh, curpage;
6465

6566
if (block_size > deflateBound(1UL << zisofs_block_shift)) {
@@ -80,7 +81,11 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
8081

8182
/* Because zlib is not thread-safe, do all the I/O at the top. */
8283
blocknum = block_start >> bufshift;
83-
memset(bhs, 0, (needblocks + 1) * sizeof(struct buffer_head *));
84+
bhs = kcalloc(needblocks + 1, sizeof(*bhs), GFP_KERNEL);
85+
if (!bhs) {
86+
*errp = -ENOMEM;
87+
return 0;
88+
}
8489
haveblocks = isofs_get_blocks(inode, blocknum, bhs, needblocks);
8590
ll_rw_block(REQ_OP_READ, 0, haveblocks, bhs);
8691

@@ -190,6 +195,7 @@ static loff_t zisofs_uncompress_block(struct inode *inode, loff_t block_start,
190195
b_eio:
191196
for (i = 0; i < haveblocks; i++)
192197
brelse(bhs[i]);
198+
kfree(bhs);
193199
return stream.total_out;
194200
}
195201

@@ -305,7 +311,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
305311
unsigned int zisofs_pages_per_cblock =
306312
PAGE_SHIFT <= zisofs_block_shift ?
307313
(1 << (zisofs_block_shift - PAGE_SHIFT)) : 0;
308-
struct page *pages[max_t(unsigned, zisofs_pages_per_cblock, 1)];
314+
struct page **pages;
309315
pgoff_t index = page->index, end_index;
310316

311317
end_index = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -330,6 +336,12 @@ static int zisofs_readpage(struct file *file, struct page *page)
330336
full_page = 0;
331337
pcount = 1;
332338
}
339+
pages = kcalloc(max_t(unsigned int, zisofs_pages_per_cblock, 1),
340+
sizeof(*pages), GFP_KERNEL);
341+
if (!pages) {
342+
unlock_page(page);
343+
return -ENOMEM;
344+
}
333345
pages[full_page] = page;
334346

335347
for (i = 0; i < pcount; i++, index++) {
@@ -357,6 +369,7 @@ static int zisofs_readpage(struct file *file, struct page *page)
357369
}
358370

359371
/* At this point, err contains 0 or -EIO depending on the "critical" page */
372+
kfree(pages);
360373
return err;
361374
}
362375

‎fs/isofs/inode.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ static int parse_options(char *options, struct iso9660_options *popt)
394394
break;
395395
#ifdef CONFIG_JOLIET
396396
case Opt_iocharset:
397+
kfree(popt->iocharset);
397398
popt->iocharset = match_strdup(&args[0]);
399+
if (!popt->iocharset)
400+
return 0;
398401
break;
399402
#endif
400403
case Opt_map_a:

‎fs/notify/fanotify/fanotify.c‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
9292
u32 event_mask,
9393
const void *data, int data_type)
9494
{
95-
__u32 marks_mask, marks_ignored_mask;
95+
__u32 marks_mask = 0, marks_ignored_mask = 0;
9696
const struct path *path = data;
9797

9898
pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p"
@@ -108,24 +108,20 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
108108
!d_can_lookup(path->dentry))
109109
return false;
110110

111-
if (inode_mark && vfsmnt_mark) {
112-
marks_mask = (vfsmnt_mark->mask | inode_mark->mask);
113-
marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask);
114-
} else if (inode_mark) {
115-
/*
116-
* if the event is for a child and this inode doesn't care about
117-
* events on the child, don't send it!
118-
*/
119-
if ((event_mask & FS_EVENT_ON_CHILD) &&
120-
!(inode_mark->mask & FS_EVENT_ON_CHILD))
121-
return false;
122-
marks_mask = inode_mark->mask;
123-
marks_ignored_mask = inode_mark->ignored_mask;
124-
} else if (vfsmnt_mark) {
125-
marks_mask = vfsmnt_mark->mask;
126-
marks_ignored_mask = vfsmnt_mark->ignored_mask;
127-
} else {
128-
BUG();
111+
/*
112+
* if the event is for a child and this inode doesn't care about
113+
* events on the child, don't send it!
114+
*/
115+
if (inode_mark &&
116+
(!(event_mask & FS_EVENT_ON_CHILD) ||
117+
(inode_mark->mask & FS_EVENT_ON_CHILD))) {
118+
marks_mask |= inode_mark->mask;
119+
marks_ignored_mask |= inode_mark->ignored_mask;
120+
}
121+
122+
if (vfsmnt_mark) {
123+
marks_mask |= vfsmnt_mark->mask;
124+
marks_ignored_mask |= vfsmnt_mark->ignored_mask;
129125
}
130126

131127
if (d_is_dir(path->dentry) &&

‎fs/notify/fsnotify.c‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ static int send_to_group(struct inode *to_tell,
192192
struct fsnotify_iter_info *iter_info)
193193
{
194194
struct fsnotify_group *group = NULL;
195-
__u32 inode_test_mask = 0;
196-
__u32 vfsmount_test_mask = 0;
195+
__u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
196+
__u32 marks_mask = 0;
197+
__u32 marks_ignored_mask = 0;
197198

198199
if (unlikely(!inode_mark && !vfsmount_mark)) {
199200
BUG();
@@ -213,29 +214,25 @@ static int send_to_group(struct inode *to_tell,
213214
/* does the inode mark tell us to do something? */
214215
if (inode_mark) {
215216
group = inode_mark->group;
216-
inode_test_mask = (mask & ~FS_EVENT_ON_CHILD);
217-
inode_test_mask &= inode_mark->mask;
218-
inode_test_mask &= ~inode_mark->ignored_mask;
217+
marks_mask |= inode_mark->mask;
218+
marks_ignored_mask |= inode_mark->ignored_mask;
219219
}
220220

221221
/* does the vfsmount_mark tell us to do something? */
222222
if (vfsmount_mark) {
223-
vfsmount_test_mask = (mask & ~FS_EVENT_ON_CHILD);
224223
group = vfsmount_mark->group;
225-
vfsmount_test_mask &= vfsmount_mark->mask;
226-
vfsmount_test_mask &= ~vfsmount_mark->ignored_mask;
227-
if (inode_mark)
228-
vfsmount_test_mask &= ~inode_mark->ignored_mask;
224+
marks_mask |= vfsmount_mark->mask;
225+
marks_ignored_mask |= vfsmount_mark->ignored_mask;
229226
}
230227

231228
pr_debug("%s: group=%p to_tell=%p mask=%x inode_mark=%p"
232-
" inode_test_mask=%x vfsmount_mark=%p vfsmount_test_mask=%x"
229+
" vfsmount_mark=%p marks_mask=%x marks_ignored_mask=%x"
233230
" data=%p data_is=%d cookie=%d\n",
234-
__func__, group, to_tell, mask, inode_mark,
235-
inode_test_mask, vfsmount_mark, vfsmount_test_mask, data,
231+
__func__, group, to_tell, mask, inode_mark, vfsmount_mark,
232+
marks_mask, marks_ignored_mask, data,
236233
data_is, cookie);
237234

238-
if (!inode_test_mask && !vfsmount_test_mask)
235+
if (!(test_mask & marks_mask & ~marks_ignored_mask))
239236
return 0;
240237

241238
return group->ops->handle_event(group, to_tell, inode_mark,

‎fs/quota/dquot.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ static int __init dquot_init(void)
29662966
NULL);
29672967

29682968
order = 0;
2969-
dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order);
2969+
dquot_hash = (struct hlist_head *)__get_free_pages(GFP_KERNEL, order);
29702970
if (!dquot_hash)
29712971
panic("Cannot create dquot hash table");
29722972

‎fs/udf/unicode.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#include "udf_sb.h"
3030

31+
#define SURROGATE_MASK 0xfffff800
32+
#define SURROGATE_PAIR 0x0000d800
33+
3134
static int udf_uni2char_utf8(wchar_t uni,
3235
unsigned char *out,
3336
int boundlen)
@@ -37,6 +40,9 @@ static int udf_uni2char_utf8(wchar_t uni,
3740
if (boundlen <= 0)
3841
return -ENAMETOOLONG;
3942

43+
if ((uni & SURROGATE_MASK) == SURROGATE_PAIR)
44+
return -EINVAL;
45+
4046
if (uni < 0x80) {
4147
out[u_len++] = (unsigned char)uni;
4248
} else if (uni < 0x800) {

‎include/linux/fsnotify_backend.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ struct fsnotify_mark {
248248
/* Group this mark is for. Set on mark creation, stable until last ref
249249
* is dropped */
250250
struct fsnotify_group *group;
251-
/* List of marks by group->i_fsnotify_marks. Also reused for queueing
251+
/* List of marks by group->marks_list. Also reused for queueing
252252
* mark into destroy_list when it's waiting for the end of SRCU period
253253
* before it can be freed. [group->mark_mutex] */
254254
struct list_head g_list;

0 commit comments

Comments
 (0)