History

Merge branch 'linus' into timers/urgent, to pick up fixes

Ingo Molnar committed 10 years ago

Commit fdbdfef2 parents 6731b0d a0cba214843 files · +205309 −138546Browse files

Showing the changes to kernel (20 of 4843 files). Show all

Unified · Split

20 files
  1. kernel/configs/android-base.config +152 −0
  2. kernel/configs/android-recommended.config +121 −0
  3. kernel/events/core.c +1 −1
  4. kernel/exit.c +1 −1
  5. kernel/jump_label.c +60 −1
  6. kernel/kexec.c +2 −1
  7. kernel/kexec_core.c +45 −24
  8. kernel/ksysfs.c +3 −3
  9. kernel/livepatch/core.c +1 −1
  10. kernel/module.c +101 −21
  11. kernel/panic.c +4 −9
  12. kernel/printk/printk.c +154 −16
  13. kernel/ptrace.c +2 −2
  14. kernel/relay.c +32 −2
  15. kernel/seccomp.c +3 −3
  16. kernel/sysctl.c +7 −0
  17. kernel/task_work.c +6 −4
  18. kernel/trace/Makefile +4 −0
  19. kernel/trace/blktrace.c +3 −3
  20. kernel/trace/trace_events_hist.c +7 −7
kernel/configs/android-base.config+152−0
@@ -0,0 +1,152 @@
1+# KEEP ALPHABETICALLY SORTED
2+# CONFIG_DEVKMEM is not set
3+# CONFIG_DEVMEM is not set
4+# CONFIG_INET_LRO is not set
5+# CONFIG_MODULES is not set
6+# CONFIG_OABI_COMPAT is not set
7+# CONFIG_SYSVIPC is not set
8+CONFIG_ANDROID=y
9+CONFIG_ANDROID_BINDER_IPC=y
10+CONFIG_ANDROID_LOW_MEMORY_KILLER=y
11+CONFIG_ARMV8_DEPRECATED=y
12+CONFIG_ASHMEM=y
13+CONFIG_AUDIT=y
14+CONFIG_BLK_DEV_DM=y
15+CONFIG_BLK_DEV_INITRD=y
16+CONFIG_CGROUPS=y
17+CONFIG_CGROUP_CPUACCT=y
18+CONFIG_CGROUP_DEBUG=y
19+CONFIG_CGROUP_FREEZER=y
20+CONFIG_CGROUP_SCHED=y
21+CONFIG_CP15_BARRIER_EMULATION=y
22+CONFIG_DM_CRYPT=y
23+CONFIG_DM_VERITY=y
24+CONFIG_DM_VERITY_FEC=y
25+CONFIG_EMBEDDED=y
26+CONFIG_FB=y
27+CONFIG_HIGH_RES_TIMERS=y
28+CONFIG_INET6_AH=y
29+CONFIG_INET6_ESP=y
30+CONFIG_INET6_IPCOMP=y
31+CONFIG_INET=y
32+CONFIG_INET_DIAG_DESTROY=y
33+CONFIG_INET_ESP=y
34+CONFIG_INET_XFRM_MODE_TUNNEL=y
35+CONFIG_IP6_NF_FILTER=y
36+CONFIG_IP6_NF_IPTABLES=y
37+CONFIG_IP6_NF_MANGLE=y
38+CONFIG_IP6_NF_RAW=y
39+CONFIG_IP6_NF_TARGET_REJECT=y
40+CONFIG_IPV6=y
41+CONFIG_IPV6_MIP6=y
42+CONFIG_IPV6_MULTIPLE_TABLES=y
43+CONFIG_IPV6_OPTIMISTIC_DAD=y
44+CONFIG_IPV6_PRIVACY=y
45+CONFIG_IPV6_ROUTER_PREF=y
46+CONFIG_IPV6_ROUTE_INFO=y
47+CONFIG_IP_ADVANCED_ROUTER=y
48+CONFIG_IP_MULTICAST=y
49+CONFIG_IP_MULTIPLE_TABLES=y
50+CONFIG_IP_NF_ARPFILTER=y
51+CONFIG_IP_NF_ARPTABLES=y
52+CONFIG_IP_NF_ARP_MANGLE=y
53+CONFIG_IP_NF_FILTER=y
54+CONFIG_IP_NF_IPTABLES=y
55+CONFIG_IP_NF_MANGLE=y
56+CONFIG_IP_NF_MATCH_AH=y
57+CONFIG_IP_NF_MATCH_ECN=y
58+CONFIG_IP_NF_MATCH_TTL=y
59+CONFIG_IP_NF_NAT=y
60+CONFIG_IP_NF_RAW=y
61+CONFIG_IP_NF_SECURITY=y
62+CONFIG_IP_NF_TARGET_MASQUERADE=y
63+CONFIG_IP_NF_TARGET_NETMAP=y
64+CONFIG_IP_NF_TARGET_REDIRECT=y
65+CONFIG_IP_NF_TARGET_REJECT=y
66+CONFIG_NET=y
67+CONFIG_NETDEVICES=y
68+CONFIG_NETFILTER=y
69+CONFIG_NETFILTER_TPROXY=y
70+CONFIG_NETFILTER_XT_MATCH_COMMENT=y
71+CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=y
72+CONFIG_NETFILTER_XT_MATCH_CONNMARK=y
73+CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
74+CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=y
75+CONFIG_NETFILTER_XT_MATCH_HELPER=y
76+CONFIG_NETFILTER_XT_MATCH_IPRANGE=y
77+CONFIG_NETFILTER_XT_MATCH_LENGTH=y
78+CONFIG_NETFILTER_XT_MATCH_LIMIT=y
79+CONFIG_NETFILTER_XT_MATCH_MAC=y
80+CONFIG_NETFILTER_XT_MATCH_MARK=y
81+CONFIG_NETFILTER_XT_MATCH_PKTTYPE=y
82+CONFIG_NETFILTER_XT_MATCH_POLICY=y
83+CONFIG_NETFILTER_XT_MATCH_QUOTA=y
84+CONFIG_NETFILTER_XT_MATCH_SOCKET=y
85+CONFIG_NETFILTER_XT_MATCH_STATE=y
86+CONFIG_NETFILTER_XT_MATCH_STATISTIC=y
87+CONFIG_NETFILTER_XT_MATCH_STRING=y
88+CONFIG_NETFILTER_XT_MATCH_TIME=y
89+CONFIG_NETFILTER_XT_MATCH_U32=y
90+CONFIG_NETFILTER_XT_TARGET_CLASSIFY=y
91+CONFIG_NETFILTER_XT_TARGET_CONNMARK=y
92+CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y
93+CONFIG_NETFILTER_XT_TARGET_IDLETIMER=y
94+CONFIG_NETFILTER_XT_TARGET_MARK=y
95+CONFIG_NETFILTER_XT_TARGET_NFLOG=y
96+CONFIG_NETFILTER_XT_TARGET_NFQUEUE=y
97+CONFIG_NETFILTER_XT_TARGET_SECMARK=y
98+CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
99+CONFIG_NETFILTER_XT_TARGET_TPROXY=y
100+CONFIG_NETFILTER_XT_TARGET_TRACE=y
101+CONFIG_NET_CLS_ACT=y
102+CONFIG_NET_CLS_U32=y
103+CONFIG_NET_EMATCH=y
104+CONFIG_NET_EMATCH_U32=y
105+CONFIG_NET_KEY=y
106+CONFIG_NET_SCHED=y
107+CONFIG_NET_SCH_HTB=y
108+CONFIG_NF_CONNTRACK=y
109+CONFIG_NF_CONNTRACK_AMANDA=y
110+CONFIG_NF_CONNTRACK_EVENTS=y
111+CONFIG_NF_CONNTRACK_FTP=y
112+CONFIG_NF_CONNTRACK_H323=y
113+CONFIG_NF_CONNTRACK_IPV4=y
114+CONFIG_NF_CONNTRACK_IPV6=y
115+CONFIG_NF_CONNTRACK_IRC=y
116+CONFIG_NF_CONNTRACK_NETBIOS_NS=y
117+CONFIG_NF_CONNTRACK_PPTP=y
118+CONFIG_NF_CONNTRACK_SANE=y
119+CONFIG_NF_CONNTRACK_SECMARK=y
120+CONFIG_NF_CONNTRACK_TFTP=y
121+CONFIG_NF_CT_NETLINK=y
122+CONFIG_NF_CT_PROTO_DCCP=y
123+CONFIG_NF_CT_PROTO_SCTP=y
124+CONFIG_NF_CT_PROTO_UDPLITE=y
125+CONFIG_NF_NAT=y
126+CONFIG_NO_HZ=y
127+CONFIG_PACKET=y
128+CONFIG_PM_AUTOSLEEP=y
129+CONFIG_PM_WAKELOCKS=y
130+CONFIG_PPP=y
131+CONFIG_PPP_BSDCOMP=y
132+CONFIG_PPP_DEFLATE=y
133+CONFIG_PPP_MPPE=y
134+CONFIG_PREEMPT=y
135+CONFIG_QUOTA=y
136+CONFIG_RTC_CLASS=y
137+CONFIG_RT_GROUP_SCHED=y
138+CONFIG_SECURITY=y
139+CONFIG_SECURITY_NETWORK=y
140+CONFIG_SECURITY_SELINUX=y
141+CONFIG_SETEND_EMULATION=y
142+CONFIG_STAGING=y
143+CONFIG_SWP_EMULATION=y
144+CONFIG_SYNC=y
145+CONFIG_TUN=y
146+CONFIG_UNIX=y
147+CONFIG_USB_GADGET=y
148+CONFIG_USB_CONFIGFS=y
149+CONFIG_USB_CONFIGFS_F_FS=y
150+CONFIG_USB_CONFIGFS_F_MIDI=y
151+CONFIG_USB_OTG_WAKELOCK=y
152+CONFIG_XFRM_USER=y
kernel/configs/android-recommended.config+121−0
@@ -0,0 +1,121 @@
1+# KEEP ALPHABETICALLY SORTED
2+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
3+# CONFIG_INPUT_MOUSE is not set
4+# CONFIG_LEGACY_PTYS is not set
5+# CONFIG_NF_CONNTRACK_SIP is not set
6+# CONFIG_PM_WAKELOCKS_GC is not set
7+# CONFIG_VT is not set
8+CONFIG_BACKLIGHT_LCD_SUPPORT=y
9+CONFIG_BLK_DEV_LOOP=y
10+CONFIG_BLK_DEV_RAM=y
11+CONFIG_BLK_DEV_RAM_SIZE=8192
12+CONFIG_COMPACTION=y
13+CONFIG_DEBUG_RODATA=y
14+CONFIG_DM_UEVENT=y
15+CONFIG_DRAGONRISE_FF=y
16+CONFIG_ENABLE_DEFAULT_TRACERS=y
17+CONFIG_EXT4_FS=y
18+CONFIG_EXT4_FS_SECURITY=y
19+CONFIG_FUSE_FS=y
20+CONFIG_GREENASIA_FF=y
21+CONFIG_HIDRAW=y
22+CONFIG_HID_A4TECH=y
23+CONFIG_HID_ACRUX=y
24+CONFIG_HID_ACRUX_FF=y
25+CONFIG_HID_APPLE=y
26+CONFIG_HID_BELKIN=y
27+CONFIG_HID_CHERRY=y
28+CONFIG_HID_CHICONY=y
29+CONFIG_HID_CYPRESS=y
30+CONFIG_HID_DRAGONRISE=y
31+CONFIG_HID_ELECOM=y
32+CONFIG_HID_EMS_FF=y
33+CONFIG_HID_EZKEY=y
34+CONFIG_HID_GREENASIA=y
35+CONFIG_HID_GYRATION=y
36+CONFIG_HID_HOLTEK=y
37+CONFIG_HID_KENSINGTON=y
38+CONFIG_HID_KEYTOUCH=y
39+CONFIG_HID_KYE=y
40+CONFIG_HID_LCPOWER=y
41+CONFIG_HID_LOGITECH=y
42+CONFIG_HID_LOGITECH_DJ=y
43+CONFIG_HID_MAGICMOUSE=y
44+CONFIG_HID_MICROSOFT=y
45+CONFIG_HID_MONTEREY=y
46+CONFIG_HID_MULTITOUCH=y
47+CONFIG_HID_NTRIG=y
48+CONFIG_HID_ORTEK=y
49+CONFIG_HID_PANTHERLORD=y
50+CONFIG_HID_PETALYNX=y
51+CONFIG_HID_PICOLCD=y
52+CONFIG_HID_PRIMAX=y
53+CONFIG_HID_PRODIKEYS=y
54+CONFIG_HID_ROCCAT=y
55+CONFIG_HID_SAITEK=y
56+CONFIG_HID_SAMSUNG=y
57+CONFIG_HID_SMARTJOYPLUS=y
58+CONFIG_HID_SONY=y
59+CONFIG_HID_SPEEDLINK=y
60+CONFIG_HID_SUNPLUS=y
61+CONFIG_HID_THRUSTMASTER=y
62+CONFIG_HID_TIVO=y
63+CONFIG_HID_TOPSEED=y
64+CONFIG_HID_TWINHAN=y
65+CONFIG_HID_UCLOGIC=y
66+CONFIG_HID_WACOM=y
67+CONFIG_HID_WALTOP=y
68+CONFIG_HID_WIIMOTE=y
69+CONFIG_HID_ZEROPLUS=y
70+CONFIG_HID_ZYDACRON=y
71+CONFIG_INPUT_EVDEV=y
72+CONFIG_INPUT_GPIO=y
73+CONFIG_INPUT_JOYSTICK=y
74+CONFIG_INPUT_MISC=y
75+CONFIG_INPUT_TABLET=y
76+CONFIG_INPUT_UINPUT=y
77+CONFIG_ION=y
78+CONFIG_JOYSTICK_XPAD=y
79+CONFIG_JOYSTICK_XPAD_FF=y
80+CONFIG_JOYSTICK_XPAD_LEDS=y
81+CONFIG_KALLSYMS_ALL=y
82+CONFIG_KSM=y
83+CONFIG_LOGIG940_FF=y
84+CONFIG_LOGIRUMBLEPAD2_FF=y
85+CONFIG_LOGITECH_FF=y
86+CONFIG_MD=y
87+CONFIG_MEDIA_SUPPORT=y
88+CONFIG_MSDOS_FS=y
89+CONFIG_PANIC_TIMEOUT=5
90+CONFIG_PANTHERLORD_FF=y
91+CONFIG_PERF_EVENTS=y
92+CONFIG_PM_DEBUG=y
93+CONFIG_PM_RUNTIME=y
94+CONFIG_PM_WAKELOCKS_LIMIT=0
95+CONFIG_POWER_SUPPLY=y
96+CONFIG_PSTORE=y
97+CONFIG_PSTORE_CONSOLE=y
98+CONFIG_PSTORE_RAM=y
99+CONFIG_SCHEDSTATS=y
100+CONFIG_SMARTJOYPLUS_FF=y
101+CONFIG_SND=y
102+CONFIG_SOUND=y
103+CONFIG_SUSPEND_TIME=y
104+CONFIG_TABLET_USB_ACECAD=y
105+CONFIG_TABLET_USB_AIPTEK=y
106+CONFIG_TABLET_USB_GTCO=y
107+CONFIG_TABLET_USB_HANWANG=y
108+CONFIG_TABLET_USB_KBTAB=y
109+CONFIG_TASKSTATS=y
110+CONFIG_TASK_DELAY_ACCT=y
111+CONFIG_TASK_IO_ACCOUNTING=y
112+CONFIG_TASK_XACCT=y
113+CONFIG_TIMER_STATS=y
114+CONFIG_TMPFS=y
115+CONFIG_TMPFS_POSIX_ACL=y
116+CONFIG_UHID=y
117+CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
118+CONFIG_USB_EHCI_HCD=y
119+CONFIG_USB_HIDDEV=y
120+CONFIG_USB_USBNET=y
121+CONFIG_VFAT_FS=y
kernel/events/core.c+1−1
@@ -448,7 +448,7 @@ static u64 __report_allowed; · 447 unmodified lines
448448
449449 static void perf_duration_warn(struct irq_work *w)
450450 {
451− printk_ratelimited(KERN_WARNING
451+ printk_ratelimited(KERN_INFO
452452 "perf: interrupt took too long (%lld > %lld), lowering "
453453 "kernel.perf_event_max_sample_rate to %d\n",
454454 __report_avg, __report_allowed,
kernel/exit.c+1−1
@@ -715,7 +715,7 @@ static void check_stack_usage(void) · 714 unmodified lines
715715
716716 spin_lock(&low_water_lock);
717717 if (free < lowest_to_date) {
718− pr_warn("%s (%d) used greatest stack depth: %lu bytes left\n",
718+ pr_info("%s (%d) used greatest stack depth: %lu bytes left\n",
719719 current->comm, task_pid_nr(current), free);
720720 lowest_to_date = free;
721721 }
kernel/jump_label.c+60−1
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/err.h>
1515 #include <linux/static_key.h>
1616 #include <linux/jump_label_ratelimit.h>
17+#include <linux/bug.h>
1718
1819 #ifdef HAVE_JUMP_LABEL
1920
@@ -56,6 +57,49 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) · 36 unmodified lines
5657
5758 static void jump_label_update(struct static_key *key);
5859
60+/*
61+ * There are similar definitions for the !HAVE_JUMP_LABEL case in jump_label.h.
62+ * The use of 'atomic_read()' requires atomic.h and its problematic for some
63+ * kernel headers such as kernel.h and others. Since static_key_count() is not
64+ * used in the branch statements as it is for the !HAVE_JUMP_LABEL case its ok
65+ * to have it be a function here. Similarly, for 'static_key_enable()' and
66+ * 'static_key_disable()', which require bug.h. This should allow jump_label.h
67+ * to be included from most/all places for HAVE_JUMP_LABEL.
68+ */
69+int static_key_count(struct static_key *key)
70+{
71+ /*
72+ * -1 means the first static_key_slow_inc() is in progress.
73+ * static_key_enabled() must return true, so return 1 here.
74+ */
75+ int n = atomic_read(&key->enabled);
76+
77+ return n >= 0 ? n : 1;
78+}
79+EXPORT_SYMBOL_GPL(static_key_count);
80+
81+void static_key_enable(struct static_key *key)
82+{
83+ int count = static_key_count(key);
84+
85+ WARN_ON_ONCE(count < 0 || count > 1);
86+
87+ if (!count)
88+ static_key_slow_inc(key);
89+}
90+EXPORT_SYMBOL_GPL(static_key_enable);
91+
92+void static_key_disable(struct static_key *key)
93+{
94+ int count = static_key_count(key);
95+
96+ WARN_ON_ONCE(count < 0 || count > 1);
97+
98+ if (count)
99+ static_key_slow_dec(key);
100+}
101+EXPORT_SYMBOL_GPL(static_key_disable);
102+
59103 void static_key_slow_inc(struct static_key *key)
60104 {
61105 int v, v1;
@@ -235,6 +279,18 @@ void __init jump_label_init(void) · 173 unmodified lines
235279 struct static_key *key = NULL;
236280 struct jump_entry *iter;
237281
282+ /*
283+ * Since we are initializing the static_key.enabled field with
284+ * with the 'raw' int values (to avoid pulling in atomic.h) in
285+ * jump_label.h, let's make sure that is safe. There are only two
286+ * cases to check since we initialize to 0 or 1.
287+ */
288+ BUILD_BUG_ON((int)ATOMIC_INIT(0) != 0);
289+ BUILD_BUG_ON((int)ATOMIC_INIT(1) != 1);
290+
291+ if (static_key_initialized)
292+ return;
293+
238294 jump_label_lock();
239295 jump_label_sort_entries(iter_start, iter_stop);
240296
@@ -284,11 +340,14 @@ static int __jump_label_mod_text_reserved(void *start, void *end) · 43 unmodified lines
284340 {
285341 struct module *mod;
286342
343+ preempt_disable();
287344 mod = __module_text_address((unsigned long)start);
345+ WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
346+ preempt_enable();
347+
288348 if (!mod)
289349 return 0;
290350
291− WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
292351
293352 return __jump_label_text_reserved(mod->jump_entries,
294353 mod->jump_entries + mod->num_jump_entries,
kernel/kexec.c+2−1
@@ -48,7 +48,8 @@ static int kimage_alloc_init(struct kimage **rimage, unsigned long entry, · 47 unmodified lines
4848
4949 if (kexec_on_panic) {
5050 /* Verify we have a valid entry point */
51− if ((entry < crashk_res.start) || (entry > crashk_res.end))
51+ if ((entry < phys_to_boot_phys(crashk_res.start)) ||
52+ (entry > phys_to_boot_phys(crashk_res.end)))
5253 return -EADDRNOTAVAIL;
5354 }
5455
kernel/kexec_core.c+45−24
@@ -95,6 +95,12 @@ int kexec_should_crash(struct task_struct *p) · 94 unmodified lines
9595 return 0;
9696 }
9797
98+int kexec_crash_loaded(void)
99+{
100+ return !!kexec_crash_image;
101+}
102+EXPORT_SYMBOL_GPL(kexec_crash_loaded);
103+
98104 /*
99105 * When kexec transitions to the new kernel there is a one-to-one
100106 * mapping between physical and virtual addresses. On processors
@@ -140,6 +146,7 @@ int kexec_should_crash(struct task_struct *p) · 39 unmodified lines
140146 * allocating pages whose destination address we do not care about.
141147 */
142148 #define KIMAGE_NO_DEST (-1UL)
149+#define PAGE_COUNT(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
143150
144151 static struct page *kimage_alloc_page(struct kimage *image,
145152 gfp_t gfp_mask,
@@ -147,8 +154,9 @@ static struct page *kimage_alloc_page(struct kimage *image, · 1 unmodified line
147154
148155 int sanity_check_segment_list(struct kimage *image)
149156 {
150− int result, i;
157+ int i;
151158 unsigned long nr_segments = image->nr_segments;
159+ unsigned long total_pages = 0;
152160
153161 /*
154162 * Verify we have good destination addresses. The caller is
@@ -163,16 +171,17 @@ int sanity_check_segment_list(struct kimage *image) · 8 unmodified lines
163171 * simply because addresses are changed to page size
164172 * granularity.
165173 */
166− result = -EADDRNOTAVAIL;
167174 for (i = 0; i < nr_segments; i++) {
168175 unsigned long mstart, mend;
169176
170177 mstart = image->segment[i].mem;
171178 mend = mstart + image->segment[i].memsz;
179+ if (mstart > mend)
180+ return -EADDRNOTAVAIL;
172181 if ((mstart & ~PAGE_MASK) || (mend & ~PAGE_MASK))
173− return result;
182+ return -EADDRNOTAVAIL;
174183 if (mend >= KEXEC_DESTINATION_MEMORY_LIMIT)
175− return result;
184+ return -EADDRNOTAVAIL;
176185 }
177186
178187 /* Verify our destination addresses do not overlap.
@@ -180,7 +189,6 @@ int sanity_check_segment_list(struct kimage *image) · 1 unmodified line
180189 * through very weird things can happen with no
181190 * easy explanation as one segment stops on another.
182191 */
183− result = -EINVAL;
184192 for (i = 0; i < nr_segments; i++) {
185193 unsigned long mstart, mend;
186194 unsigned long j;
@@ -194,7 +202,7 @@ int sanity_check_segment_list(struct kimage *image) · 7 unmodified lines
194202 pend = pstart + image->segment[j].memsz;
195203 /* Do the segments overlap ? */
196204 if ((mend > pstart) && (mstart < pend))
197− return result;
205+ return -EINVAL;
198206 }
199207 }
200208
@@ -203,12 +211,26 @@ int sanity_check_segment_list(struct kimage *image) · 2 unmodified lines
203211 * and it is easier to check up front than to be surprised
204212 * later on.
205213 */
206− result = -EINVAL;
207214 for (i = 0; i < nr_segments; i++) {
208215 if (image->segment[i].bufsz > image->segment[i].memsz)
209− return result;
216+ return -EINVAL;
217+ }
218+
219+ /*
220+ * Verify that no more than half of memory will be consumed. If the
221+ * request from userspace is too large, a large amount of time will be
222+ * wasted allocating pages, which can cause a soft lockup.
223+ */
224+ for (i = 0; i < nr_segments; i++) {
225+ if (PAGE_COUNT(image->segment[i].memsz) > totalram_pages / 2)
226+ return -EINVAL;
227+
228+ total_pages += PAGE_COUNT(image->segment[i].memsz);
210229 }
211230
231+ if (total_pages > totalram_pages / 2)
232+ return -EINVAL;
233+
212234 /*
213235 * Verify we have good destination addresses. Normally
214236 * the caller is responsible for making certain we don't
@@ -220,16 +242,15 @@ int sanity_check_segment_list(struct kimage *image) · 5 unmodified lines
220242 */
221243
222244 if (image->type == KEXEC_TYPE_CRASH) {
223− result = -EADDRNOTAVAIL;
224245 for (i = 0; i < nr_segments; i++) {
225246 unsigned long mstart, mend;
226247
227248 mstart = image->segment[i].mem;
228249 mend = mstart + image->segment[i].memsz - 1;
229250 /* Ensure we are within the crash kernel limits */
230− if ((mstart < crashk_res.start) ||
231− (mend > crashk_res.end))
232− return result;
251+ if ((mstart < phys_to_boot_phys(crashk_res.start)) ||
252+ (mend > phys_to_boot_phys(crashk_res.end)))
253+ return -EADDRNOTAVAIL;
233254 }
234255 }
235256
@@ -352,7 +373,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image, · 116 unmodified lines
352373 pages = kimage_alloc_pages(KEXEC_CONTROL_MEMORY_GFP, order);
353374 if (!pages)
354375 break;
355− pfn = page_to_pfn(pages);
376+ pfn = page_to_boot_pfn(pages);
356377 epfn = pfn + count;
357378 addr = pfn << PAGE_SHIFT;
358379 eaddr = epfn << PAGE_SHIFT;
@@ -478,7 +499,7 @@ static int kimage_add_entry(struct kimage *image, kimage_entry_t entry) · 119 unmodified lines
478499 return -ENOMEM;
479500
480501 ind_page = page_address(page);
481− *image->entry = virt_to_phys(ind_page) | IND_INDIRECTION;
502+ *image->entry = virt_to_boot_phys(ind_page) | IND_INDIRECTION;
482503 image->entry = ind_page;
483504 image->last_entry = ind_page +
484505 ((PAGE_SIZE/sizeof(kimage_entry_t)) - 1);
@@ -533,13 +554,13 @@ void kimage_terminate(struct kimage *image) · 48 unmodified lines
533554 #define for_each_kimage_entry(image, ptr, entry) \
534555 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); \
535556 ptr = (entry & IND_INDIRECTION) ? \
536− phys_to_virt((entry & PAGE_MASK)) : ptr + 1)
557+ boot_phys_to_virt((entry & PAGE_MASK)) : ptr + 1)
537558
538559 static void kimage_free_entry(kimage_entry_t entry)
539560 {
540561 struct page *page;
541562
542− page = pfn_to_page(entry >> PAGE_SHIFT);
563+ page = boot_pfn_to_page(entry >> PAGE_SHIFT);
543564 kimage_free_pages(page);
544565 }
545566
@@ -633,7 +654,7 @@ static struct page *kimage_alloc_page(struct kimage *image, · 87 unmodified lines
633654 * have a match.
634655 */
635656 list_for_each_entry(page, &image->dest_pages, lru) {
636− addr = page_to_pfn(page) << PAGE_SHIFT;
657+ addr = page_to_boot_pfn(page) << PAGE_SHIFT;
637658 if (addr == destination) {
638659 list_del(&page->lru);
639660 return page;
@@ -648,12 +669,12 @@ static struct page *kimage_alloc_page(struct kimage *image, · 8 unmodified lines
648669 if (!page)
649670 return NULL;
650671 /* If the page cannot be used file it away */
651− if (page_to_pfn(page) >
672+ if (page_to_boot_pfn(page) >
652673 (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) {
653674 list_add(&page->lru, &image->unusable_pages);
654675 continue;
655676 }
656− addr = page_to_pfn(page) << PAGE_SHIFT;
677+ addr = page_to_boot_pfn(page) << PAGE_SHIFT;
657678
658679 /* If it is the destination page we want use it */
659680 if (addr == destination)
@@ -676,7 +697,7 @@ static struct page *kimage_alloc_page(struct kimage *image, · 16 unmodified lines
676697 struct page *old_page;
677698
678699 old_addr = *old & PAGE_MASK;
679− old_page = pfn_to_page(old_addr >> PAGE_SHIFT);
700+ old_page = boot_pfn_to_page(old_addr >> PAGE_SHIFT);
680701 copy_highpage(page, old_page);
681702 *old = addr | (*old & ~PAGE_MASK);
682703
@@ -732,7 +753,7 @@ static int kimage_load_normal_segment(struct kimage *image, · 49 unmodified lines
732753 result = -ENOMEM;
733754 goto out;
734755 }
735− result = kimage_add_page(image, page_to_pfn(page)
756+ result = kimage_add_page(image, page_to_boot_pfn(page)
736757 << PAGE_SHIFT);
737758 if (result < 0)
738759 goto out;
@@ -793,7 +814,7 @@ static int kimage_load_crash_segment(struct kimage *image, · 54 unmodified lines
793814 char *ptr;
794815 size_t uchunk, mchunk;
795816
796− page = pfn_to_page(maddr >> PAGE_SHIFT);
817+ page = boot_pfn_to_page(maddr >> PAGE_SHIFT);
797818 if (!page) {
798819 result = -ENOMEM;
799820 goto out;
@@ -921,7 +942,7 @@ void __weak crash_free_reserved_phys_range(unsigned long begin, · 121 unmodified lines
921942 unsigned long addr;
922943
923944 for (addr = begin; addr < end; addr += PAGE_SIZE)
924− free_reserved_page(pfn_to_page(addr >> PAGE_SHIFT));
945+ free_reserved_page(boot_pfn_to_page(addr >> PAGE_SHIFT));
925946 }
926947
927948 int crash_shrink_memory(unsigned long new_size)
@@ -1374,7 +1395,7 @@ void vmcoreinfo_append_str(const char *fmt, ...) · 446 unmodified lines
13741395 void __weak arch_crash_save_vmcoreinfo(void)
13751396 {}
13761397
1377−unsigned long __weak paddr_vmcoreinfo_note(void)
1398+phys_addr_t __weak paddr_vmcoreinfo_note(void)
13781399 {
13791400 return __pa((unsigned long)(char *)&vmcoreinfo_note);
13801401 }
kernel/ksysfs.c+3−3
@@ -101,7 +101,7 @@ KERNEL_ATTR_RO(kexec_loaded); · 100 unmodified lines
101101 static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
102102 struct kobj_attribute *attr, char *buf)
103103 {
104− return sprintf(buf, "%d\n", !!kexec_crash_image);
104+ return sprintf(buf, "%d\n", kexec_crash_loaded());
105105 }
106106 KERNEL_ATTR_RO(kexec_crash_loaded);
107107
@@ -128,8 +128,8 @@ KERNEL_ATTR_RW(kexec_crash_size); · 20 unmodified lines
128128 static ssize_t vmcoreinfo_show(struct kobject *kobj,
129129 struct kobj_attribute *attr, char *buf)
130130 {
131− return sprintf(buf, "%lx %x\n",
132− paddr_vmcoreinfo_note(),
131+ phys_addr_t vmcore_base = paddr_vmcoreinfo_note();
132+ return sprintf(buf, "%pa %x\n", &vmcore_base,
133133 (unsigned int)sizeof(vmcoreinfo_note));
134134 }
135135 KERNEL_ATTR_RO(vmcoreinfo);
kernel/livepatch/core.c+1−1
@@ -309,7 +309,7 @@ static int klp_write_object_relocations(struct module *pmod, · 308 unmodified lines
309309 break;
310310 }
311311
312− module_enable_ro(pmod);
312+ module_enable_ro(pmod, true);
313313 return ret;
314314 }
315315
kernel/module.c+101−21
@@ -60,6 +60,7 @@ · 59 unmodified lines
6060 #include <linux/jump_label.h>
6161 #include <linux/pfn.h>
6262 #include <linux/bsearch.h>
63+#include <linux/dynamic_debug.h>
6364 #include <uapi/linux/module.h>
6465 #include "module-internal.h"
6566
@@ -264,7 +265,7 @@ static void module_assert_mutex_or_preempt(void) · 198 unmodified lines
264265 if (unlikely(!debug_locks))
265266 return;
266267
267− WARN_ON(!rcu_read_lock_sched_held() &&
268+ WARN_ON_ONCE(!rcu_read_lock_sched_held() &&
268269 !lockdep_is_held(&module_mutex));
269270 #endif
270271 }
@@ -336,7 +337,7 @@ static inline void add_taint_module(struct module *mod, unsigned flag, · 65 unmodified lines
336337 * A thread that wants to hold a reference to a module only while it
337338 * is running can call this to safely exit. nfsd and lockd use this.
338339 */
339−void __module_put_and_exit(struct module *mod, long code)
340+void __noreturn __module_put_and_exit(struct module *mod, long code)
340341 {
341342 module_put(mod);
342343 do_exit(code);
@@ -1693,8 +1694,7 @@ static int module_add_modinfo_attrs(struct module *mod) · 1350 unmodified lines
16931694
16941695 temp_attr = mod->modinfo_attrs;
16951696 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1696− if (!attr->test ||
1697− (attr->test && attr->test(mod))) {
1697+ if (!attr->test || attr->test(mod)) {
16981698 memcpy(temp_attr, attr, sizeof(*temp_attr));
16991699 sysfs_attr_init(&temp_attr->attr);
17001700 error = sysfs_create_file(&mod->mkobj.kobj,
@@ -1858,10 +1858,11 @@ static void mod_sysfs_teardown(struct module *mod) · 157 unmodified lines
18581858 * from modification and any data from execution.
18591859 *
18601860 * General layout of module is:
1861− * [text] [read-only-data] [writable data]
1862− * text_size -----^ ^ ^
1863− * ro_size ------------------------| |
1864− * size -------------------------------------------|
1861+ * [text] [read-only-data] [ro-after-init] [writable data]
1862+ * text_size -----^ ^ ^ ^
1863+ * ro_size ------------------------| | |
1864+ * ro_after_init_size -----------------------------| |
1865+ * size -----------------------------------------------------------|
18651866 *
18661867 * These values are always page-aligned (as is base)
18671868 */
@@ -1884,14 +1885,24 @@ static void frob_rodata(const struct module_layout *layout, · 16 unmodified lines
18841885 (layout->ro_size - layout->text_size) >> PAGE_SHIFT);
18851886 }
18861887
1888+static void frob_ro_after_init(const struct module_layout *layout,
1889+ int (*set_memory)(unsigned long start, int num_pages))
1890+{
1891+ BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1));
1892+ BUG_ON((unsigned long)layout->ro_size & (PAGE_SIZE-1));
1893+ BUG_ON((unsigned long)layout->ro_after_init_size & (PAGE_SIZE-1));
1894+ set_memory((unsigned long)layout->base + layout->ro_size,
1895+ (layout->ro_after_init_size - layout->ro_size) >> PAGE_SHIFT);
1896+}
1897+
18871898 static void frob_writable_data(const struct module_layout *layout,
18881899 int (*set_memory)(unsigned long start, int num_pages))
18891900 {
18901901 BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1));
1891− BUG_ON((unsigned long)layout->ro_size & (PAGE_SIZE-1));
1902+ BUG_ON((unsigned long)layout->ro_after_init_size & (PAGE_SIZE-1));
18921903 BUG_ON((unsigned long)layout->size & (PAGE_SIZE-1));
1893− set_memory((unsigned long)layout->base + layout->ro_size,
1894− (layout->size - layout->ro_size) >> PAGE_SHIFT);
1904+ set_memory((unsigned long)layout->base + layout->ro_after_init_size,
1905+ (layout->size - layout->ro_after_init_size) >> PAGE_SHIFT);
18951906 }
18961907
18971908 /* livepatching wants to disable read-only so it can frob module. */
@@ -1899,21 +1910,26 @@ void module_disable_ro(const struct module *mod) · 1 unmodified line
18991910 {
19001911 frob_text(&mod->core_layout, set_memory_rw);
19011912 frob_rodata(&mod->core_layout, set_memory_rw);
1913+ frob_ro_after_init(&mod->core_layout, set_memory_rw);
19021914 frob_text(&mod->init_layout, set_memory_rw);
19031915 frob_rodata(&mod->init_layout, set_memory_rw);
19041916 }
19051917
1906−void module_enable_ro(const struct module *mod)
1918+void module_enable_ro(const struct module *mod, bool after_init)
19071919 {
19081920 frob_text(&mod->core_layout, set_memory_ro);
19091921 frob_rodata(&mod->core_layout, set_memory_ro);
19101922 frob_text(&mod->init_layout, set_memory_ro);
19111923 frob_rodata(&mod->init_layout, set_memory_ro);
1924+
1925+ if (after_init)
1926+ frob_ro_after_init(&mod->core_layout, set_memory_ro);
19121927 }
19131928
19141929 static void module_enable_nx(const struct module *mod)
19151930 {
19161931 frob_rodata(&mod->core_layout, set_memory_nx);
1932+ frob_ro_after_init(&mod->core_layout, set_memory_nx);
19171933 frob_writable_data(&mod->core_layout, set_memory_nx);
19181934 frob_rodata(&mod->init_layout, set_memory_nx);
19191935 frob_writable_data(&mod->init_layout, set_memory_nx);
@@ -1922,6 +1938,7 @@ static void module_enable_nx(const struct module *mod) · 2 unmodified lines
19221938 static void module_disable_nx(const struct module *mod)
19231939 {
19241940 frob_rodata(&mod->core_layout, set_memory_x);
1941+ frob_ro_after_init(&mod->core_layout, set_memory_x);
19251942 frob_writable_data(&mod->core_layout, set_memory_x);
19261943 frob_rodata(&mod->init_layout, set_memory_x);
19271944 frob_writable_data(&mod->init_layout, set_memory_x);
@@ -1964,6 +1981,8 @@ static void disable_ro_nx(const struct module_layout *layout) · 36 unmodified lines
19641981 frob_text(layout, set_memory_rw);
19651982 frob_rodata(layout, set_memory_rw);
19661983 frob_rodata(layout, set_memory_x);
1984+ frob_ro_after_init(layout, set_memory_rw);
1985+ frob_ro_after_init(layout, set_memory_x);
19671986 frob_writable_data(layout, set_memory_x);
19681987 }
19691988
@@ -2306,6 +2325,7 @@ static void layout_sections(struct module *mod, struct load_info *info) · 336 unmodified lines
23062325 * finder in the two loops below */
23072326 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
23082327 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
2328+ { SHF_RO_AFTER_INIT | SHF_ALLOC, ARCH_SHF_SMALL },
23092329 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
23102330 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
23112331 };
@@ -2337,7 +2357,11 @@ static void layout_sections(struct module *mod, struct load_info *info) · 25 unmodified lines
23372357 mod->core_layout.size = debug_align(mod->core_layout.size);
23382358 mod->core_layout.ro_size = mod->core_layout.size;
23392359 break;
2340− case 3: /* whole core */
2360+ case 2: /* RO after init */
2361+ mod->core_layout.size = debug_align(mod->core_layout.size);
2362+ mod->core_layout.ro_after_init_size = mod->core_layout.size;
2363+ break;
2364+ case 4: /* whole core */
23412365 mod->core_layout.size = debug_align(mod->core_layout.size);
23422366 break;
23432367 }
@@ -2367,7 +2391,14 @@ static void layout_sections(struct module *mod, struct load_info *info) · 23 unmodified lines
23672391 mod->init_layout.size = debug_align(mod->init_layout.size);
23682392 mod->init_layout.ro_size = mod->init_layout.size;
23692393 break;
2370− case 3: /* whole init */
2394+ case 2:
2395+ /*
2396+ * RO after init doesn't apply to init_layout (only
2397+ * core_layout), so it just takes the value of ro_size.
2398+ */
2399+ mod->init_layout.ro_after_init_size = mod->init_layout.ro_size;
2400+ break;
2401+ case 4: /* whole init */
23712402 mod->init_layout.size = debug_align(mod->init_layout.size);
23722403 break;
23732404 }
@@ -2687,13 +2718,18 @@ static inline void kmemleak_load_module(const struct module *mod, · 313 unmodified lines
26872718 #endif
26882719
26892720 #ifdef CONFIG_MODULE_SIG
2690−static int module_sig_check(struct load_info *info)
2721+static int module_sig_check(struct load_info *info, int flags)
26912722 {
26922723 int err = -ENOKEY;
26932724 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
26942725 const void *mod = info->hdr;
26952726
2696− if (info->len > markerlen &&
2727+ /*
2728+ * Require flags == 0, as a module with version information
2729+ * removed is no longer the module that was signed
2730+ */
2731+ if (flags == 0 &&
2732+ info->len > markerlen &&
26972733 memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
26982734 /* We truncate the module to discard the signature */
26992735 info->len -= markerlen;
@@ -2712,7 +2748,7 @@ static int module_sig_check(struct load_info *info) · 12 unmodified lines
27122748 return err;
27132749 }
27142750 #else /* !CONFIG_MODULE_SIG */
2715−static int module_sig_check(struct load_info *info)
2751+static int module_sig_check(struct load_info *info, int flags)
27162752 {
27172753 return 0;
27182754 }
@@ -2920,8 +2956,12 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags) · 201 unmodified lines
29202956 return -ENOEXEC;
29212957 }
29222958
2923− if (!get_modinfo(info, "intree"))
2959+ if (!get_modinfo(info, "intree")) {
2960+ if (!test_taint(TAINT_OOT_MODULE))
2961+ pr_warn("%s: loading out-of-tree module taints kernel.\n",
2962+ mod->name);
29242963 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
2964+ }
29252965
29262966 if (get_modinfo(info, "staging")) {
29272967 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
@@ -3090,6 +3130,8 @@ static int move_module(struct module *mod, struct load_info *info) · 162 unmodified lines
30903130
30913131 static int check_module_license_and_versions(struct module *mod)
30923132 {
3133+ int prev_taint = test_taint(TAINT_PROPRIETARY_MODULE);
3134+
30933135 /*
30943136 * ndiswrapper is under GPL by itself, but loads proprietary modules.
30953137 * Don't use add_taint_module(), as it would prevent ndiswrapper from
@@ -3108,6 +3150,9 @@ static int check_module_license_and_versions(struct module *mod) · 12 unmodified lines
31083150 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
31093151 LOCKDEP_NOW_UNRELIABLE);
31103152
3153+ if (!prev_taint && test_taint(TAINT_PROPRIETARY_MODULE))
3154+ pr_warn("%s: module license taints kernel.\n", mod->name);
3155+
31113156 #ifdef CONFIG_MODVERSIONS
31123157 if ((mod->num_syms && !mod->crcs)
31133158 || (mod->num_gpl_syms && !mod->gpl_crcs)
@@ -3155,16 +3200,41 @@ int __weak module_frob_arch_sections(Elf_Ehdr *hdr, · 41 unmodified lines
31553200 return 0;
31563201 }
31573202
3203+/* module_blacklist is a comma-separated list of module names */
3204+static char *module_blacklist;
3205+static bool blacklisted(char *module_name)
3206+{
3207+ const char *p;
3208+ size_t len;
3209+
3210+ if (!module_blacklist)
3211+ return false;
3212+
3213+ for (p = module_blacklist; *p; p += len) {
3214+ len = strcspn(p, ",");
3215+ if (strlen(module_name) == len && !memcmp(module_name, p, len))
3216+ return true;
3217+ if (p[len] == ',')
3218+ len++;
3219+ }
3220+ return false;
3221+}
3222+core_param(module_blacklist, module_blacklist, charp, 0400);
3223+
31583224 static struct module *layout_and_allocate(struct load_info *info, int flags)
31593225 {
31603226 /* Module within temporary copy. */
31613227 struct module *mod;
3228+ unsigned int ndx;
31623229 int err;
31633230
31643231 mod = setup_load_info(info, flags);
31653232 if (IS_ERR(mod))
31663233 return mod;
31673234
3235+ if (blacklisted(mod->name))
3236+ return ERR_PTR(-EPERM);
3237+
31683238 err = check_modinfo(mod, info, flags);
31693239 if (err)
31703240 return ERR_PTR(err);
@@ -3178,6 +3248,15 @@ static struct module *layout_and_allocate(struct load_info *info, int flags) · 7 unmodified lines
31783248 /* We will do a special allocation for per-cpu sections later. */
31793249 info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC;
31803250
3251+ /*
3252+ * Mark ro_after_init section with SHF_RO_AFTER_INIT so that
3253+ * layout_sections() can put it in the right place.
3254+ * Note: ro_after_init sections also have SHF_{WRITE,ALLOC} set.
3255+ */
3256+ ndx = find_sec(info, ".data..ro_after_init");
3257+ if (ndx)
3258+ info->sechdrs[ndx].sh_flags |= SHF_RO_AFTER_INIT;
3259+
31813260 /* Determine total sizes, and put offsets in sh_entsize. For now
31823261 this is done generically; there doesn't appear to be any
31833262 special cases for the architectures. */
@@ -3344,12 +3423,14 @@ static noinline int do_init_module(struct module *mod) · 160 unmodified lines
33443423 /* Switch to core kallsyms now init is done: kallsyms may be walking! */
33453424 rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms);
33463425 #endif
3426+ module_enable_ro(mod, true);
33473427 mod_tree_remove_init(mod);
33483428 disable_ro_nx(&mod->init_layout);
33493429 module_arch_freeing_init(mod);
33503430 mod->init_layout.base = NULL;
33513431 mod->init_layout.size = 0;
33523432 mod->init_layout.ro_size = 0;
3433+ mod->init_layout.ro_after_init_size = 0;
33533434 mod->init_layout.text_size = 0;
33543435 /*
33553436 * We want to free module_init, but be aware that kallsyms may be
@@ -3441,8 +3522,7 @@ static int complete_formation(struct module *mod, struct load_info *info) · 85 unmodified lines
34413522 /* This relies on module_mutex for list integrity. */
34423523 module_bug_finalize(info->hdr, info->sechdrs, mod);
34433524
3444− /* Set RO and NX regions */
3445− module_enable_ro(mod);
3525+ module_enable_ro(mod, false);
34463526 module_enable_nx(mod);
34473527
34483528 /* Mark state as coming so strong_try_module_get() ignores us,
@@ -3498,7 +3578,7 @@ static int load_module(struct load_info *info, const char __user *uargs, · 49 unmodified lines
34983578 long err;
34993579 char *after_dashes;
35003580
3501− err = module_sig_check(info);
3581+ err = module_sig_check(info, flags);
35023582 if (err)
35033583 goto free_copy;
35043584
kernel/panic.c+4−9
@@ -108,6 +108,7 @@ void panic(const char *fmt, ...) · 107 unmodified lines
108108 long i, i_next = 0;
109109 int state = 0;
110110 int old_cpu, this_cpu;
111+ bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers;
111112
112113 /*
113114 * Disable local interrupts. This will prevent panic_smp_self_stop
@@ -160,7 +161,7 @@ void panic(const char *fmt, ...) · 46 unmodified lines
160161 *
161162 * Bypass the panic_cpu check and call __crash_kexec directly.
162163 */
163− if (!crash_kexec_post_notifiers) {
164+ if (!_crash_kexec_post_notifiers) {
164165 printk_nmi_flush_on_panic();
165166 __crash_kexec(NULL);
166167 }
@@ -191,7 +192,7 @@ void panic(const char *fmt, ...) · 24 unmodified lines
191192 *
192193 * Bypass the panic_cpu check and call __crash_kexec directly.
193194 */
194− if (crash_kexec_post_notifiers)
195+ if (_crash_kexec_post_notifiers)
195196 __crash_kexec(NULL);
196197
197198 bust_spinlocks(0);
@@ -571,13 +572,7 @@ EXPORT_SYMBOL(__stack_chk_fail); · 373 unmodified lines
571572 core_param(panic, panic_timeout, int, 0644);
572573 core_param(pause_on_oops, pause_on_oops, int, 0644);
573574 core_param(panic_on_warn, panic_on_warn, int, 0644);
574−
575−static int __init setup_crash_kexec_post_notifiers(char *s)
576−{
577− crash_kexec_post_notifiers = true;
578− return 0;
579−}
580−early_param("crash_kexec_post_notifiers", setup_crash_kexec_post_notifiers);
575+core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644);
581576
582577 static int __init oops_setup(char *s)
583578 {
kernel/printk/printk.c+154−16
@@ -26,7 +26,6 @@ · 25 unmodified lines
2626 #include <linux/nmi.h>
2727 #include <linux/module.h>
2828 #include <linux/moduleparam.h>
29−#include <linux/interrupt.h> /* For in_interrupt() */
3029 #include <linux/delay.h>
3130 #include <linux/smp.h>
3231 #include <linux/security.h>
@@ -48,7 +47,7 @@ · 15 unmodified lines
4847 #include <linux/uio.h>
4948
5049 #include <asm/uaccess.h>
51−#include <asm-generic/sections.h>
50+#include <asm/sections.h>
5251
5352 #define CREATE_TRACE_POINTS
5453 #include <trace/events/printk.h>
@@ -86,6 +85,111 @@ static struct lockdep_map console_lock_dep_map = { · 31 unmodified lines
8685 };
8786 #endif
8887
88+enum devkmsg_log_bits {
89+ __DEVKMSG_LOG_BIT_ON = 0,
90+ __DEVKMSG_LOG_BIT_OFF,
91+ __DEVKMSG_LOG_BIT_LOCK,
92+};
93+
94+enum devkmsg_log_masks {
95+ DEVKMSG_LOG_MASK_ON = BIT(__DEVKMSG_LOG_BIT_ON),
96+ DEVKMSG_LOG_MASK_OFF = BIT(__DEVKMSG_LOG_BIT_OFF),
97+ DEVKMSG_LOG_MASK_LOCK = BIT(__DEVKMSG_LOG_BIT_LOCK),
98+};
99+
100+/* Keep both the 'on' and 'off' bits clear, i.e. ratelimit by default: */
101+#define DEVKMSG_LOG_MASK_DEFAULT 0
102+
103+static unsigned int __read_mostly devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
104+
105+static int __control_devkmsg(char *str)
106+{
107+ if (!str)
108+ return -EINVAL;
109+
110+ if (!strncmp(str, "on", 2)) {
111+ devkmsg_log = DEVKMSG_LOG_MASK_ON;
112+ return 2;
113+ } else if (!strncmp(str, "off", 3)) {
114+ devkmsg_log = DEVKMSG_LOG_MASK_OFF;
115+ return 3;
116+ } else if (!strncmp(str, "ratelimit", 9)) {
117+ devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
118+ return 9;
119+ }
120+ return -EINVAL;
121+}
122+
123+static int __init control_devkmsg(char *str)
124+{
125+ if (__control_devkmsg(str) < 0)
126+ return 1;
127+
128+ /*
129+ * Set sysctl string accordingly:
130+ */
131+ if (devkmsg_log == DEVKMSG_LOG_MASK_ON) {
132+ memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
133+ strncpy(devkmsg_log_str, "on", 2);
134+ } else if (devkmsg_log == DEVKMSG_LOG_MASK_OFF) {
135+ memset(devkmsg_log_str, 0, DEVKMSG_STR_MAX_SIZE);
136+ strncpy(devkmsg_log_str, "off", 3);
137+ }
138+ /* else "ratelimit" which is set by default. */
139+
140+ /*
141+ * Sysctl cannot change it anymore. The kernel command line setting of
142+ * this parameter is to force the setting to be permanent throughout the
143+ * runtime of the system. This is a precation measure against userspace
144+ * trying to be a smarta** and attempting to change it up on us.
145+ */
146+ devkmsg_log |= DEVKMSG_LOG_MASK_LOCK;
147+
148+ return 0;
149+}
150+__setup("printk.devkmsg=", control_devkmsg);
151+
152+char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE] = "ratelimit";
153+
154+int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write,
155+ void __user *buffer, size_t *lenp, loff_t *ppos)
156+{
157+ char old_str[DEVKMSG_STR_MAX_SIZE];
158+ unsigned int old;
159+ int err;
160+
161+ if (write) {
162+ if (devkmsg_log & DEVKMSG_LOG_MASK_LOCK)
163+ return -EINVAL;
164+
165+ old = devkmsg_log;
166+ strncpy(old_str, devkmsg_log_str, DEVKMSG_STR_MAX_SIZE);
167+ }
168+
169+ err = proc_dostring(table, write, buffer, lenp, ppos);
170+ if (err)
171+ return err;
172+
173+ if (write) {
174+ err = __control_devkmsg(devkmsg_log_str);
175+
176+ /*
177+ * Do not accept an unknown string OR a known string with
178+ * trailing crap...
179+ */
180+ if (err < 0 || (err + 1 != *lenp)) {
181+
182+ /* ... and restore old setting. */
183+ devkmsg_log = old;
184+ strncpy(devkmsg_log_str, old_str, DEVKMSG_STR_MAX_SIZE);
185+
186+ return -EINVAL;
187+ }
188+ }
189+
190+ return 0;
191+}
192+
89193 /*
90194 * Number of registered extended console drivers.
91195 *
@@ -614,6 +718,7 @@ struct devkmsg_user { · 522 unmodified lines
614718 u64 seq;
615719 u32 idx;
616720 enum log_flags prev;
721+ struct ratelimit_state rs;
617722 struct mutex lock;
618723 char buf[CONSOLE_EXT_LOG_MAX];
619724 };
@@ -623,11 +728,24 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from) · 3 unmodified lines
623728 char *buf, *line;
624729 int level = default_message_loglevel;
625730 int facility = 1; /* LOG_USER */
731+ struct file *file = iocb->ki_filp;
732+ struct devkmsg_user *user = file->private_data;
626733 size_t len = iov_iter_count(from);
627734 ssize_t ret = len;
628735
629− if (len > LOG_LINE_MAX)
736+ if (!user || len > LOG_LINE_MAX)
630737 return -EINVAL;
738+
739+ /* Ignore when user logging is disabled. */
740+ if (devkmsg_log & DEVKMSG_LOG_MASK_OFF)
741+ return len;
742+
743+ /* Ratelimit when not explicitly enabled. */
744+ if (!(devkmsg_log & DEVKMSG_LOG_MASK_ON)) {
745+ if (!___ratelimit(&user->rs, current->comm))
746+ return ret;
747+ }
748+
631749 buf = kmalloc(len+1, GFP_KERNEL);
632750 if (buf == NULL)
633751 return -ENOMEM;
@@ -800,19 +918,24 @@ static int devkmsg_open(struct inode *inode, struct file *file) · 166 unmodified lines
800918 struct devkmsg_user *user;
801919 int err;
802920
803− /* write-only does not need any file context */
804− if ((file->f_flags & O_ACCMODE) == O_WRONLY)
805− return 0;
921+ if (devkmsg_log & DEVKMSG_LOG_MASK_OFF)
922+ return -EPERM;
806923
807− err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
808− SYSLOG_FROM_READER);
809− if (err)
810− return err;
924+ /* write-only does not need any file context */
925+ if ((file->f_flags & O_ACCMODE) != O_WRONLY) {
926+ err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
927+ SYSLOG_FROM_READER);
928+ if (err)
929+ return err;
930+ }
811931
812932 user = kmalloc(sizeof(struct devkmsg_user), GFP_KERNEL);
813933 if (!user)
814934 return -ENOMEM;
815935
936+ ratelimit_default_init(&user->rs);
937+ ratelimit_set_flags(&user->rs, RATELIMIT_MSG_ON_RELEASE);
938+
816939 mutex_init(&user->lock);
817940
818941 raw_spin_lock_irq(&logbuf_lock);
@@ -831,6 +954,8 @@ static int devkmsg_release(struct inode *inode, struct file *file) · 12 unmodified lines
831954 if (!user)
832955 return 0;
833956
957+ ratelimit_state_exit(&user->rs);
958+
834959 mutex_destroy(&user->lock);
835960 kfree(user);
836961 return 0;
@@ -986,6 +1111,11 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR); · 149 unmodified lines
9861111 MODULE_PARM_DESC(ignore_loglevel,
9871112 "ignore loglevel setting (prints all kernel messages to the console)");
9881113
1114+static bool suppress_message_printing(int level)
1115+{
1116+ return (level >= console_loglevel && !ignore_loglevel);
1117+}
1118+
9891119 #ifdef CONFIG_BOOT_PRINTK_DELAY
9901120
9911121 static int boot_delay; /* msecs delay after each printk during bootup */
@@ -1015,7 +1145,7 @@ static void boot_delay_msec(int level) · 23 unmodified lines
10151145 unsigned long timeout;
10161146
10171147 if ((boot_delay == 0 || system_state != SYSTEM_BOOTING)
1018− || (level >= console_loglevel && !ignore_loglevel)) {
1148+ || suppress_message_printing(level)) {
10191149 return;
10201150 }
10211151
@@ -1439,8 +1569,6 @@ static void call_console_drivers(int level, · 417 unmodified lines
14391569
14401570 trace_console(text, len);
14411571
1442− if (level >= console_loglevel && !ignore_loglevel)
1443− return;
14441572 if (!console_drivers)
14451573 return;
14461574
@@ -1888,6 +2016,7 @@ static void call_console_drivers(int level, · 441 unmodified lines
18882016 static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev,
18892017 bool syslog, char *buf, size_t size) { return 0; }
18902018 static size_t cont_print_text(char *text, size_t size) { return 0; }
2019+static bool suppress_message_printing(int level) { return false; }
18912020
18922021 /* Still needs to be defined for users */
18932022 DEFINE_PER_CPU(printk_func_t, printk_func);
@@ -2167,6 +2296,13 @@ static void console_cont_flush(char *text, size_t size) · 273 unmodified lines
21672296 if (!cont.len)
21682297 goto out;
21692298
2299+ if (suppress_message_printing(cont.level)) {
2300+ cont.cons = cont.len;
2301+ if (cont.flushed)
2302+ cont.len = 0;
2303+ goto out;
2304+ }
2305+
21702306 /*
21712307 * We still queue earlier records, likely because the console was
21722308 * busy. The earlier ones need to be printed before this one, we
@@ -2270,10 +2406,13 @@ skip: · 97 unmodified lines
22702406 break;
22712407
22722408 msg = log_from_idx(console_idx);
2273− if (msg->flags & LOG_NOCONS) {
2409+ level = msg->level;
2410+ if ((msg->flags & LOG_NOCONS) ||
2411+ suppress_message_printing(level)) {
22742412 /*
22752413 * Skip record we have buffered and already printed
2276− * directly to the console when we received it.
2414+ * directly to the console when we received it, and
2415+ * record that has level above the console loglevel.
22772416 */
22782417 console_idx = log_next(console_idx);
22792418 console_seq++;
@@ -2287,7 +2426,6 @@ skip: · 7 unmodified lines
22872426 goto skip;
22882427 }
22892428
2290− level = msg->level;
22912429 len += msg_print_text(msg, console_prev, false,
22922430 text + len, sizeof(text) - len);
22932431 if (nr_ext_console_drivers) {
kernel/ptrace.c+2−2
@@ -585,8 +585,8 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data) · 584 unmodified lines
585585 return -EINVAL;
586586
587587 if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) {
588− if (!config_enabled(CONFIG_CHECKPOINT_RESTORE) ||
589− !config_enabled(CONFIG_SECCOMP))
588+ if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) ||
589+ !IS_ENABLED(CONFIG_SECCOMP))
590590 return -EINVAL;
591591
592592 if (!capable(CAP_SYS_ADMIN))
kernel/relay.c+32−2
@@ -451,6 +451,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu) · 450 unmodified lines
451451 if (!dentry)
452452 goto free_buf;
453453 relay_set_buf_dentry(buf, dentry);
454+ } else {
455+ /* Only retrieve global info, nothing more, nothing less */
456+ dentry = chan->cb->create_buf_file(NULL, NULL,
457+ S_IRUSR, buf,
458+ &chan->is_global);
459+ if (WARN_ON(dentry))
460+ goto free_buf;
454461 }
455462
456463 buf->cpu = cpu;
@@ -562,6 +569,10 @@ static int relay_hotcpu_callback(struct notifier_block *nb, · 105 unmodified lines
562569 * attributes specified. The created channel buffer files
563570 * will be named base_filename0...base_filenameN-1. File
564571 * permissions will be %S_IRUSR.
572+ *
573+ * If opening a buffer (@parent = NULL) that you later wish to register
574+ * in a filesystem, call relay_late_setup_files() once the @parent dentry
575+ * is available.
565576 */
566577 struct rchan *relay_open(const char *base_filename,
567578 struct dentry *parent,
@@ -640,8 +651,12 @@ static void __relay_set_buf_dentry(void *info) · 72 unmodified lines
640651 *
641652 * Returns 0 if successful, non-zero otherwise.
642653 *
643− * Use to setup files for a previously buffer-only channel.
644− * Useful to do early tracing in kernel, before VFS is up, for example.
654+ * Use to setup files for a previously buffer-only channel created
655+ * by relay_open() with a NULL parent dentry.
656+ *
657+ * For example, this is useful for perfomring early tracing in kernel,
658+ * before VFS is up and then exposing the early results once the dentry
659+ * is available.
645660 */
646661 int relay_late_setup_files(struct rchan *chan,
647662 const char *base_filename,
@@ -666,6 +681,20 @@ int relay_late_setup_files(struct rchan *chan, · 18 unmodified lines
666681 }
667682 chan->has_base_filename = 1;
668683 chan->parent = parent;
684+
685+ if (chan->is_global) {
686+ err = -EINVAL;
687+ if (!WARN_ON_ONCE(!chan->buf[0])) {
688+ dentry = relay_create_buf_file(chan, chan->buf[0], 0);
689+ if (dentry && !WARN_ON_ONCE(!chan->is_global)) {
690+ relay_set_buf_dentry(chan->buf[0], dentry);
691+ err = 0;
692+ }
693+ }
694+ mutex_unlock(&relay_channels_mutex);
695+ return err;
696+ }
697+
669698 curr_cpu = get_cpu();
670699 /*
671700 * The CPU hotplug notifier ran before us and created buffers with
@@ -706,6 +735,7 @@ int relay_late_setup_files(struct rchan *chan, · 34 unmodified lines
706735
707736 return err;
708737 }
738+EXPORT_SYMBOL_GPL(relay_late_setup_files);
709739
710740 /**
711741 * relay_switch_subbuf - switch to a new sub-buffer
kernel/seccomp.c+3−3
@@ -347,7 +347,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog) · 346 unmodified lines
347347 {
348348 struct seccomp_filter *sfilter;
349349 int ret;
350− const bool save_orig = config_enabled(CONFIG_CHECKPOINT_RESTORE);
350+ const bool save_orig = IS_ENABLED(CONFIG_CHECKPOINT_RESTORE);
351351
352352 if (fprog->len == 0 || fprog->len > BPF_MAXINSNS)
353353 return ERR_PTR(-EINVAL);
@@ -542,7 +542,7 @@ void secure_computing_strict(int this_syscall) · 188 unmodified lines
542542 {
543543 int mode = current->seccomp.mode;
544544
545− if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
545+ if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
546546 unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
547547 return;
548548
@@ -655,7 +655,7 @@ int __secure_computing(const struct seccomp_data *sd) · 106 unmodified lines
655655 int mode = current->seccomp.mode;
656656 int this_syscall;
657657
658− if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
658+ if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) &&
659659 unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
660660 return 0;
661661
kernel/sysctl.c+7−0
@@ -813,6 +813,13 @@ static struct ctl_table kern_table[] = { · 812 unmodified lines
813813 .extra1 = &zero,
814814 .extra2 = &ten_thousand,
815815 },
816+ {
817+ .procname = "printk_devkmsg",
818+ .data = devkmsg_log_str,
819+ .maxlen = DEVKMSG_STR_MAX_SIZE,
820+ .mode = 0644,
821+ .proc_handler = devkmsg_sysctl_set_loglvl,
822+ },
816823 {
817824 .procname = "dmesg_restrict",
818825 .data = &dmesg_restrict,
kernel/task_work.c+6−4
@@ -29,7 +29,7 @@ task_work_add(struct task_struct *task, struct callback_head *work, bool notify) · 28 unmodified lines
2929 struct callback_head *head;
3030
3131 do {
32− head = ACCESS_ONCE(task->task_works);
32+ head = READ_ONCE(task->task_works);
3333 if (unlikely(head == &work_exited))
3434 return -ESRCH;
3535 work->next = head;
@@ -57,6 +57,9 @@ task_work_cancel(struct task_struct *task, task_work_func_t func) · 21 unmodified lines
5757 struct callback_head **pprev = &task->task_works;
5858 struct callback_head *work;
5959 unsigned long flags;
60+
61+ if (likely(!task->task_works))
62+ return NULL;
6063 /*
6164 * If cmpxchg() fails we continue without updating pprev.
6265 * Either we raced with task_work_add() which added the
@@ -64,8 +67,7 @@ task_work_cancel(struct task_struct *task, task_work_func_t func) · 1 unmodified line
6467 * we raced with task_work_run(), *pprev == NULL/exited.
6568 */
6669 raw_spin_lock_irqsave(&task->pi_lock, flags);
67− while ((work = ACCESS_ONCE(*pprev))) {
68− smp_read_barrier_depends();
70+ while ((work = lockless_dereference(*pprev))) {
6971 if (work->func != func)
7072 pprev = &work->next;
7173 else if (cmpxchg(pprev, work, work->next) == work)
@@ -95,7 +97,7 @@ void task_work_run(void) · 23 unmodified lines
9597 * work_exited unless the list is empty.
9698 */
9799 do {
98− work = ACCESS_ONCE(task->task_works);
100+ work = READ_ONCE(task->task_works);
99101 head = !work && (task->flags & PF_EXITING) ?
100102 &work_exited : NULL;
101103 } while (cmpxchg(&task->task_works, work, head) != work);
kernel/trace/Makefile+4−0
@@ -1,4 +1,8 @@
11
2+# We are fully aware of the dangers of __builtin_return_address()
3+FRAME_CFLAGS := $(call cc-disable-warning,frame-address)
4+KBUILD_CFLAGS += $(FRAME_CFLAGS)
5+
26 # Do not instrument the tracer itself:
37
48 ifdef CONFIG_FUNCTION_TRACER
kernel/trace/blktrace.c+3−3
@@ -776,7 +776,7 @@ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, · 775 unmodified lines
776776 return;
777777
778778 __blk_add_trace(bt, bio->bi_iter.bi_sector, bio->bi_iter.bi_size,
779− bio_op(bio), bio->bi_rw, what, error, 0, NULL);
779+ bio_op(bio), bio->bi_opf, what, error, 0, NULL);
780780 }
781781
782782 static void blk_add_trace_bio_bounce(void *ignore,
@@ -881,7 +881,7 @@ static void blk_add_trace_split(void *ignore, · 98 unmodified lines
881881 __be64 rpdu = cpu_to_be64(pdu);
882882
883883 __blk_add_trace(bt, bio->bi_iter.bi_sector,
884− bio->bi_iter.bi_size, bio_op(bio), bio->bi_rw,
884+ bio->bi_iter.bi_size, bio_op(bio), bio->bi_opf,
885885 BLK_TA_SPLIT, bio->bi_error, sizeof(rpdu),
886886 &rpdu);
887887 }
@@ -915,7 +915,7 @@ static void blk_add_trace_bio_remap(void *ignore, · 27 unmodified lines
915915 r.sector_from = cpu_to_be64(from);
916916
917917 __blk_add_trace(bt, bio->bi_iter.bi_sector, bio->bi_iter.bi_size,
918− bio_op(bio), bio->bi_rw, BLK_TA_REMAP, bio->bi_error,
918+ bio_op(bio), bio->bi_opf, BLK_TA_REMAP, bio->bi_error,
919919 sizeof(r), &r);
920920 }
921921
kernel/trace/trace_events_hist.c+7−7
@@ -1441,6 +1441,9 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, · 1440 unmodified lines
14411441 goto out;
14421442 }
14431443
1444+ if (hist_data->attrs->pause)
1445+ data->paused = true;
1446+
14441447 if (named_data) {
14451448 destroy_hist_data(data->private_data);
14461449 data->private_data = named_data->private_data;
@@ -1448,9 +1451,6 @@ static int hist_register_trigger(char *glob, struct event_trigger_ops *ops, · 1 unmodified line
14481451 data->ops = &event_hist_trigger_named_ops;
14491452 }
14501453
1451− if (hist_data->attrs->pause)
1452− data->paused = true;
1453−
14541454 if (data->ops->init) {
14551455 ret = data->ops->init(data->ops, data);
14561456 if (ret < 0)
@@ -1500,9 +1500,9 @@ static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops, · 43 unmodified lines
15001500
15011501 static void hist_unreg_all(struct trace_event_file *file)
15021502 {
1503− struct event_trigger_data *test;
1503+ struct event_trigger_data *test, *n;
15041504
1505− list_for_each_entry_rcu(test, &file->triggers, list) {
1505+ list_for_each_entry_safe(test, n, &file->triggers, list) {
15061506 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
15071507 list_del_rcu(&test->list);
15081508 trace_event_trigger_enable_disable(file, 0);
@@ -1699,9 +1699,9 @@ hist_enable_get_trigger_ops(char *cmd, char *param) · 190 unmodified lines
16991699
17001700 static void hist_enable_unreg_all(struct trace_event_file *file)
17011701 {
1702− struct event_trigger_data *test;
1702+ struct event_trigger_data *test, *n;
17031703
1704− list_for_each_entry_rcu(test, &file->triggers, list) {
1704+ list_for_each_entry_safe(test, n, &file->triggers, list) {
17051705 if (test->cmd_ops->trigger_type == ETT_HIST_ENABLE) {
17061706 list_del_rcu(&test->list);
17071707 update_cond_flag(file);