Skip to content

Commit decd616

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc fixes from Andrew Morton: "7 fixes" * emailed patches from Andrew Morton <[email protected]>: kasan: add missing functions declarations to kasan.h kasan: consistently disable debugging features ipc/util.c: sysvipc_find_ipc() incorrectly updates position index userfaultfd: fix remap event with MREMAP_DONTUNMAP mm/gup: fix fixup_user_fault() on multiple retries epoll: call final ep_events_available() check under the lock mm, memcg: fix inconsistent oom event behavior
2 parents 8c1684b + 13cf048 commit decd616

File tree

7 files changed

+86
-39
lines changed

7 files changed

+86
-39
lines changed

fs/eventpoll.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,34 +1879,33 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
18791879
* event delivery.
18801880
*/
18811881
init_wait(&wait);
1882-
write_lock_irq(&ep->lock);
1883-
__add_wait_queue_exclusive(&ep->wq, &wait);
1884-
write_unlock_irq(&ep->lock);
18851882

1883+
write_lock_irq(&ep->lock);
18861884
/*
1887-
* We don't want to sleep if the ep_poll_callback() sends us
1888-
* a wakeup in between. That's why we set the task state
1889-
* to TASK_INTERRUPTIBLE before doing the checks.
1885+
* Barrierless variant, waitqueue_active() is called under
1886+
* the same lock on wakeup ep_poll_callback() side, so it
1887+
* is safe to avoid an explicit barrier.
18901888
*/
1891-
set_current_state(TASK_INTERRUPTIBLE);
1889+
__set_current_state(TASK_INTERRUPTIBLE);
1890+
18921891
/*
1893-
* Always short-circuit for fatal signals to allow
1894-
* threads to make a timely exit without the chance of
1895-
* finding more events available and fetching
1896-
* repeatedly.
1892+
* Do the final check under the lock. ep_scan_ready_list()
1893+
* plays with two lists (->rdllist and ->ovflist) and there
1894+
* is always a race when both lists are empty for short
1895+
* period of time although events are pending, so lock is
1896+
* important.
18971897
*/
1898-
if (fatal_signal_pending(current)) {
1899-
res = -EINTR;
1900-
break;
1898+
eavail = ep_events_available(ep);
1899+
if (!eavail) {
1900+
if (signal_pending(current))
1901+
res = -EINTR;
1902+
else
1903+
__add_wait_queue_exclusive(&ep->wq, &wait);
19011904
}
1905+
write_unlock_irq(&ep->lock);
19021906

1903-
eavail = ep_events_available(ep);
1904-
if (eavail)
1905-
break;
1906-
if (signal_pending(current)) {
1907-
res = -EINTR;
1907+
if (eavail || res)
19081908
break;
1909-
}
19101909

19111910
if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS)) {
19121911
timed_out = 1;
@@ -1927,6 +1926,15 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
19271926
}
19281927

19291928
send_events:
1929+
if (fatal_signal_pending(current)) {
1930+
/*
1931+
* Always short-circuit for fatal signals to allow
1932+
* threads to make a timely exit without the chance of
1933+
* finding more events available and fetching
1934+
* repeatedly.
1935+
*/
1936+
res = -EINTR;
1937+
}
19301938
/*
19311939
* Try to transfer events to user space. In case we get 0 events and
19321940
* there's still timeout left over, we go trying again in search of

include/linux/memcontrol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg,
783783
atomic_long_inc(&memcg->memory_events[event]);
784784
cgroup_file_notify(&memcg->events_file);
785785

786+
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
787+
break;
786788
if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
787789
break;
788790
} while ((memcg = parent_mem_cgroup(memcg)) &&

ipc/util.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,21 +764,21 @@ static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
764764
total++;
765765
}
766766

767-
*new_pos = pos + 1;
767+
ipc = NULL;
768768
if (total >= ids->in_use)
769-
return NULL;
769+
goto out;
770770

771771
for (; pos < ipc_mni; pos++) {
772772
ipc = idr_find(&ids->ipcs_idr, pos);
773773
if (ipc != NULL) {
774774
rcu_read_lock();
775775
ipc_lock_object(ipc);
776-
return ipc;
776+
break;
777777
}
778778
}
779-
780-
/* Out of range - return NULL to terminate iteration */
781-
return NULL;
779+
out:
780+
*new_pos = pos + 1;
781+
return ipc;
782782
}
783783

784784
static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)

mm/gup.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,10 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
12181218
if (!vma_permits_fault(vma, fault_flags))
12191219
return -EFAULT;
12201220

1221+
if ((fault_flags & FAULT_FLAG_KILLABLE) &&
1222+
fatal_signal_pending(current))
1223+
return -EINTR;
1224+
12211225
ret = handle_mm_fault(vma, address, fault_flags);
12221226
major |= ret & VM_FAULT_MAJOR;
12231227
if (ret & VM_FAULT_ERROR) {
@@ -1230,11 +1234,9 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
12301234

12311235
if (ret & VM_FAULT_RETRY) {
12321236
down_read(&mm->mmap_sem);
1233-
if (!(fault_flags & FAULT_FLAG_TRIED)) {
1234-
*unlocked = true;
1235-
fault_flags |= FAULT_FLAG_TRIED;
1236-
goto retry;
1237-
}
1237+
*unlocked = true;
1238+
fault_flags |= FAULT_FLAG_TRIED;
1239+
goto retry;
12381240
}
12391241

12401242
if (tsk) {

mm/kasan/Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# SPDX-License-Identifier: GPL-2.0
22
KASAN_SANITIZE := n
3-
UBSAN_SANITIZE_common.o := n
4-
UBSAN_SANITIZE_generic.o := n
5-
UBSAN_SANITIZE_generic_report.o := n
6-
UBSAN_SANITIZE_tags.o := n
3+
UBSAN_SANITIZE := n
74
KCOV_INSTRUMENT := n
85

6+
# Disable ftrace to avoid recursion.
97
CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
108
CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
119
CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE)
10+
CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE)
11+
CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE)
12+
CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
1213
CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE)
14+
CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE)
1315

1416
# Function splitter causes unnecessary splits in __asan_load1/__asan_store1
1517
# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
16-
1718
CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
1819
CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
1920
CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
21+
CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
22+
CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
23+
CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
2024
CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
25+
CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
2126

2227
obj-$(CONFIG_KASAN) := common.o init.o report.o
2328
obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o

mm/kasan/kasan.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
212212
asmlinkage void kasan_unpoison_task_stack_below(const void *watermark);
213213
void __asan_register_globals(struct kasan_global *globals, size_t size);
214214
void __asan_unregister_globals(struct kasan_global *globals, size_t size);
215-
void __asan_loadN(unsigned long addr, size_t size);
216-
void __asan_storeN(unsigned long addr, size_t size);
217215
void __asan_handle_no_return(void);
218216
void __asan_alloca_poison(unsigned long addr, size_t size);
219217
void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
@@ -228,6 +226,8 @@ void __asan_load8(unsigned long addr);
228226
void __asan_store8(unsigned long addr);
229227
void __asan_load16(unsigned long addr);
230228
void __asan_store16(unsigned long addr);
229+
void __asan_loadN(unsigned long addr, size_t size);
230+
void __asan_storeN(unsigned long addr, size_t size);
231231

232232
void __asan_load1_noabort(unsigned long addr);
233233
void __asan_store1_noabort(unsigned long addr);
@@ -239,6 +239,21 @@ void __asan_load8_noabort(unsigned long addr);
239239
void __asan_store8_noabort(unsigned long addr);
240240
void __asan_load16_noabort(unsigned long addr);
241241
void __asan_store16_noabort(unsigned long addr);
242+
void __asan_loadN_noabort(unsigned long addr, size_t size);
243+
void __asan_storeN_noabort(unsigned long addr, size_t size);
244+
245+
void __asan_report_load1_noabort(unsigned long addr);
246+
void __asan_report_store1_noabort(unsigned long addr);
247+
void __asan_report_load2_noabort(unsigned long addr);
248+
void __asan_report_store2_noabort(unsigned long addr);
249+
void __asan_report_load4_noabort(unsigned long addr);
250+
void __asan_report_store4_noabort(unsigned long addr);
251+
void __asan_report_load8_noabort(unsigned long addr);
252+
void __asan_report_store8_noabort(unsigned long addr);
253+
void __asan_report_load16_noabort(unsigned long addr);
254+
void __asan_report_store16_noabort(unsigned long addr);
255+
void __asan_report_load_n_noabort(unsigned long addr, size_t size);
256+
void __asan_report_store_n_noabort(unsigned long addr, size_t size);
242257

243258
void __asan_set_shadow_00(const void *addr, size_t size);
244259
void __asan_set_shadow_f1(const void *addr, size_t size);
@@ -247,4 +262,19 @@ void __asan_set_shadow_f3(const void *addr, size_t size);
247262
void __asan_set_shadow_f5(const void *addr, size_t size);
248263
void __asan_set_shadow_f8(const void *addr, size_t size);
249264

265+
void __hwasan_load1_noabort(unsigned long addr);
266+
void __hwasan_store1_noabort(unsigned long addr);
267+
void __hwasan_load2_noabort(unsigned long addr);
268+
void __hwasan_store2_noabort(unsigned long addr);
269+
void __hwasan_load4_noabort(unsigned long addr);
270+
void __hwasan_store4_noabort(unsigned long addr);
271+
void __hwasan_load8_noabort(unsigned long addr);
272+
void __hwasan_store8_noabort(unsigned long addr);
273+
void __hwasan_load16_noabort(unsigned long addr);
274+
void __hwasan_store16_noabort(unsigned long addr);
275+
void __hwasan_loadN_noabort(unsigned long addr, size_t size);
276+
void __hwasan_storeN_noabort(unsigned long addr, size_t size);
277+
278+
void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size);
279+
250280
#endif

mm/mremap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
794794
if (locked && new_len > old_len)
795795
mm_populate(new_addr + old_len, new_len - old_len);
796796
userfaultfd_unmap_complete(mm, &uf_unmap_early);
797-
mremap_userfaultfd_complete(&uf, addr, new_addr, old_len);
797+
mremap_userfaultfd_complete(&uf, addr, ret, old_len);
798798
userfaultfd_unmap_complete(mm, &uf_unmap);
799799
return ret;
800800
}

0 commit comments

Comments
 (0)