3.16.83-rc1 review
Subsystems (6)
PATCH 146/245 USB: core: add endpoint-blacklist quirk
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 73f8bda9b5dc1c69df2bc55c0cbb24461a6391a9 upstream.
Add a new device quirk that can be used to blacklist endpoints.
Since commit 3e4f8e21c4f2 ("USB: core: fix check for duplicate endpoints") USB core ignores any duplicate endpoints found during descriptor parsing.
In order to handle devices where the first interfaces with duplicate endpoints are the ones that should have their endpoints ignored, we need to add a blacklist.
--- drivers/usb/core/config.c | 11 +++++++++++ drivers/usb/core/quirks.c | 32 ++++++++++++++++++++++++++++++++ drivers/usb/core/usb.h | 3 +++ include/linux/usb/quirks.h | 3 +++ 4 files changed, 49 insertions(+)
drivers/usb/core/config.c +11 -0
@@ -222,6 +222,7 @@ static int usb_parse_endpoint(struct dev struct usb_host_interface *ifp, int num_ep, unsigned char *buffer, int size) { + struct usb_device *udev = to_usb_device(ddev);unsigned char *buffer0 = buffer;struct usb_endpoint_descriptor *d;struct usb_host_endpoint *endpoint;
@@ -263,6 +264,16 @@ static int usb_parse_endpoint(struct dev goto skip_to_next_endpoint_or_interface_descriptor; } +/* Ignore blacklisted endpoints */ +if (udev->quirks &USB_QUIRK_ENDPOINT_BLACKLIST ) { +if (usb_endpoint_is_blacklisted (udev, ifp, d)) { +dev_warn (ddev,"config %d interface %d altsetting %d has a blacklisted endpoint with address 0x%X, skipping\n" , + cfgno, inum, asnum, + d->bEndpointAddress); + goto skip_to_next_endpoint_or_interface_descriptor; + } + } + endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints]; ++ifp->desc.bNumEndpoints;
drivers/usb/core/quirks.c +32 -0
@@ -318,6 +318,38 @@ static const struct usb_device_id usb_am { }/* terminating entry must be last */ }; +/* +* Entries for blacklisted endpoints that should be ignored when parsing +* configuration descriptors. +* +* Matched for devices with USB_QUIRK_ENDPOINT_BLACKLIST. +*/ +static const struct usb_device_id usb_endpoint_blacklist[] = { + { } +}; + +bool usb_endpoint_is_blacklisted (struct usb_device *udev, +struct usb_host_interface *intf, +struct usb_endpoint_descriptor *epd) +{ +const struct usb_device_id *id; +unsigned int address; + +for (id = usb_endpoint_blacklist; id->match_flags; ++id) { +if (!usb_match_device (udev, id)) +continue ; + +if (!usb_match_one_id_intf (udev, intf, id)) +continue ; + + address = id->driver_info; +if (address == epd->bEndpointAddress) +return true; + } + +return false; +} +static bool usb_match_any_interface (struct usb_device *udev,const struct usb_device_id *id) {
drivers/usb/core/usb.h +3 -0
@@ -29,6 +29,9 @@ extern int usb_deauthorize_device(structextern int usb_authorize_device (struct usb_device *);extern void usb_detect_quirks (struct usb_device *udev);extern void usb_detect_interface_quirks (struct usb_device *udev); +extern bool usb_endpoint_is_blacklisted (struct usb_device *udev, +struct usb_host_interface *intf, +struct usb_endpoint_descriptor *epd);extern int usb_remove_device (struct usb_device *udev); extern int usb_get_device_descriptor(struct usb_device *dev,
include/linux/usb/quirks.h +3 -0
@@ -62,4 +62,7 @@/* Hub needs extra delay after resetting its port. */ #define USB_QUIRK_HUB_SLOW_RESET BIT(14) +/* device has blacklisted endpoints */ +#define USB_QUIRK_ENDPOINT_BLACKLIST BIT(15) +#endif /* __LINUX_USB_QUIRKS_H */
PATCH 147/245 USB: quirks: blacklist duplicate ep on Sound Devices USBPre2
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit bdd1b147b8026df0e4260b387026b251d888ed01 upstream.
This device has a broken vendor-specific altsetting for interface 1, where endpoint 0x85 is declared as an isochronous endpoint despite being used by interface 2 for audio capture.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0x0926
idProduct 0x0202
bcdDevice 1.00
iManufacturer 1 Sound Devices iProduct 2 USBPre2 iSerial 3 [...] bNumConfigurations 1
[...]
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 3
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0126 1x 294 bytes
bInterval 1
[...]
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 4
bDelay 1 frames
wFormatTag 0x0001 PCM
AudioStreaming Interface Descriptor:
bLength 26
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 6 Discrete
tSamFreq[ 0] 8000
tSamFreq[ 1] 16000
tSamFreq[ 2] 24000
tSamFreq[ 3] 32000
tSamFreq[ 4] 44100
tSamFreq[ 5] 48000
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x0126 1x 294 bytes
bInterval 4
bRefresh 0
bSynchAddress 0
AudioStreaming Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 2 Decoded PCM samples
wLockDelay 0x0000
Since commit 3e4f8e21c4f2 ("USB: core: fix check for duplicate endpoints") USB core ignores any duplicate endpoints found during descriptor parsing, but in this case we need to ignore the first instance in order to avoid breaking the audio capture interface.
--- drivers/usb/core/quirks.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/core/quirks.c +5 -0
@@ -206,6 +206,10 @@ static const struct usb_device_id usb_qu { USB_DEVICE(0x0904, 0x6103), .driver_info = USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL }, + /* Sound Devices USBPre2 */ + { USB_DEVICE(0x0926, 0x0202), .driver_info = + USB_QUIRK_ENDPOINT_BLACKLIST }, + /* Keytouch QWERTY Panel keyboard */ { USB_DEVICE(0x0926, 0x3333), .driver_info = USB_QUIRK_CONFIG_INTF_STRINGS },
@@ -325,6 +329,7 @@ static const struct usb_device_id usb_am* Matched for devices with USB_QUIRK_ENDPOINT_BLACKLIST. */ static const struct usb_device_id usb_endpoint_blacklist[] = { + {USB_DEVICE_INTERFACE_NUMBER (0x0926 ,0x0202 ,1 ), .driver_info =0x85 }, { } };
PATCH 148/245 usb: musb: dma: Correct parameter passed to IRQ handler
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paul Cercueil <[email protected]>
commit c80d0f4426c7fdc7efd6ae8d8b021dcfc89b4254 upstream.
The IRQ handler was passed a pointer to a struct dma_controller, but the argument was then casted to a pointer to a struct musb_dma_controller.
--- drivers/usb/musb/musbhsdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/musbhsdma.c +1 -1
@@ -396,7 +396,7 @@ struct dma_controller *dma_controller_cr controller->controller.channel_abort = dma_channel_abort;if (request_irq (irq, dma_controller_irq,0 , -dev_name (musb->controller), &controller->controller)) { +dev_name (musb->controller), controller)) {dev_err (dev,"request_irq %d failed!\n" , irq);dma_controller_destroy (&controller->controller);
PATCH 149/245 can: gs_usb: gs_usb_probe(): use descriptors of current altsetting
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 2f361cd9474ab2c4ab9ac8db20faf81e66c6279b upstream.
Make sure to always use the descriptors of the current alternate setting to avoid future issues when accessing fields that may differ between settings.
--- drivers/net/can/usb/gs_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/can/usb/gs_usb.c +2 -2
@@ -846,7 +846,7 @@ static int gs_usb_probe(struct usb_interGS_USB_BREQ_HOST_FORMAT ,USB_DIR_OUT |USB_TYPE_VENDOR |USB_RECIP_INTERFACE ,1 , - intf->altsetting[0 ].desc.bInterfaceNumber, + intf->cur_altsetting->desc.bInterfaceNumber, hconf,sizeof (*hconf), 1000);
@@ -869,7 +869,7 @@ static int gs_usb_probe(struct usb_interGS_USB_BREQ_DEVICE_CONFIG ,USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_INTERFACE ,1 , - intf->altsetting[0 ].desc.bInterfaceNumber, + intf->cur_altsetting->desc.bInterfaceNumber, dconf,sizeof (*dconf), 1000);
PATCH 150/245 can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Faber <[email protected]>
commit 2d77bd61a2927be8f4e00d9478fe6996c47e8d45 upstream.
Under load, the RX side of the mscan driver can get stuck while TX still works. Restarting the interface locks up the system. This behaviour could be reproduced reliably on a MPC5121e based system.
The patch fixes the return value of the NAPI polling function (should be the number of processed packets, not constant 1) and the condition under which IRQs are enabled again after polling is finished.
With this patch, no more lockups were observed over a test period of ten days.
--- drivers/net/can/mscan/mscan.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/net/can/mscan/mscan.c +10 -11
@@ -412,13 +412,12 @@ static int mscan_rx_poll(struct napi_strstruct net_device *dev = napi->dev;struct mscan_regs __iomem *regs = priv->reg_base;struct net_device_stats *stats = &dev->stats; -int npackets =0 ; -int ret =1 ; +int work_done =0 ;struct sk_buff *skb;struct can_frame *frame;u8 canrflg; -while (npackets < quota) { +while (work_done < quota) { canrflg =in_8 (®s->canrflg);if (!(canrflg & (MSCAN_RXF |MSCAN_ERR_IF )))break ;
@@ -439,18 +438,18 @@ static int mscan_rx_poll(struct napi_str stats->rx_packets++; stats->rx_bytes += frame->can_dlc; - npackets++; + work_done++;netif_receive_skb (skb); } -if (!(in_8 (®s->canrflg) & (MSCAN_RXF |MSCAN_ERR_IF ))) { -napi_complete (&priv->napi); -clear_bit (F_RX_PROGRESS , &priv->flags); -if (priv->can.state <CAN_STATE_BUS_OFF ) -out_8 (®s->canrier, priv->shadow_canrier); - ret =0 ; +if (work_done < quota) { +if (likely (napi_complete_done (&priv->napi, work_done))) { +clear_bit (F_RX_PROGRESS , &priv->flags); +if (priv->can.state <CAN_STATE_BUS_OFF ) +out_8 (®s->canrier, priv->shadow_canrier); + } } -return ret; +return work_done; }static irqreturn_t mscan_isr (int irq,void *dev_id)
PATCH 151/245 tcp: fix "old stuff" D-SACK causing SACK to be treated as D-SACK
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Pengcheng Yang <[email protected]>
commit c9655008e7845bcfdaac10a1ed8554ec167aea88 upstream.
When we receive a D-SACK, where the sequence number satisfies:
undo_marker <= start_seq < end_seq <= prior_snd_una
we consider this is a valid D-SACK and tcp_is_sackblock_valid() returns true, then this D-SACK is discarded as "old stuff", but the variable first_sack_index is not marked as negative in tcp_sacktag_write_queue().
If this D-SACK also carries a SACK that needs to be processed (for example, the previous SACK segment was lost), this SACK will be treated as a D-SACK in the following processing of tcp_sacktag_write_queue(), which will eventually lead to incorrect updates of undo_retrans and reordering.
--- net/ipv4/tcp_input.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +4 -1
@@ -1713,8 +1713,11 @@ tcp_sacktag_write_queue(struct sock *sk, }/* Ignore very old stuff early */ -if (!after (sp[used_sacks].end_seq, prior_snd_una)) +if (!after (sp[used_sacks].end_seq, prior_snd_una)) { +if (i ==0 ) + first_sack_index =-1 ;continue ; + } used_sacks++; }
PATCH 152/245 vxlan: fix tos value before xmit
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hangbin Liu <[email protected]>
commit 71130f29979c7c7956b040673e6b9d5643003176 upstream.
Before ip_tunnel_ecn_encap() and udp_tunnel_xmit_skb() we should filter tos value by RT_TOS() instead of using config tos directly.
vxlan_get_route() would filter the tos to fl4.flowi4_tos but we didn't return it back, as geneve_get_v4_rt() did. So we have to use RT_TOS() directly in function ip_tunnel_ecn_encap().
--- drivers/net/vxlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/vxlan.c +1 -1
@@ -1904,7 +1904,7 @@ static void vxlan_xmit_one(struct sk_bufreturn ; } - tos =ip_tunnel_ecn_encap (tos, old_iph, skb); + tos =ip_tunnel_ecn_encap (RT_TOS (tos), old_iph, skb); ttl = ttl ? :ip4_dst_hoplimit (&rt->dst); err = vxlan_xmit_skb(vxlan->vn_sock, rt, skb,
PATCH 153/245 tracing: Have stack tracer compile when MCOUNT_INSN_SIZE is not defined
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Steven Rostedt (VMware)" <[email protected]>
commit b8299d362d0837ae39e87e9019ebe6b736e0f035 upstream.
On some archs with some configurations, MCOUNT_INSN_SIZE is not defined, and this makes the stack tracer fail to compile. Just define it to zero in this case.
--- kernel/trace/trace_stack.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/trace/trace_stack.c +5 -0
@@ -182,6 +182,11 @@ check_stack(unsigned long ip, unsigned llocal_irq_restore (flags); } +/* Some archs may not define MCOUNT_INSN_SIZE */ +#ifndef MCOUNT_INSN_SIZE +# define MCOUNT_INSN_SIZE 0 +#endif +static void stack_trace_call (unsigned long ip,unsigned long parent_ip,struct ftrace_ops *op,struct pt_regs *pt_regs)
PATCH 154/245 ftrace: Avoid potential division by zero in function profiler
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wen Yang <[email protected]>
commit e31f7939c1c27faa5d0e3f14519eaf7c89e8a69d upstream.
The ftrace_profile->counter is unsigned long and do_div truncates it to 32 bits, which means it can test non-zero and be truncated to zero for division. Fix this issue by using div64_ul() instead.
--- kernel/trace/ftrace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +3 -3
@@ -595,8 +595,7 @@ static int function_stat_show(struct seq#ifdef CONFIG_FUNCTION_GRAPH_TRACER seq_printf (m," " ); - avg = rec->time; -do_div (avg, rec->counter); + avg =div64_ul (rec->time, rec->counter);/* Sample standard deviation (s^2) */ if (rec->counter <=1 )
@@ -613,7 +612,8 @@ static int function_stat_show(struct seq* Divide only 1000 for ns^2 -> us^2 conversion. * trace_print_graph_duration will divide 1000 again. */ -do_div (stddev, rec->counter * (rec->counter -1 ) *1000 ); + stddev =div64_ul (stddev, + rec->counter * (rec->counter -1 ) *1000 ); }trace_seq_init (&s);
PATCH 155/245 staging: rtl8188eu: Add device code for TP-Link TL-WN727N v5.21
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michael Straube <[email protected]>
commit 58dcc5bf4030cab548d5c98cd4cd3632a5444d5a upstream.
This device was added to the stand-alone driver on github. Add it to the staging driver as well.
--- drivers/staging/rtl8188eu/os_dep/usb_intf.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/rtl8188eu/os_dep/usb_intf.c +1 -0
@@ -61,6 +61,7 @@ static struct usb_device_id rtw_usb_id_t {USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */ {USB_DEVICE(0x2001, 0x331B)}, /* D-Link DWA-121 rev B1 */ {USB_DEVICE(0x2357, 0x010c)}, /* TP-Link TL-WN722N v2 */ + {USB_DEVICE(0x2357, 0x0111)}, /* TP-Link TL-WN727N v5.21 */ {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */ {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xffef)}, /* Rosewill RNX-N150NUB */ {} /* Terminating entry */
PATCH 156/245 kernel/trace: Fix do not unregister tracepoints when register sched_migrate_task fail
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kaitao Cheng <[email protected]>
commit 50f9ad607ea891a9308e67b81f774c71736d1098 upstream.
In the function, if register_trace_sched_migrate_task() returns error, sched_switch/sched_wakeup_new/sched_wakeup won't unregister. That is why fail_deprobe_sched_switch was added.
--- kernel/trace/trace_sched_wakeup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_sched_wakeup.c +3 -1
@@ -567,7 +567,7 @@ static void start_wakeup_tracer(struct tif (ret) {pr_info ("wakeup trace: Couldn't activate tracepoint" " probe to kernel_sched_migrate_task\n" ); -return ; + goto fail_deprobe_sched_switch; }wakeup_reset (tr);
@@ -585,6 +585,8 @@ static void start_wakeup_tracer(struct tprintk (KERN_ERR "failed to start wakeup tracer\n" );return ; +fail_deprobe_sched_switch: +unregister_trace_sched_switch (probe_wakeup_sched_switch,NULL ); fail_deprobe_wake_new:unregister_trace_sched_wakeup_new (probe_wakeup,NULL ); fail_deprobe:
PATCH 157/245 kobject: Export kobject_get_unless_zero()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit c70c176ff8c3ff0ac6ef9a831cd591ea9a66bd1a upstream.
Make the function available for outside use and fortify it against NULL kobject.
--- include/linux/kobject.h | 2 ++ lib/kobject.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/linux/kobject.h +2 -0
@@ -107,6 +107,8 @@ extern int __must_check kobject_rename(sextern int __must_check kobject_move (struct kobject *,struct kobject *);extern struct kobject *kobject_get (struct kobject *kobj); +extern struct kobject *__must_check kobject_get_unless_zero ( +struct kobject *kobj);extern void kobject_put (struct kobject *kobj);extern const void *kobject_namespace (struct kobject *kobj);
lib/kobject.c +4 -1
@@ -581,12 +581,15 @@ struct kobject *kobject_get(struct kobjereturn kobj; } -static struct kobject *__must_check kobject_get_unless_zero (struct kobject *kobj) +struct kobject *__must_check kobject_get_unless_zero (struct kobject *kobj) { +if (!kobj) +return NULL ;if (!kref_get_unless_zero (&kobj->kref)) kobj =NULL ;return kobj; } +EXPORT_SYMBOL (kobject_get_unless_zero);/* * kobject_cleanup - free kobject resources.
PATCH 158/245 chardev: Avoid potential use-after-free in 'chrdev_open()'
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit 68faa679b8be1a74e6663c21c3a9d25d32f1c079 upstream.
'chrdev_open()' calls 'cdev_get()' to obtain a reference to the 'struct cdev *' stashed in the 'i_cdev' field of the target inode structure. If the pointer is NULL, then it is initialised lazily by looking up the kobject in the 'cdev_map' and so the whole procedure is protected by the 'cdev_lock' spinlock to serialise initialisation of the shared pointer.
Unfortunately, it is possible for the initialising thread to fail *after* installing the new pointer, for example if the subsequent '->open()' call on the file fails. In this case, 'cdev_put()' is called, the reference count on the kobject is dropped and, if nobody else has taken a reference, the release function is called which finally clears 'inode->i_cdev' from 'cdev_purge()' before potentially freeing the object. The problem here is that a racing thread can happily take the 'cdev_lock' and see the non-NULL pointer in the inode, which can result in a refcount increment from zero and a warning:
| ------------[ cut here ]------------ | refcount_t: addition on 0; use-after-free. | WARNING: CPU: 2 PID: 6385 at lib/refcount.c:25 refcount_warn_saturate+0x6d/0xf0 | Modules linked in: | CPU: 2 PID: 6385 Comm: repro Not tainted 5.5.0-rc2+ #22 | Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 | RIP: 0010:refcount_warn_saturate+0x6d/0xf0 | Code: 05 55 9a 15 01 01 e8 9d aa c8 ff 0f 0b c3 80 3d 45 9a 15 01 00 75 ce 48 c7 c7 00 9c 62 b3 c6 08 | RSP: 0018:ffffb524c1b9bc70 EFLAGS: 00010282 | RAX: 0000000000000000 RBX: ffff9e9da1f71390 RCX: 0000000000000000 | RDX: ffff9e9dbbd27618 RSI: ffff9e9dbbd18798 RDI: ffff9e9dbbd18798 | RBP: 0000000000000000 R08: 000000000000095f R09: 0000000000000039 | R10: 0000000000000000 R11: ffffb524c1b9bb20 R12: ffff9e9da1e8c700 | R13: ffffffffb25ee8b0 R14: 0000000000000000 R15: ffff9e9da1e8c700 | FS: 00007f3b87d26700(0000) GS:ffff9e9dbbd00000(0000) knlGS:0000000000000000 | CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 | CR2: 00007fc16909c000 CR3: 000000012df9c000 CR4: 00000000000006e0 | DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 | DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 | Call Trace: | kobject_get+0x5c/0x60 | cdev_get+0x2b/0x60 | chrdev_open+0x55/0x220 | ? cdev_put.part.3+0x20/0x20 | do_dentry_open+0x13a/0x390 | path_openat+0x2c8/0x1470 | do_filp_open+0x93/0x100 | ? selinux_file_ioctl+0x17f/0x220 | do_sys_open+0x186/0x220 | do_syscall_64+0x48/0x150 | entry_SYSCALL_64_after_hwframe+0x44/0xa9 | RIP: 0033:0x7f3b87efcd0e | Code: 89 54 24 08 e8 a3 f4 ff ff 8b 74 24 0c 48 8b 3c 24 41 89 c0 44 8b 54 24 08 b8 01 01 00 00 89 f4 | RSP: 002b:00007f3b87d259f0 EFLAGS: 00000293 ORIG_RAX: 0000000000000101 | RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f3b87efcd0e | RDX: 0000000000000000 RSI: 00007f3b87d25a80 RDI: 00000000ffffff9c | RBP: 00007f3b87d25e90 R08: 0000000000000000 R09: 0000000000000000 | R10: 0000000000000000 R11: 0000000000000293 R12: 00007ffe188f504e | R13: 00007ffe188f504f R14: 00007f3b87d26700 R15: 0000000000000000 | ---[ end trace 24f53ca58db8180a ]---
Since 'cdev_get()' can already fail to obtain a reference, simply move it over to use 'kobject_get_unless_zero()' instead of 'kobject_get()', which will cause the racing thread to return -ENXIO if the initialising thread fails unexpectedly.
--- fs/char_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/char_dev.c +1 -1
@@ -348,7 +348,7 @@ static struct kobject *cdev_get(struct cif (owner && !try_module_get (owner))return NULL ; - kobj =kobject_get (&p->kobj); + kobj =kobject_get_unless_zero (&p->kobj);if (!kobj)module_put (owner);return kobj;
PATCH 159/245 sctp: free cmd->obj.chunk for the unprocessed SCTP_CMD_REPLY
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit be7a7729207797476b6666f046d765bdf9630407 upstream.
This patch is to fix a memleak caused by no place to free cmd->obj.chunk for the unprocessed SCTP_CMD_REPLY. This issue occurs when failing to process a cmd while there're still SCTP_CMD_REPLY cmds on the cmd seq with an allocated chunk in cmd->obj.chunk.
So fix it by freeing cmd->obj.chunk for each SCTP_CMD_REPLY cmd left on the cmd seq when any cmd returns error. While at it, also remove 'nomem' label.
--- net/sctp/sm_sideeffect.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
net/sctp/sm_sideeffect.c +18 -10
@@ -1327,8 +1327,10 @@ static int sctp_cmd_interpreter(sctp_eve/* Generate an INIT ACK chunk. */ new_obj =sctp_make_init_ack (asoc, chunk,GFP_ATOMIC ,0 ); -if (!new_obj) - goto nomem; +if (!new_obj) { + error = -ENOMEM ; +break ; + }sctp_add_cmd_sf (commands,SCTP_CMD_REPLY ,SCTP_CHUNK (new_obj));
@@ -1350,7 +1352,8 @@ static int sctp_cmd_interpreter(sctp_eveif (!new_obj) {if (cmd->obj.chunk)sctp_chunk_free (cmd->obj.chunk); - goto nomem; + error = -ENOMEM ; +break ; }sctp_add_cmd_sf (commands,SCTP_CMD_REPLY ,SCTP_CHUNK (new_obj));
@@ -1397,8 +1400,10 @@ static int sctp_cmd_interpreter(sctp_eve/* Generate a SHUTDOWN chunk. */ new_obj =sctp_make_shutdown (asoc, chunk); -if (!new_obj) - goto nomem; +if (!new_obj) { + error = -ENOMEM ; +break ; + }sctp_add_cmd_sf (commands,SCTP_CMD_REPLY ,SCTP_CHUNK (new_obj));break ;
@@ -1727,11 +1732,17 @@ static int sctp_cmd_interpreter(sctp_evebreak ; } -if (error) +if (error) { + cmd =sctp_next_cmd (commands); +while (cmd) { +if (cmd->verb ==SCTP_CMD_REPLY ) +sctp_chunk_free (cmd->obj.chunk); + cmd =sctp_next_cmd (commands); + }break ; + } } -out:/* If this is in response to a received chunk, wait until * we are done with the packet to open the queue so that we don't * send multiple packets in response to a single request.
@@ -1742,8 +1753,5 @@ out: }else if (local_cork) error =sctp_outq_uncork (&asoc->outqueue);return error; -nomem: - error = -ENOMEM ; - goto out; }
PATCH 160/245 vlan: vlan_changelink() should propagate errors
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit eb8ef2a3c50092bb018077c047b8dba1ce0e78e3 upstream.
Both vlan_dev_change_flags() and vlan_dev_set_egress_priority() can return an error. vlan_changelink() should not ignore them.
--- net/8021q/vlan_netlink.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/8021q/vlan_netlink.c +7 -3
@@ -92,11 +92,13 @@ static int vlan_changelink(struct net_destruct ifla_vlan_flags *flags;struct ifla_vlan_qos_mapping *m;struct nlattr *attr; -int rem; +int rem, err;if (data[IFLA_VLAN_FLAGS ]) { flags =nla_data (data[IFLA_VLAN_FLAGS ]); -vlan_dev_change_flags (dev, flags->flags, flags->mask); + err =vlan_dev_change_flags (dev, flags->flags, flags->mask); +if (err) +return err; }if (data[IFLA_VLAN_INGRESS_QOS ]) {nla_for_each_nested (attr, data[IFLA_VLAN_INGRESS_QOS ], rem) {
@@ -107,7 +109,9 @@ static int vlan_changelink(struct net_deif (data[IFLA_VLAN_EGRESS_QOS ]) {nla_for_each_nested (attr, data[IFLA_VLAN_EGRESS_QOS ], rem) { m =nla_data (attr); -vlan_dev_set_egress_priority (dev, m->from, m->to); + err =vlan_dev_set_egress_priority (dev, m->from, m->to); +if (err) +return err; } }return 0 ;
PATCH 161/245 net: stmmac: dwmac-sunxi: Allow all RGMII modes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
commit 52cc73e5404c7ba0cbfc50cb4c265108c84b3d5a upstream.
Allow all the RGMII modes to be used. This would allow us to represent the hardware better in the device tree with RGMII_ID where in most cases the PHY's internal delay for both RX and TX are used.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c +1 -1
@@ -78,7 +78,7 @@ static int sun7i_gmac_init(struct platfo* rate, which then uses the auto-reparenting feature of the * clock driver, and enabling/disabling the clock. */ -if (gmac->interface ==PHY_INTERFACE_MODE_RGMII ) { +if (phy_interface_mode_is_rgmii (gmac->interface)) {clk_set_rate (gmac->tx_clk,SUN7I_GMAC_GMII_RGMII_RATE );clk_prepare_enable (gmac->tx_clk); gmac->clk_enabled =1 ;
PATCH 162/245 pkt_sched: fq: avoid hang when quantum 0
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kenneth Klette Jonassen <[email protected]>
commit 3725a269815ba6dbb415feddc47da5af7d1fac58 upstream.
Configuring fq with quantum 0 hangs the system, presumably because of a non-interruptible infinite loop. Either way quantum 0 does not make sense.
Reproduce with:
sudo tc qdisc add dev lo root fq quantum 0 initial_quantum 0 ping 127.0.0.1
--- net/sched/sch_fq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/sched/sch_fq.c +8 -2
@@ -687,8 +687,14 @@ static int fq_change(struct Qdisc *sch,if (tb[TCA_FQ_FLOW_PLIMIT ]) q->flow_plimit =nla_get_u32 (tb[TCA_FQ_FLOW_PLIMIT ]); -if (tb[TCA_FQ_QUANTUM ]) - q->quantum =nla_get_u32 (tb[TCA_FQ_QUANTUM ]); +if (tb[TCA_FQ_QUANTUM ]) { +u32 quantum =nla_get_u32 (tb[TCA_FQ_QUANTUM ]); + +if (quantum >0 ) + q->quantum = quantum; +else + err = -EINVAL ; + }if (tb[TCA_FQ_INITIAL_QUANTUM ]) q->initial_quantum =nla_get_u32 (tb[TCA_FQ_INITIAL_QUANTUM ]);
PATCH 163/245 pkt_sched: fq: do not accept silly TCA_FQ_QUANTUM
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit d9e15a2733067c9328fb56d98fe8e574fa19ec31 upstream.
As diagnosed by Florian :
If TCA_FQ_QUANTUM is set to 0x80000000, fq_deueue() can loop forever in :
if (f->credit <= 0) {
f->credit += q->quantum;
goto begin;
}
... because f->credit is either 0 or -2147483648.
Let's limit TCA_FQ_QUANTUM to no more than 1 << 20 :
This max value should limit risks of breaking user setups while fixing this bug.
[bwh: Backported to 3.16: Drop call to NL_SET_ERR_MSG_MOD() as extack is
not supported.]
---
net/sched/sch_fq.c +1 -1
@@ -690,7 +690,7 @@ static int fq_change(struct Qdisc *sch,if (tb[TCA_FQ_QUANTUM ]) {u32 quantum =nla_get_u32 (tb[TCA_FQ_QUANTUM ]); -if (quantum >0 ) +if (quantum >0 && quantum <= (1 <<20 )) q->quantum = quantum;else err = -EINVAL ;
PATCH 164/245 macvlan: do not assume mac_header is set in macvlan_broadcast()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 96cc4b69581db68efc9749ef32e9cf8e0160c509 upstream.
Use of eth_hdr() in tx path is error prone.
Many drivers call skb_reset_mac_header() before using it, but others do not.
Commit 6d1ccff62780 ("net: reset mac header in dev_start_xmit()") attempted to fix this generically, but commit d346a3fae3ff ("packet: introduce PACKET_QDISC_BYPASS socket option") brought back the macvlan bug.
Lets add a new helper, so that tx paths no longer have to call skb_reset_mac_header() only to get a pointer to skb->data.
Hopefully we will be able to revert 6d1ccff62780
("net: reset mac header in dev_start_xmit()") and save few cycles in transmit fast path.
BUG: KASAN: use-after-free in __get_unaligned_cpu32 include/linux/unaligned/packed_struct.h:19 [inline]
BUG: KASAN: use-after-free in mc_hash drivers/net/macvlan.c:251 [inline]
BUG: KASAN: use-after-free in macvlan_broadcast+0x547/0x620 drivers/net/macvlan.c:277
Read of size 4 at addr ffff8880a4932401 by task syz-executor947/9579
CPU: 0 PID: 9579 Comm: syz-executor947 Not tainted 5.5.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x197/0x210 lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374
__kasan_report.cold+0x1b/0x41 mm/kasan/report.c:506
kasan_report+0x12/0x20 mm/kasan/common.c:639
__asan_report_load_n_noabort+0xf/0x20 mm/kasan/generic_report.c:145
__get_unaligned_cpu32 include/linux/unaligned/packed_struct.h:19 [inline]
mc_hash drivers/net/macvlan.c:251 [inline]
macvlan_broadcast+0x547/0x620 drivers/net/macvlan.c:277
macvlan_queue_xmit drivers/net/macvlan.c:520 [inline]
macvlan_start_xmit+0x402/0x77f drivers/net/macvlan.c:559
__netdev_start_xmit include/linux/netdevice.h:4447 [inline]
netdev_start_xmit include/linux/netdevice.h:4461 [inline]
dev_direct_xmit+0x419/0x630 net/core/dev.c:4079
packet_direct_xmit+0x1a9/0x250 net/packet/af_packet.c:240
packet_snd net/packet/af_packet.c:2966 [inline]
packet_sendmsg+0x260d/0x6220 net/packet/af_packet.c:2991
sock_sendmsg_nosec net/socket.c:639 [inline]
sock_sendmsg+0xd7/0x130 net/socket.c:659
__sys_sendto+0x262/0x380 net/socket.c:1985
__do_sys_sendto net/socket.c:1997 [inline]
__se_sys_sendto net/socket.c:1993 [inline]
__x64_sys_sendto+0xe1/0x1a0 net/socket.c:1993
do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x442639
Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 5b 10 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffc13549e08 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000442639
RDX: 000000000000000e RSI: 0000000020000080 RDI: 0000000000000003
RBP: 0000000000000004 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000403bb0 R14: 0000000000000000 R15: 0000000000000000
Allocated by task 9389:
save_stack+0x23/0x90 mm/kasan/common.c:72
set_track mm/kasan/common.c:80 [inline]
__kasan_kmalloc mm/kasan/common.c:513 [inline]
__kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:486
kasan_kmalloc+0x9/0x10 mm/kasan/common.c:527
__do_kmalloc mm/slab.c:3656 [inline]
__kmalloc+0x163/0x770 mm/slab.c:3665
kmalloc include/linux/slab.h:561 [inline]
tomoyo_realpath_from_path+0xc5/0x660 security/tomoyo/realpath.c:252
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x230/0x430 security/tomoyo/file.c:822
tomoyo_inode_getattr+0x1d/0x30 security/tomoyo/tomoyo.c:129
security_inode_getattr+0xf2/0x150 security/security.c:1222
vfs_getattr+0x25/0x70 fs/stat.c:115
vfs_statx_fd+0x71/0xc0 fs/stat.c:145
vfs_fstat include/linux/fs.h:3265 [inline]
__do_sys_newfstat+0x9b/0x120 fs/stat.c:378
__se_sys_newfstat fs/stat.c:375 [inline]
__x64_sys_newfstat+0x54/0x80 fs/stat.c:375
do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Freed by task 9389:
save_stack+0x23/0x90 mm/kasan/common.c:72
set_track mm/kasan/common.c:80 [inline]
kasan_set_free_info mm/kasan/common.c:335 [inline]
__kasan_slab_free+0x102/0x150 mm/kasan/common.c:474
kasan_slab_free+0xe/0x10 mm/kasan/common.c:483
__cache_free mm/slab.c:3426 [inline]
kfree+0x10a/0x2c0 mm/slab.c:3757
tomoyo_realpath_from_path+0x1a7/0x660 security/tomoyo/realpath.c:289
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x230/0x430 security/tomoyo/file.c:822
tomoyo_inode_getattr+0x1d/0x30 security/tomoyo/tomoyo.c:129
security_inode_getattr+0xf2/0x150 security/security.c:1222
vfs_getattr+0x25/0x70 fs/stat.c:115
vfs_statx_fd+0x71/0xc0 fs/stat.c:145
vfs_fstat include/linux/fs.h:3265 [inline]
__do_sys_newfstat+0x9b/0x120 fs/stat.c:378
__se_sys_newfstat fs/stat.c:375 [inline]
__x64_sys_newfstat+0x54/0x80 fs/stat.c:375
do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
entry_SYSCALL_64_after_hwframe+0x49/0xbe
The buggy address belongs to the object at ffff8880a4932000
which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 1025 bytes inside of
4096-byte region [ffff8880a4932000, ffff8880a4933000)
The buggy address belongs to the page:
page:ffffea0002924c80 refcount:1 mapcount:0 mapping:ffff8880aa402000 index:0x0 compound_mapcount: 0
raw: 00fffe0000010200 ffffea0002846208 ffffea00028f3888 ffff8880aa402000
raw: 0000000000000000 ffff8880a4932000 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8880a4932300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a4932380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8880a4932400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880a4932480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880a4932500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb--- drivers/net/macvlan.c | 2 +- include/linux/if_ether.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/macvlan.c +1 -1
@@ -162,7 +162,7 @@ static void macvlan_broadcast(struct sk_ struct net_device *src, enum macvlan_mode mode) { -const struct ethhdr *eth =eth_hdr (skb); +const struct ethhdr *eth =skb_eth_hdr (skb);const struct macvlan_dev *vlan;struct sk_buff *nskb;unsigned int i;
include/linux/if_ether.h +8 -0
@@ -28,6 +28,14 @@ static inline struct ethhdr *eth_hdr(conreturn (struct ethhdr *)skb_mac_header (skb); } +/* Prefer this version in TX path, instead of +* skb_reset_mac_header() + eth_hdr() +*/ +static inline struct ethhdr *skb_eth_hdr (const struct sk_buff *skb) +{ +return (struct ethhdr *)skb->data; +} +int eth_header_parse (const struct sk_buff *skb,unsigned char *haddr);extern ssize_t sysfs_format_mac (char *buf,const unsigned char *addr,int len);
PATCH 165/245 netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 22dad713b8a5ff488e07b821195270672f486eb2 upstream.
The set uadt functions assume lineno is never NULL, but it is in case of ip_set_utest().
syzkaller managed to generate a netlink message that calls this with LINENO attr present:
general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: 0010:hash_mac4_uadt+0x1bc/0x470 net/netfilter/ipset/ip_set_hash_mac.c:104 Call Trace: ip_set_utest+0x55b/0x890 net/netfilter/ipset/ip_set_core.c:1867 nfnetlink_rcv_msg+0xcf2/0xfb0 net/netfilter/nfnetlink.c:229 netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477 nfnetlink_rcv+0x1ba/0x460 net/netfilter/nfnetlink.c:563
pass a dummy lineno storage, its easier than patching all set implementations.
This seems to be a day-0 bug.
--- net/netfilter/ipset/ip_set_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_core.c +2 -1
@@ -1549,6 +1549,7 @@ ip_set_utest(struct sock *ctnl, struct sstruct ip_set *set;struct nlattr *tb[IPSET_ATTR_ADT_MAX +1 ] = {};int ret =0 ; +u32 lineno; if (unlikely(protocol_failed(attr) || attr[IPSET_ATTR_SETNAME] == NULL ||
@@ -1565,7 +1566,7 @@ ip_set_utest(struct sock *ctnl, struct sreturn -IPSET_ERR_PROTOCOL ;read_lock_bh (&set->lock); - ret = set->variant->uadt (set, tb,IPSET_TEST ,NULL ,0 ,0 ); + ret = set->variant->uadt (set, tb,IPSET_TEST , &lineno,0 ,0 );read_unlock_bh (&set->lock);/* Userspace can't trigger element to be re-added */ if (ret == -EAGAIN )
PATCH 166/245 ixgbevf: Remove limit of 10 entries for unicast filter list
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Radoslaw Tyl <[email protected]>
commit aa604651d523b1493988d0bf6710339f3ee60272 upstream.
Currently, though the FDB entry is added to VF, it does not appear in RAR filters. VF driver only allows to add 10 entries. Attempting to add another causes an error. This patch removes limitation and allows use of all free RAR entries for the FDB if needed.
--- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -5
@@ -1465,11 +1465,6 @@ static int ixgbevf_write_uc_addr_list(ststruct ixgbe_hw *hw = &adapter->hw;int count =0 ; -if ((netdev_uc_count (netdev)) >10 ) { -pr_err ("Too many unicast filters - No Space\n" ); -return -ENOSPC ; - } -if (!netdev_uc_empty (netdev)) {struct netdev_hw_addr *ha;netdev_for_each_uc_addr (ha, netdev) {
PATCH 167/245 scsi: sd: Clear sdkp->protection_type if disk is reformatted without PI
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Chen <[email protected]>
commit 465f4edaecc6c37f81349233e84d46246bcac11a upstream.
If an attached disk with protection information enabled is reformatted to Type 0 the revalidation code does not clear the original protection type and subsequent accesses will keep setting RDPROTECT/WRPROTECT.
Set the protection type to 0 if the disk reports PROT_EN=0 in READ CAPACITY(16).
[mkp: commit desc]
--- drivers/scsi/sd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +3 -1
@@ -1910,8 +1910,10 @@ static int sd_read_protection_type(strucu8 type;int ret =0 ; -if (scsi_device_protection (sdp) ==0 || (buffer[12 ] &1 ) ==0 ) +if (scsi_device_protection (sdp) ==0 || (buffer[12 ] &1 ) ==0 ) { + sdkp->protection_type =0 ;return ret; + } type = ((buffer[12 ] >>1 ) &7 ) +1 ;/* P_TYPE 0 = Type 1 */
PATCH 168/245 scsi: enclosure: Fix stale device oops with hot replug
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: James Bottomley <[email protected]>
commit 529244bd1afc102ab164429d338d310d5d65e60d upstream.
Doing an add/remove/add on a SCSI device in an enclosure leads to an oops caused by poisoned values in the enclosure device list pointers. The reason is because we are keeping the enclosure device across the enclosed device add/remove/add but the current code is doing a device_add/device_del/device_add on it. This is the wrong thing to do in sysfs, so fix it by not doing a device_del on the enclosure device simply because of a hot remove of the drive in the slot.
[mkp: added missing email addresses]
--- drivers/misc/enclosure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/enclosure.c +1 -2
@@ -364,10 +364,9 @@ int enclosure_remove_device(struct enclo cdev = &edev->component[i];if (cdev->dev == dev) {enclosure_remove_links (cdev); -device_del (&cdev->cdev);put_device (dev); cdev->dev =NULL ; -return device_add (&cdev->cdev); +return 0 ; } }return -ENODEV ;
PATCH 169/245 hidraw: Return EPOLLOUT from hidraw_poll
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Fabian Henneke <[email protected]>
commit 378b80370aa1fe50f9c48a3ac8af3e416e73b89f upstream.
Always return EPOLLOUT from hidraw_poll when a device is connected. This is safe since writes are always possible (but will always block).
hidraw does not support non-blocking writes and instead always calls blocking backend functions on write requests. Hence, so far, a call to poll never returned EPOLLOUT, which confuses tools like socat.
In-reply-to: <CA+hv5qkyis03CgYTWeWX9cr0my-d2Oe+aZo+mjmWRXgjrGqyrw@mail.gmail.com>
--- drivers/hid/hidraw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hidraw.c +1 -1
@@ -265,7 +265,7 @@ static unsigned int hidraw_poll(struct fpoll_wait (file, &list->hidraw->wait, wait);if (list->head != list->tail) -return POLLIN |POLLRDNORM ; +return POLLIN |POLLRDNORM |POLLOUT ;if (!list->hidraw->exist)return POLLERR |POLLHUP ;return 0 ;
PATCH 170/245 HID: hidraw: Fix returning EPOLLOUT from hidraw_poll
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marcel Holtmann <[email protected]>
commit 9f3b61dc1dd7b81e99e7ed23776bb64a35f39e1a upstream.
When polling a connected /dev/hidrawX device, it is useful to get the EPOLLOUT when writing is possible. Since writing is possible as soon as the device is connected, always return it.
Right now EPOLLOUT is only returned when there are also input reports are available. This works if devices start sending reports when connected, but some HID devices might need an output report first before sending any input reports. This change will allow using EPOLLOUT here as well.
--- drivers/hid/hidraw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hidraw.c +2 -2
@@ -265,10 +265,10 @@ static unsigned int hidraw_poll(struct fpoll_wait (file, &list->hidraw->wait, wait);if (list->head != list->tail) -return POLLIN |POLLRDNORM |POLLOUT ; +return POLLIN |POLLRDNORM ;if (!list->hidraw->exist)return POLLERR |POLLHUP ; -return 0 ; +return POLLOUT |POLLWRNORM ; }static int hidraw_open (struct inode *inode,struct file *file)
PATCH 171/245 HID: hidraw, uhid: Always report EPOLLOUT
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Kosina <[email protected]>
commit 9e635c2851df6caee651e589fbf937b637973c91 upstream.
hidraw and uhid device nodes are always available for writing so we should always report EPOLLOUT and EPOLLWRNORM bits, not only in the cases when there is nothing to read.
[bwh: Backported to 3.16:
- Use unsigned int type instead of __poll_t
- s/EPOLL/POLL/g]
--- drivers/hid/hidraw.c | 7 ++++--- drivers/hid/uhid.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/hid/hidraw.c +4 -3
@@ -262,13 +262,14 @@ out:static unsigned int hidraw_poll (struct file *file,poll_table *wait) {struct hidraw_list *list = file->private_data; +unsigned int mask =POLLOUT |POLLWRNORM ;/* hidraw is always writable */ poll_wait (file, &list->hidraw->wait, wait);if (list->head != list->tail) -return POLLIN |POLLRDNORM ; + mask |=POLLIN |POLLRDNORM ;if (!list->hidraw->exist) -return POLLERR |POLLHUP ; -return POLLOUT |POLLWRNORM ; + mask |=POLLERR |POLLHUP ; +return mask; }static int hidraw_open (struct inode *inode,struct file *file)
drivers/hid/uhid.c +3 -2
@@ -720,13 +720,14 @@ unlock:static unsigned int uhid_char_poll (struct file *file,poll_table *wait) {struct uhid_device *uhid = file->private_data; +unsigned int mask =POLLOUT |POLLWRNORM ;/* uhid is always writable */ poll_wait (file, &uhid->waitq, wait);if (uhid->head != uhid->tail) -return POLLIN |POLLRDNORM ; + mask |=POLLIN |POLLRDNORM ; -return POLLOUT |POLLWRNORM ; +return mask; }static const struct file_operations uhid_fops = {
PATCH 172/245 Input: aiptek - fix endpoint sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 3111491fca4f01764e0c158c5e0f7ced808eef51 upstream.
The driver was checking the number of endpoints of the first alternate setting instead of the current one, something which could lead to the driver binding to an invalid interface.
This in turn could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/input/tablet/aiptek.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/tablet/aiptek.c +3 -3
@@ -1820,14 +1820,14 @@ aiptek_probe(struct usb_interface *intf,input_set_abs_params (inputdev,ABS_WHEEL ,AIPTEK_WHEEL_MIN ,AIPTEK_WHEEL_MAX -1 ,0 ,0 );/* Verify that a device really has an endpoint */ -if (intf->altsetting[0 ].desc.bNumEndpoints <1 ) { +if (intf->cur_altsetting->desc.bNumEndpoints <1 ) {dev_err (&intf->dev,"interface has %d endpoints, but must have minimum 1\n" , - intf->altsetting[0 ].desc.bNumEndpoints); + intf->cur_altsetting->desc.bNumEndpoints); err = -EINVAL ; goto fail3; } - endpoint = &intf->altsetting[0 ].endpoint[0 ].desc; + endpoint = &intf->cur_altsetting->endpoint[0 ].desc;/* Go set up our URB, which is called when the tablet receives * input.
PATCH 173/245 Input: gtco - fix endpoint sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit a8eeb74df5a6bdb214b2b581b14782c5f5a0cf83 upstream.
The driver was checking the number of endpoints of the first alternate setting instead of the current one, something which could lead to the driver binding to an invalid interface.
This in turn could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/input/tablet/gtco.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/input/tablet/gtco.c +3 -7
@@ -886,18 +886,14 @@ static int gtco_probe(struct usb_interfa }/* Sanity check that a device has an endpoint */ -if (usbinterface->altsetting[0 ].desc.bNumEndpoints <1 ) { +if (usbinterface->cur_altsetting->desc.bNumEndpoints <1 ) {dev_err (&usbinterface->dev,"Invalid number of endpoints\n" ); error = -EINVAL ; goto err_free_urb; } -/* -* The endpoint is always altsetting 0, we know this since we know -* this device only has one interrupt endpoint -*/ - endpoint = &usbinterface->altsetting[0 ].endpoint[0 ].desc; + endpoint = &usbinterface->cur_altsetting->endpoint[0 ].desc;/* Some debug */ dev_dbg (&usbinterface->dev,"gtco # interfaces: %d\n" , usbinterface->num_altsetting);
@@ -984,7 +980,7 @@ static int gtco_probe(struct usb_interfa input_dev->dev.parent = &usbinterface->dev;/* Setup the URB, it will be posted later on open of input device */ - endpoint = &usbinterface->altsetting[0 ].endpoint[0 ].desc; + endpoint = &usbinterface->cur_altsetting->endpoint[0 ].desc; usb_fill_int_urb(gtco->urbinfo, gtco->usbdev,
PATCH 174/245 Input: sur40 - fix interface sanity checks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 6b32391ed675827f8425a414abbc6fbd54ea54fe upstream.
Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface.
This in turn could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on.
--- drivers/input/touchscreen/sur40.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/sur40.c +1 -1
@@ -357,7 +357,7 @@ static int sur40_probe(struct usb_interfint error;/* Check if we really have the right interface. */ - iface_desc = &interface->altsetting[0 ]; + iface_desc = interface->cur_altsetting;if (iface_desc->desc.bInterfaceClass !=0xFF )return -ENODEV ;
PATCH 175/245 platform/x86: asus-wmi: Fix keyboard brightness cannot be set to 0
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jian-Hong Pan <[email protected]>
commit 176a7fca81c5090a7240664e3002c106d296bf31 upstream.
Some of ASUS laptops like UX431FL keyboard backlight cannot be set to brightness 0. According to ASUS' information, the brightness should be 0x80 ~ 0x83. This patch fixes it by following the logic.
--- drivers/platform/x86/asus-wmi.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -7
@@ -386,13 +386,7 @@ static void kbd_led_update(struct work_s asus = container_of(work, struct asus_wmi, kbd_led_work); -/* -* bits 0-2: level -* bit 7: light on/off -*/ -if (asus->kbd_led_wk >0 ) - ctrl_param =0x80 | (asus->kbd_led_wk &0x7F ); - + ctrl_param =0x80 | (asus->kbd_led_wk &0x7F );asus_wmi_set_devstate (ASUS_WMI_DEVID_KBD_BACKLIGHT , ctrl_param,NULL ); }
PATCH 176/245 iio: buffer: align the size of scan bytes to size of the largest element
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lars Möllendorf <[email protected]>
commit 883f616530692d81cb70f8a32d85c0d2afc05f69 upstream.
Previous versions of iio_compute_scan_bytes only aligned each element to its own length (i.e. its own natural alignment). Because multiple consecutive sets of scan elements are buffered this does not work in case the computed scan bytes do not align with the natural alignment of the first scan element in the set.
This commit fixes this by aligning the scan bytes to the natural alignment of the largest scan element in the set.
--- drivers/iio/industrialio-buffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +5 -1
@@ -478,7 +478,7 @@ static int iio_compute_scan_bytes(struct {const struct iio_chan_spec *ch;unsigned bytes =0 ; -int length, i; +int length, i, largest =0 ;/* How much space will the demuxed element take? */ for_each_set_bit(i, mask,
@@ -491,6 +491,7 @@ static int iio_compute_scan_bytes(struct length = ch->scan_type.storagebits /8 ; bytes =ALIGN (bytes, length); bytes += length; + largest =max (largest, length); }if (timestamp) { ch = iio_find_channel_from_si(indio_dev,
@@ -502,7 +503,10 @@ static int iio_compute_scan_bytes(struct length = ch->scan_type.storagebits /8 ; bytes =ALIGN (bytes, length); bytes += length; + largest =max (largest, length); } + + bytes =ALIGN (bytes, largest);return bytes; }
PATCH 177/245 USB: serial: simple: Add Motorola Solutions TETRA MTP3xxx and MTP85xx
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jerónimo Borque <[email protected]>
commit 260e41ac4dd3e5acb90be624c03ba7f019615b75 upstream.
Add device-ids for the Motorola Solutions TETRA radios MTP3xxx series and MTP85xx series
$ lsusb -vd 0cad:
Bus 001 Device 009: ID 0cad:9015 Motorola CGISS TETRA PEI interface Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0cad Motorola CGISS idProduct 0x9015 bcdDevice 24.16 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0037
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 3
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Bus 001 Device 010: ID 0cad:9013 Motorola CGISS TETRA PEI interface Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0cad Motorola CGISS idProduct 0x9013 bcdDevice 24.16 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0037
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 3
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
--- drivers/usb/serial/usb-serial-simple.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/serial/usb-serial-simple.c +2 -0
@@ -89,6 +89,8 @@ DEVICE(moto_modem, MOTO_IDS);#define MOTOROLA_TETRA_IDS () \ { USB_DEVICE(0x0cad, 0x9011) },/* Motorola Solutions TETRA PEI */ \ { USB_DEVICE(0x0cad, 0x9012) }, /* MTP6550 */ \ + { USB_DEVICE(0x0cad, 0x9013) }, /* MTP3xxx */ \ + { USB_DEVICE(0x0cad, 0x9015) }, /* MTP85xx */ \ { USB_DEVICE(0x0cad, 0x9016) } /* TPG2200 */DEVICE (motorola_tetra,MOTOROLA_TETRA_IDS );
PATCH 178/245 netfilter: fix a use-after-free in mtype_destroy()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit c120959387efa51479056fd01dc90adfba7a590c upstream.
map->members is freed by ip_set_free() right before using it in mtype_ext_cleanup() again. So we just have to move it down.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +1 -1
@@ -66,12 +66,12 @@ mtype_destroy(struct ip_set *set)if (SET_WITH_TIMEOUT (set))del_timer_sync (&map->gc); -ip_set_free (map->members);if (set->dsize) {if (set->extensions &IPSET_EXT_DESTROY )mtype_ext_cleanup (set);ip_set_free (map->extensions); } +ip_set_free (map->members);kfree (map); set->data =NULL ;
PATCH 179/245 netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 212e7f56605ef9688d0846db60c6c6ec06544095 upstream.
An earlier commit (1b789577f655060d98d20e,
"netfilter: arp_tables: init netns pointer in xt_tgchk_param struct") fixed missing net initialization for arptables, but turns out it was incomplete. We can get a very similar struct net NULL deref during error unwinding:
general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: 0010:xt_rateest_put+0xa1/0x440 net/netfilter/xt_RATEEST.c:77 xt_rateest_tg_destroy+0x72/0xa0 net/netfilter/xt_RATEEST.c:175 cleanup_entry net/ipv4/netfilter/arp_tables.c:509 [inline] translate_table+0x11f4/0x1d80 net/ipv4/netfilter/arp_tables.c:587 do_replace net/ipv4/netfilter/arp_tables.c:981 [inline] do_arpt_set_ctl+0x317/0x650 net/ipv4/netfilter/arp_tables.c:1461
Also init the netns pointer in xt_tgdtor_param struct.
[bwh: Backported to 3.16:
- __arpt_unregister_table() has not been split out of arpt_unregister_table()
- Add "net" parameter to arpt_unregister_table() and update its only caller in arptable_filter.c]
---
include/linux/netfilter_arp/arp_tables.h +1 -1
@@ -51,7 +51,7 @@ extern void *arpt_alloc_initial_table(coextern struct xt_table *arpt_register_table (struct net *net,const struct xt_table *table,const struct arpt_replace *repl); -extern void arpt_unregister_table (struct xt_table *table); +extern void arpt_unregister_table (struct net *,struct xt_table *table); extern unsigned int arpt_do_table(struct sk_buff *skb, unsigned int hook, const struct net_device *in,
net/ipv4/netfilter/arp_tables.c +8 -7
@@ -602,12 +602,13 @@ static inline int check_entry_size_and_hreturn 0 ; } -static inline void cleanup_entry (struct arpt_entry *e) +static void cleanup_entry (struct arpt_entry *e,struct net *net) {struct xt_tgdtor_param par;struct xt_entry_target *t; t =arpt_get_target (e); + par.net = net; par.target = t->u.kernel.target; par.targinfo = t->data; par.family =NFPROTO_ARP ;
@@ -706,7 +707,7 @@ static int translate_table(struct net *n xt_entry_foreach(iter, entry0, newinfo->size) {if (i-- ==0 )break ; -cleanup_entry (iter); +cleanup_entry (iter, net); }return ret; }
@@ -1051,7 +1052,7 @@ static int __do_replace(struct net *net,/* Decrease module usage counts and free resource */ loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id ()]; xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) -cleanup_entry (iter); +cleanup_entry (iter, net);xt_free_table_info (oldinfo); if (copy_to_user(counters_ptr, counters,
@@ -1118,7 +1119,7 @@ static int do_replace(struct net *net, c free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) -cleanup_entry (iter); +cleanup_entry (iter, net); free_newinfo:xt_free_table_info (newinfo);return ret;
@@ -1431,7 +1432,7 @@ static int compat_do_replace(struct net free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) -cleanup_entry (iter); +cleanup_entry (iter, net); free_newinfo:xt_free_table_info (newinfo);return ret;
@@ -1708,7 +1709,7 @@ out:return ERR_PTR (ret); } -void arpt_unregister_table (struct xt_table *table) +void arpt_unregister_table (struct net *net,struct xt_table *table) {struct xt_table_info *private;void *loc_cpu_entry;
@@ -1720,7 +1721,7 @@ void arpt_unregister_table(struct xt_tab/* Decrease module usage counts and free resources */ loc_cpu_entry = private->entries[raw_smp_processor_id ()]; xt_entry_foreach(iter, loc_cpu_entry, private->size) -cleanup_entry (iter); +cleanup_entry (iter, net);if (private->number > private->initial_entries)module_put (table_owner);xt_free_table_info (private);
net/ipv4/netfilter/arptable_filter.c +1 -1
@@ -54,7 +54,7 @@ static int __net_init arptable_filter_ne static void __net_exit arptable_filter_net_exit(struct net *net) { -arpt_unregister_table (net->ipv4.arptable_filter); +arpt_unregister_table (net, net->ipv4.arptable_filter); }static struct pernet_operations arptable_filter_net_ops = {
PATCH 180/245 ALSA: usb-audio: add implicit fb quirk for Axe-Fx II
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alberto Aguirre <[email protected]>
commit 17f08b0d9aafccdb10038ab6dbd9ddb6433c13e2 upstream.
The Axe-Fx II implicit feedback end point and the data sync endpoint are in different interface descriptors. Add quirk to ensure a sync endpoint is properly configured.
--- sound/usb/pcm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/usb/pcm.c +10 -0
@@ -351,6 +351,15 @@ static int set_sync_ep_implicit_fb_quirk alts = &iface->altsetting[1 ]; goto add_sync_ep; +case USB_ID (0x2466 ,0x8003 ): + ep =0x86 ; + iface =usb_ifnum_to_if (dev,2 ); + +if (!iface || iface->num_altsetting ==0 ) +return -EINVAL ; + + alts = &iface->altsetting[1 ]; + goto add_sync_ep;case USB_ID (0x1397 ,0x0002 ): ep =0x81 ; iface =usb_ifnum_to_if (dev,1 );
@@ -360,6 +369,7 @@ static int set_sync_ep_implicit_fb_quirk alts = &iface->altsetting[1 ]; goto add_sync_ep; + } if (attr == USB_ENDPOINT_SYNC_ASYNC && altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
PATCH 181/245 ALSA: usb-audio: simplify set_sync_ep_implicit_fb_quirk
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alberto Aguirre <[email protected]>
commit 103e9625647ad74d201e26fb74afcd8479142a37 upstream.
--- sound/usb/pcm.c | 52 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 32 deletions(-)
sound/usb/pcm.c +20 -32
@@ -324,6 +324,7 @@ static int set_sync_ep_implicit_fb_quirkstruct usb_host_interface *alts;struct usb_interface *iface;unsigned int ep; +unsigned int ifnum;/* Implicit feedback sync EPs consumers are always playback EPs */ if (subs->direction !=SNDRV_PCM_STREAM_PLAYBACK )
@@ -333,44 +334,23 @@ static int set_sync_ep_implicit_fb_quirkcase USB_ID (0x0763 ,0x2030 ):/* M-Audio Fast Track C400 */ case USB_ID (0x0763 ,0x2031 ):/* M-Audio Fast Track C600 */ ep =0x81 ; - iface =usb_ifnum_to_if (dev,3 ); - -if (!iface || iface->num_altsetting ==0 ) -return -EINVAL ; - - alts = &iface->altsetting[1 ]; - goto add_sync_ep; -break ; + ifnum =3 ; + goto add_sync_ep_from_ifnum;case USB_ID (0x0763 ,0x2080 ):/* M-Audio FastTrack Ultra */ case USB_ID (0x0763 ,0x2081 ): ep =0x81 ; - iface =usb_ifnum_to_if (dev,2 ); - -if (!iface || iface->num_altsetting ==0 ) -return -EINVAL ; - - alts = &iface->altsetting[1 ]; - goto add_sync_ep; -case USB_ID (0x2466 ,0x8003 ): + ifnum =2 ; + goto add_sync_ep_from_ifnum; +case USB_ID (0x2466 ,0x8003 ):/* Fractal Audio Axe-Fx II */ ep =0x86 ; - iface =usb_ifnum_to_if (dev,2 ); - -if (!iface || iface->num_altsetting ==0 ) -return -EINVAL ; - - alts = &iface->altsetting[1 ]; - goto add_sync_ep; -case USB_ID (0x1397 ,0x0002 ): + ifnum =2 ; + goto add_sync_ep_from_ifnum; +case USB_ID (0x1397 ,0x0002 ):/* Behringer UFX1204 */ ep =0x81 ; - iface =usb_ifnum_to_if (dev,1 ); - -if (!iface || iface->num_altsetting ==0 ) -return -EINVAL ; - - alts = &iface->altsetting[1 ]; - goto add_sync_ep; - + ifnum =1 ; + goto add_sync_ep_from_ifnum; } + if (attr == USB_ENDPOINT_SYNC_ASYNC && altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC && altsd->bInterfaceProtocol == 2 &&
@@ -385,6 +365,14 @@ static int set_sync_ep_implicit_fb_quirk/* No quirk */ return 0 ; +add_sync_ep_from_ifnum: + iface =usb_ifnum_to_if (dev, ifnum); + +if (!iface || iface->num_altsetting ==0 ) +return -EINVAL ; + + alts = &iface->altsetting[1 ]; + add_sync_ep: subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip, alts, ep, !subs->direction,
PATCH 182/245 ALSA: usb-audio: fix sync-ep altsetting sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 5d1b71226dc4d44b4b65766fa9d74492f9d4587b upstream.
The altsetting sanity check in set_sync_ep_implicit_fb_quirk() was checking for there to be at least one altsetting but then went on to access the second one, which may not exist.
This could lead to random slab data being used to initialise the sync endpoint in snd_usb_add_endpoint().
--- sound/usb/pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/pcm.c +1 -1
@@ -368,7 +368,7 @@ static int set_sync_ep_implicit_fb_quirk add_sync_ep_from_ifnum: iface =usb_ifnum_to_if (dev, ifnum); -if (!iface || iface->num_altsetting ==0 ) +if (!iface || iface->num_altsetting <2 )return -EINVAL ; alts = &iface->altsetting[1 ];
PATCH 183/245 USB: serial: opticon: fix control-message timeouts
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 5e28055f340275a8616eee88ef19186631b4d136 upstream.
The driver was issuing synchronous uninterruptible control requests without using a timeout. This could lead to the driver hanging on open() or tiocmset() due to a malfunctioning (or malicious) device until the device is physically disconnected.
The USB upper limit of five seconds per request should be more than enough.
--- drivers/usb/serial/opticon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/opticon.c +1 -1
@@ -116,7 +116,7 @@ static int send_control_msg(struct usb_s retval =usb_control_msg (serial->dev,usb_sndctrlpipe (serial->dev,0 ), requesttype,USB_DIR_OUT |USB_TYPE_VENDOR |USB_RECIP_INTERFACE , -0 ,0 , buffer,1 ,0 ); +0 ,0 , buffer,1 ,USB_CTRL_SET_TIMEOUT );kfree (buffer);if (retval <0 )
PATCH 184/245 r8152: add missing endpoint sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 86f3f4cd53707ceeec079b83205c8d3c756eca93 upstream.
Add missing endpoint sanity check to probe in order to prevent a NULL-pointer dereference (or slab out-of-bounds access) when retrieving the interrupt-endpoint bInterval on ndo_open() in case a device lacks the expected endpoints.
--- drivers/net/usb/r8152.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/usb/r8152.c +3 -0
@@ -3425,6 +3425,9 @@ static int rtl8152_probe(struct usb_intereturn -ENODEV ; } +if (intf->cur_altsetting->desc.bNumEndpoints <3 ) +return -ENODEV ; +usb_reset_device (udev); netdev =alloc_etherdev (sizeof (struct r8152 ));if (!netdev) {
PATCH 185/245 usb: core: hub: Improved device recognition on remote wakeup
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Keiya Nobuta <[email protected]>
commit 9c06ac4c83df6d6fbdbf7488fbad822b4002ba19 upstream.
If hub_activate() is called before D+ has stabilized after remote wakeup, the following situation might occur:
__ ___________________
/ \ /D+ __/ \__/
Hub _______________________________
| ^ ^ ^
| | | |
Host _____v__|___|___________|______
| | | |
| | | \-- Interrupt Transfer (*3)
| | \-- ClearPortFeature (*2) | \-- GetPortStatus (*1)
\-- Host detects remote wakeup
- D+ goes high, Host starts running by remote wakeup
- D+ is not stable, goes low
- Host requests GetPortStatus at (*1) and gets the following hub status:
- Current Connect Status bit is 0
- Connect Status Change bit is 1
- D+ stabilizes, goes high
- Host requests ClearPortFeature and thus Connect Status Change bit is cleared at (*2)
- After waiting 100 ms, Host starts the Interrupt Transfer at (*3)
- Since the Connect Status Change bit is 0, Hub returns NAK.
In this case, port_event() is not called in hub_event() and Host cannot recognize device. To solve this issue, flag change_bits even if only Connect Status Change bit is 1 when got in the first GetPortStatus.
This issue occurs rarely because it only if D+ changes during a very short time between GetPortStatus and ClearPortFeature. However, it is fatal if it occurs in embedded system.
--- drivers/usb/core/hub.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
@@ -1125,6 +1125,7 @@ static void hub_activate(struct usb_hub* PORT_OVER_CURRENT is not. So check for any of them. */ if (udev || (portstatus &USB_PORT_STAT_CONNECTION ) || + (portchange &USB_PORT_STAT_C_CONNECTION ) || (portstatus &USB_PORT_STAT_OVERCURRENT ) || (portchange &USB_PORT_STAT_C_OVERCURRENT ))set_bit (port1, hub->change_bits);
PATCH 186/245 Fix built-in early-load Intel microcode alignment
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jari Ruusu <[email protected]>
commit f5ae2ea6347a308cfe91f53b53682ce635497d0d upstream.
Intel Software Developer's Manual, volume 3, chapter 9.11.6 says:
"Note that the microcode update must be aligned on a 16-byte boundary
and the size of the microcode update must be 1-KByte granular"
When early-load Intel microcode is loaded from initramfs, userspace tool 'iucode_tool' has already 16-byte aligned those microcode bits in that initramfs image. Image that was created something like this:
iucode_tool --write-earlyfw=FOO.cpio microcode-files...
However, when early-load Intel microcode is loaded from built-in firmware BLOB using CONFIG_EXTRA_FIRMWARE= kernel config option, that 16-byte alignment is not guaranteed.
Fix this by forcing all built-in firmware BLOBs to 16-byte alignment.
[ If we end up having other firmware with much bigger alignment
requirements, we might need to introduce some method for the firmware to specify it, this is the minimal "just increase the alignment a bit
to account for this one special case" patch - Linus ]
--- firmware/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
firmware/Makefile +1 -1
@@ -156,7 +156,7 @@ quiet_cmd_fwbin = MK_FW $@ PROGBITS=$(if $(CONFIG_ARM),%,@)progbits; \ echo "/* Generated by firmware/Makefile */" > $@;\ echo " .section .rodata" >>$@;\ - echo " .p2align $${ASM_ALIGN}" >>$@;\ + echo " .p2align 4" >>$@;\ echo "_fw_$${FWSTR}_bin:" >>$@;\ echo " .incbin \"$(2)\"" >>$@;\ echo "_fw_end:" >>$@;\
PATCH 187/245 ALSA: seq: Fix racy access for queue timer in proc read
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 60adcfde92fa40fcb2dbf7cc52f9b096e0cd109a upstream.
snd_seq_info_timer_read() reads the information of the timer assigned for each queue, but it's done in a racy way which may lead to UAF as spotted by syzkaller.
This patch applies the missing q->timer_mutex lock while accessing the timer object as well as a slight code change to adapt the standard coding style.
--- sound/core/seq/seq_timer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
sound/core/seq/seq_timer.c +9 -5
@@ -484,15 +484,19 @@ void snd_seq_info_timer_read(struct snd_ q =queueptr (idx);if (q ==NULL )continue ; -if ((tmr = q->timer) ==NULL || - (ti = tmr->timeri) ==NULL ) { -queuefree (q); -continue ; - } +mutex_lock (&q->timer_mutex); + tmr = q->timer; +if (!tmr) + goto unlock; + ti = tmr->timeri; +if (!ti) + goto unlock;snd_iprintf (buffer,"Timer for queue %i : %s\n" , q->queue, ti->timer->name); resolution =snd_timer_resolution (ti) * tmr->ticks;snd_iprintf (buffer," Period time : %lu.%09lu\n" , resolution /1000000000 , resolution %1000000000 );snd_iprintf (buffer," Skew : %u / %u\n" , tmr->skew, tmr->skew_base); +unlock: +mutex_unlock (&q->timer_mutex);queuefree (q); } }
PATCH 188/245 scsi: fnic: fix invalid stack access
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 42ec15ceaea74b5f7a621fc6686cbf69ca66c4cf upstream.
gcc -O3 warns that some local variables are not properly initialized:
drivers/scsi/fnic/vnic_dev.c: In function 'fnic_dev_hang_notify':drivers/scsi/fnic/vnic_dev.c:511:16: error: 'a0' is used uninitialized in this function [-Werror=uninitialized]
vdev->args[0] = *a0;
~~~~~~~~~~~~~~^~~~~drivers/scsi/fnic/vnic_dev.c:691:6: note: 'a0' was declared here
u64 a0, a1;
^~drivers/scsi/fnic/vnic_dev.c:512:16: error: 'a1' is used uninitialized in this function [-Werror=uninitialized]
vdev->args[1] = *a1;
~~~~~~~~~~~~~~^~~~~drivers/scsi/fnic/vnic_dev.c:691:10: note: 'a1' was declared here
u64 a0, a1;
^~drivers/scsi/fnic/vnic_dev.c: In function 'fnic_dev_mac_addr':drivers/scsi/fnic/vnic_dev.c:512:16: error: 'a1' is used uninitialized in this function [-Werror=uninitialized]
vdev->args[1] = *a1;
~~~~~~~~~~~~~~^~~~~drivers/scsi/fnic/vnic_dev.c:698:10: note: 'a1' was declared here
u64 a0, a1;
^~Apparently the code relies on the local variables occupying adjacent memory locations in the same order, but this is of course not guaranteed.
Use an array of two u64 variables where needed to make it work correctly.
I suspect there is also an endianness bug here, but have not digged in deep enough to be sure.
--- drivers/scsi/fnic/vnic_dev.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/scsi/fnic/vnic_dev.c +10 -10
@@ -445,26 +445,26 @@ int vnic_dev_soft_reset_done(struct vnicint vnic_dev_hang_notify (struct vnic_dev *vdev) { -u64 a0, a1; +u64 a0 =0 , a1 =0 ;int wait =1000 ;return vnic_dev_cmd (vdev,CMD_HANG_NOTIFY , &a0, &a1, wait); }int vnic_dev_mac_addr (struct vnic_dev *vdev,u8 *mac_addr) { -u64 a0, a1; +u64 a[2 ] = {};int wait =1000 ;int err, i;for (i =0 ; i <ETH_ALEN ; i++) mac_addr[i] =0 ; - err =vnic_dev_cmd (vdev,CMD_MAC_ADDR , &a0, &a1, wait); + err =vnic_dev_cmd (vdev,CMD_MAC_ADDR , &a[0 ], &a[1 ], wait);if (err)return err;for (i =0 ; i <ETH_ALEN ; i++) - mac_addr[i] = ((u8 *)&a0)[i]; + mac_addr[i] = ((u8 *)&a)[i];return 0 ; }
@@ -489,15 +489,15 @@ void vnic_dev_packet_filter(struct vnic_void vnic_dev_add_addr (struct vnic_dev *vdev,u8 *addr) { -u64 a0 =0 , a1 =0 ; +u64 a[2 ] = {};int wait =1000 ;int err;int i;for (i =0 ; i <ETH_ALEN ; i++) - ((u8 *)&a0)[i] = addr[i]; + ((u8 *)&a)[i] = addr[i]; - err =vnic_dev_cmd (vdev,CMD_ADDR_ADD , &a0, &a1, wait); + err =vnic_dev_cmd (vdev,CMD_ADDR_ADD , &a[0 ], &a[1 ], wait);if (err) printk(KERN_ERR "Can't add addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
@@ -507,15 +507,15 @@ void vnic_dev_add_addr(struct vnic_dev *void vnic_dev_del_addr (struct vnic_dev *vdev,u8 *addr) { -u64 a0 =0 , a1 =0 ; +u64 a[2 ] = {};int wait =1000 ;int err;int i;for (i =0 ; i <ETH_ALEN ; i++) - ((u8 *)&a0)[i] = addr[i]; + ((u8 *)&a)[i] = addr[i]; - err =vnic_dev_cmd (vdev,CMD_ADDR_DEL , &a0, &a1, wait); + err =vnic_dev_cmd (vdev,CMD_ADDR_DEL , &a[0 ], &a[1 ], wait);if (err) printk(KERN_ERR "Can't del addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
PATCH 189/245 block: fix an integer overflow in logical block size
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit ad6bf88a6c19a39fb3b0045d78ea880325dfcf15 upstream.
Logical block size has type unsigned short. That means that it can be at most 32768. However, there are architectures that can run with 64k pages (for example arm64) and on these architectures, it may be possible to create block devices with 64k block size.
For exmaple (run this on an architecture with 64k pages):
Mount will fail with this error because it tries to read the superblock using 2-sector access:
device-mapper: writecache: I/O is not aligned, sector 2, size 1024, block size 65536 EXT4-fs (dm-0): unable to read superblock
This patch changes the logical block size from unsigned short to unsigned int to avoid the overflow.
--- block/blk-settings.c | 2 +- drivers/md/dm-snap-persistent.c | 2 +- drivers/md/raid0.c | 2 +- include/linux/blkdev.h | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-)
block/blk-settings.c +1 -1
@@ -373,7 +373,7 @@ EXPORT_SYMBOL(blk_queue_max_segment_size* storage device can address. The default of 512 covers most * hardware. **/ -void blk_queue_logical_block_size (struct request_queue *q,unsigned short size) +void blk_queue_logical_block_size (struct request_queue *q,unsigned int size) { q->limits.logical_block_size = size;
drivers/md/dm-snap-persistent.c +1 -1
@@ -16,7 +16,7 @@#include "dm-bufio.h" #define DM_MSG_PREFIX "persistent snapshot" -#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32/* 16KB */ +#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32U/* 16KB */ #define DM_PREFETCH_CHUNKS 12
drivers/md/raid0.c +1 -1
@@ -88,7 +88,7 @@ static int create_strip_zones(struct mddchar b[BDEVNAME_SIZE ];char b2[BDEVNAME_SIZE ];struct r0conf *conf =kzalloc (sizeof (*conf),GFP_KERNEL ); -unsigned short blksize =512 ; +unsigned blksize =512 ;if (!conf)return -ENOMEM ;
include/linux/blkdev.h +4 -4
@@ -284,6 +284,7 @@ struct queue_limits {unsigned int max_sectors;unsigned int max_segment_size;unsigned int physical_block_size; +unsigned int logical_block_size;unsigned int alignment_offset;unsigned int io_min;unsigned int io_opt;
@@ -292,7 +293,6 @@ struct queue_limits {unsigned int discard_granularity;unsigned int discard_alignment; -unsigned short logical_block_size;unsigned short max_segments;unsigned short max_integrity_segments;
@@ -1017,7 +1017,7 @@ extern void blk_queue_max_discard_sector unsigned int max_discard_sectors);extern void blk_queue_max_write_same_sectors (struct request_queue *q,unsigned int max_write_same_sectors); -extern void blk_queue_logical_block_size (struct request_queue *,unsigned short ); +extern void blk_queue_logical_block_size (struct request_queue *,unsigned int );extern void blk_queue_physical_block_size (struct request_queue *,unsigned int );extern void blk_queue_alignment_offset (struct request_queue *q,unsigned int alignment);
@@ -1232,7 +1232,7 @@ static inline unsigned int queue_max_segreturn q->limits.max_segment_size; } -static inline unsigned short queue_logical_block_size (struct request_queue *q) +static inline unsigned queue_logical_block_size (struct request_queue *q) {int retval =512 ;
@@ -1242,7 +1242,7 @@ static inline unsigned short queue_logicreturn retval; } -static inline unsigned short bdev_logical_block_size (struct block_device *bdev) +static inline unsigned int bdev_logical_block_size (struct block_device *bdev) {return queue_logical_block_size (bdev_get_queue (bdev)); }
PATCH 190/245 macvlan: use skb_reset_mac_header() in macvlan_queue_xmit()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 1712b2fff8c682d145c7889d2290696647d82dab upstream.
I missed the fact that macvlan_broadcast() can be used both in RX and TX.
skb_eth_hdr() makes only sense in TX paths, so we can not use it blindly in macvlan_broadcast()
--- drivers/net/macvlan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/macvlan.c +3 -2
@@ -162,7 +162,7 @@ static void macvlan_broadcast(struct sk_ struct net_device *src, enum macvlan_mode mode) { -const struct ethhdr *eth =skb_eth_hdr (skb); +const struct ethhdr *eth =eth_hdr (skb);const struct macvlan_dev *vlan;struct sk_buff *nskb;unsigned int i;
@@ -345,10 +345,11 @@ static int macvlan_queue_xmit(struct sk_const struct macvlan_dev *dest;if (vlan->mode ==MACVLAN_MODE_BRIDGE ) { -const struct ethhdr *eth = (void *)skb->data; +const struct ethhdr *eth =skb_eth_hdr (skb);/* send to other bridge ports directly */ if (is_multicast_ether_addr (eth->h_dest)) { +skb_reset_mac_header (skb);macvlan_broadcast (skb, port, dev,MACVLAN_MODE_BRIDGE ); goto xmit_world; }
PATCH 191/245 Input: keyspan-remote - fix control-message timeouts
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit ba9a103f40fc4a3ec7558ec9b0b97d4f92034249 upstream.
The driver was issuing synchronous uninterruptible control requests without using a timeout. This could lead to the driver hanging on probe due to a malfunctioning (or malicious) device until the device is physically disconnected. While sleeping in probe the driver prevents other devices connected to the same hub from being added to (or removed from) the bus.
The USB upper limit of five seconds per request should be more than enough.
--- drivers/input/misc/keyspan_remote.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/input/misc/keyspan_remote.c +6 -3
@@ -344,7 +344,8 @@ static int keyspan_setup(struct usb_deviint retval =0 ; retval =usb_control_msg (dev,usb_sndctrlpipe (dev,0 ), -0x11 ,0x40 ,0x5601 ,0x0 ,NULL ,0 ,0 ); +0x11 ,0x40 ,0x5601 ,0x0 ,NULL ,0 , +USB_CTRL_SET_TIMEOUT );if (retval) {dev_dbg (&dev->dev,"%s - failed to set bit rate due to error: %d\n" , __func__, retval);
@@ -352,7 +353,8 @@ static int keyspan_setup(struct usb_devi } retval =usb_control_msg (dev,usb_sndctrlpipe (dev,0 ), -0x44 ,0x40 ,0x0 ,0x0 ,NULL ,0 ,0 ); +0x44 ,0x40 ,0x0 ,0x0 ,NULL ,0 , +USB_CTRL_SET_TIMEOUT );if (retval) {dev_dbg (&dev->dev,"%s - failed to set resume sensitivity due to error: %d\n" , __func__, retval);
@@ -360,7 +362,8 @@ static int keyspan_setup(struct usb_devi } retval =usb_control_msg (dev,usb_sndctrlpipe (dev,0 ), -0x22 ,0x40 ,0x0 ,0x0 ,NULL ,0 ,0 ); +0x22 ,0x40 ,0x0 ,0x0 ,NULL ,0 , +USB_CTRL_SET_TIMEOUT );if (retval) {dev_dbg (&dev->dev,"%s - failed to turn receive on due to error: %d\n" , __func__, retval);
PATCH 192/245 USB: serial: suppress driver bind attributes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit fdb838efa31e1ed9a13ae6ad0b64e30fdbd00570 upstream.
USB-serial drivers must not be unbound from their ports before the corresponding USB driver is unbound from the parent interface so suppress the bind and unbind attributes.
Unbinding a serial driver while it's port is open is a sure way to trigger a crash as any driver state is released on unbind while port hangup is handled on the parent USB interface level. Drivers for multiport devices where ports share a resource such as an interrupt endpoint also generally cannot handle individual ports going away.
--- drivers/usb/serial/usb-serial.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/serial/usb-serial.c +3 -0
@@ -1337,6 +1337,9 @@ static int usb_serial_register(struct usreturn -EINVAL ; } +/* Prevent individual ports from being unbound. */ + driver->driver.suppress_bind_attrs = true; +usb_serial_operations_init (driver);/* Add this device to our list of devices */
PATCH 193/245 USB: serial: ch341: handle unbound port at reset_resume
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 4d5ef53f75c22d28f490bcc5c771fcc610a9afa4 upstream.
Check for NULL port data in reset_resume() to avoid dereferencing a NULL pointer in case the port device isn't bound to a driver (e.g. after a failed control request at port probe).
--- drivers/usb/serial/ch341.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/serial/ch341.c +5 -1
@@ -571,9 +571,13 @@ static int ch341_tiocmget(struct tty_strstatic int ch341_reset_resume (struct usb_serial *serial) {struct usb_serial_port *port = serial->port[0 ]; -struct ch341_private *priv =usb_get_serial_port_data (port); +struct ch341_private *priv;int ret; + priv =usb_get_serial_port_data (port); +if (!priv) +return 0 ; +/* reconfigure ch341 serial port after bus-reset */ ch341_configure (serial->dev, priv);
PATCH 194/245 USB: serial: io_edgeport: handle unbound ports on URB completion
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit e37d1aeda737a20b1846a91a3da3f8b0f00cf690 upstream.
Check for NULL port data in the shared interrupt and bulk completion callbacks to avoid dereferencing a NULL pointer in case a device sends data for a port device which isn't bound to a driver (e.g. due to a malicious device having unexpected endpoints or after an allocation failure on port probe).
--- drivers/usb/serial/io_edgeport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/io_edgeport.c +2 -2
@@ -638,7 +638,7 @@ static void edge_interrupt_callback(struif (txCredits) { port = edge_serial->serial->port[portNumber]; edge_port =usb_get_serial_port_data (port); -if (edge_port->open) { +if (edge_port && edge_port->open) {spin_lock (&edge_port->ep_lock); edge_port->txCredits += txCredits;spin_unlock (&edge_port->ep_lock);
@@ -1775,7 +1775,7 @@ static void process_rcvd_data(struct edg port = edge_serial->serial->port[ edge_serial->rxPort]; edge_port =usb_get_serial_port_data (port); -if (edge_port->open) { +if (edge_port && edge_port->open) {dev_dbg (dev,"%s - Sending %d bytes to TTY for port %d\n" , __func__, rxLen, edge_serial->rxPort);
PATCH 195/245 USB: serial: io_edgeport: add missing active-port sanity check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 1568c58d11a7c851bd09341aeefd6a1c308ac40d upstream.
The driver receives the active port number from the device, but never made sure that the port number was valid. This could lead to a NULL-pointer dereference or memory corruption in case a device sends data for an invalid port.
--- drivers/usb/serial/io_edgeport.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/serial/io_edgeport.c +7 -5
@@ -1666,7 +1666,8 @@ static void edge_break(struct tty_structstatic void process_rcvd_data (struct edgeport_serial *edge_serial,unsigned char *buffer,__u16 bufferLength) { -struct device *dev = &edge_serial->serial->dev->dev; +struct usb_serial *serial = edge_serial->serial; +struct device *dev = &serial->dev->dev;struct usb_serial_port *port;struct edgeport_port *edge_port;__u16 lastBufferLength;
@@ -1771,9 +1772,8 @@ static void process_rcvd_data(struct edg/* spit this data back into the tty driver if this port is open */ -if (rxLen) { - port = edge_serial->serial->port[ - edge_serial->rxPort]; +if (rxLen && edge_serial->rxPort < serial->num_ports) { + port = serial->port[edge_serial->rxPort]; edge_port =usb_get_serial_port_data (port);if (edge_port && edge_port->open) { dev_dbg(dev, "%s - Sending %d bytes to TTY for port %d\n",
@@ -1783,8 +1783,8 @@ static void process_rcvd_data(struct edg rxLen); edge_port->port->icount.rx += rxLen; } - buffer += rxLen; } + buffer += rxLen;break ;case EXPECT_HDR3 :/* Expect 3rd byte of status header */
@@ -1819,6 +1819,8 @@ static void process_rcvd_status(struct e__u8 code = edge_serial->rxStatusCode;/* switch the port pointer to the one being currently talked about */ +if (edge_serial->rxPort >= edge_serial->serial->num_ports) +return ; port = edge_serial->serial->port[edge_serial->rxPort]; edge_port =usb_get_serial_port_data (port);if (edge_port ==NULL ) {
PATCH 196/245 USB: serial: keyspan: handle unbound ports
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 3018dd3fa114b13261e9599ddb5656ef97a1fa17 upstream.
Check for NULL port data in the control URB completion handlers to avoid dereferencing a NULL pointer in the unlikely case where a port device isn't bound to a driver (e.g. after an allocation failure on port probe()).
--- drivers/usb/serial/keyspan.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/serial/keyspan.c +4 -0
@@ -962,6 +962,10 @@ static void usa67_glocont_callback(strucfor (i =0 ; i < serial->num_ports; ++i) { port = serial->port[i]; p_priv =usb_get_serial_port_data (port); +if (!p_priv) +continue ; +if (!p_priv) +continue ;if (p_priv->resend_cont) {dev_dbg (&port->dev,"%s - sending setup\n" , __func__);
PATCH 197/245 USB: serial: quatech2: handle unbound ports
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 9715a43eea77e42678a1002623f2d9a78f5b81a1 upstream.
Check for NULL port data in the modem- and line-status handlers to avoid dereferencing a NULL pointer in the unlikely case where a port device isn't bound to a driver (e.g. after an allocation failure on port probe).
Note that the other (stubbed) event handlers qt2_process_xmit_empty() and qt2_process_flush() would need similar sanity checks in case they are ever implemented.
--- drivers/usb/serial/quatech2.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/serial/quatech2.c +6 -0
@@ -872,7 +872,10 @@ static void qt2_update_msr(struct usb_seu8 newMSR = (u8) *ch;unsigned long flags; +/* May be called from qt2_process_read_urb() for an unbound port. */ port_priv =usb_get_serial_port_data (port); +if (!port_priv) +return ;spin_lock_irqsave (&port_priv->lock, flags); port_priv->shadowMSR = newMSR;
@@ -900,7 +903,10 @@ static void qt2_update_lsr(struct usb_seunsigned long flags;u8 newLSR = (u8) *ch; +/* May be called from qt2_process_read_urb() for an unbound port. */ port_priv =usb_get_serial_port_data (port); +if (!port_priv) +return ;if (newLSR &UART_LSR_BI ) newLSR &= (u8) (UART_LSR_OE |UART_LSR_BI );
PATCH 198/245 hwmon: (adt7475) Make volt2reg return same reg as reg2volt input
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Luuk Paulussen <[email protected]>
commit cf3ca1877574a306c0207cbf7fdf25419d9229df upstream.
reg2volt returns the voltage that matches a given register value. Converting this back the other way with volt2reg didn't return the same register value because it used truncation instead of rounding.
This meant that values read from sysfs could not be written back to sysfs to set back the same register value.
With this change, volt2reg will return the same value for every voltage previously returned by reg2volt (for the set of possible input values)
--- drivers/hwmon/adt7475.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/adt7475.c +3 -2
@@ -268,9 +268,10 @@ static inline u16 volt2reg(int channel,long reg;if (bypass_attn & (1 << channel)) - reg = (volt *1024 ) /2250 ; + reg =DIV_ROUND_CLOSEST (volt *1024 ,2250 );else - reg = (volt * r[1 ] *1024 ) / ((r[0 ] + r[1 ]) *2250 ); + reg =DIV_ROUND_CLOSEST (volt * r[1 ] *1024 , + (r[0 ] + r[1 ]) *2250 );return clamp_val (reg,0 ,1023 ) & (0xff <<2 ); }
PATCH 199/245 ARM: 8950/1: ftrace/recordmcount: filter relocation types
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alex Sverdlin <[email protected]>
commit 927d780ee371d7e121cea4fc7812f6ef2cea461c upstream.
Scenario 1, ARMv7
=================
If code in arch/arm/kernel/ftrace.c would operate on mcount() pointer the following may be generated:
00000230 <prealloc_fixed_plts>:
230: b5f8 push {r3, r4, r5, r6, r7, lr}
232: b500 push {lr}
234: f7ff fffe bl 0 <__gnu_mcount_nc>
234: R_ARM_THM_CALL __gnu_mcount_nc
238: f240 0600 movw r6, #0
238: R_ARM_THM_MOVW_ABS_NC __gnu_mcount_nc 23c: f8d0 1180 ldr.w r1, [r0, #384] ; 0x180
FTRACE currently is not able to deal with it:
WARNING: CPU: 0 PID: 0 at .../kernel/trace/ftrace.c:1979 ftrace_bug+0x1ad/0x230() ... CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.116-... #1
...
[<c0314e3d>] (unwind_backtrace) from [<c03115e9>] (show_stack+0x11/0x14) [<c03115e9>] (show_stack) from [<c051a7f1>] (dump_stack+0x81/0xa8) [<c051a7f1>] (dump_stack) from [<c0321c5d>] (warn_slowpath_common+0x69/0x90) [<c0321c5d>] (warn_slowpath_common) from [<c0321cf3>] (warn_slowpath_null+0x17/0x1c) [<c0321cf3>] (warn_slowpath_null) from [<c038ee9d>] (ftrace_bug+0x1ad/0x230) [<c038ee9d>] (ftrace_bug) from [<c038f1f9>] (ftrace_process_locs+0x27d/0x444) [<c038f1f9>] (ftrace_process_locs) from [<c08915bd>] (ftrace_init+0x91/0xe8) [<c08915bd>] (ftrace_init) from [<c0885a67>] (start_kernel+0x34b/0x358) [<c0885a67>] (start_kernel) from [<00308095>] (0x308095)
---[ end trace cb88537fdc8fa200 ]--- ftrace failed to modify [<c031266c>] prealloc_fixed_plts+0x8/0x60 actual: 44:f2:e1:36
ftrace record flags: 0
(0) expected tramp: c03143e9
Scenario 2, ARMv4T
==================
ftrace: allocating 14435 entries in 43 pages
------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:2029 ftrace_bug+0x204/0x310 CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.5 #1 Hardware name: Cirrus Logic EDB9302 Evaluation Board [<c0010a24>] (unwind_backtrace) from [<c000ecb0>] (show_stack+0x20/0x2c) [<c000ecb0>] (show_stack) from [<c03c72e8>] (dump_stack+0x20/0x30) [<c03c72e8>] (dump_stack) from [<c0021c18>] (__warn+0xdc/0x104) [<c0021c18>] (__warn) from [<c0021d7c>] (warn_slowpath_null+0x4c/0x5c) [<c0021d7c>] (warn_slowpath_null) from [<c0095360>] (ftrace_bug+0x204/0x310) [<c0095360>] (ftrace_bug) from [<c04dabac>] (ftrace_init+0x3b4/0x4d4) [<c04dabac>] (ftrace_init) from [<c04cef4c>] (start_kernel+0x20c/0x410) [<c04cef4c>] (start_kernel) from [<00000000>] ( (null)) ---[ end trace 0506a2f5dae6b341 ]--- ftrace failed to modify [<c000c350>] perf_trace_sys_exit+0x5c/0xe8 actual: 1e:ff:2f:e1
Initializing ftrace call sites
ftrace record flags: 0
(0)
expected tramp: c000fb24
The analysis for this problem has been already performed previously, refer to the link below.
Fix the above problems by allowing only selected reloc types in __mcount_loc. The list itself comes from the legacy recordmcount.pl script.
--- scripts/recordmcount.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
scripts/recordmcount.c +17 -0
@@ -52,6 +52,10 @@#define R_AARCH64_ABS64 257#endif +#define R_ARM_PC24 1 +#define R_ARM_THM_CALL 10 +#define R_ARM_CALL 28 +static int fd_map;/* File descriptor for file being modified. */ static int mmap_failed;/* Boolean flag. */ static char gpfx;/* prefix for global symbol name (sometimes '_') */
@@ -355,6 +359,18 @@ is_mcounted_section_name(char const *con#define RECORD_MCOUNT_64 #include "recordmcount.h" +static int arm_is_fake_mcount (Elf32_Rel const *rp) +{ +switch (ELF32_R_TYPE (w (rp->r_info))) { +case R_ARM_THM_CALL : +case R_ARM_CALL : +case R_ARM_PC24 : +return 0 ; + } + +return 1 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
@@ -443,6 +459,7 @@ do_file(char const *const fname)break ;case EM_ARM : reltype =R_ARM_ABS32 ; altmcount ="__gnu_mcount_nc" ; + is_fake_mcount32 = arm_is_fake_mcount;break ;case EM_AARCH64 : reltype =R_AARCH64_ABS64 ; gpfx ='_' ;break ;
PATCH 200/245 mmc: sdhci: fix minimum clock rate for v3 controller
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michał Mirosław <[email protected]>
commit 2a187d03352086e300daa2044051db00044cd171 upstream.
For SDHCIv3+ with programmable clock mode, minimal clock frequency is still base clock / max(divider). Minimal programmable clock frequency is always greater than minimal divided clock frequency. Without this patch, SDHCI uses out-of-spec initial frequency when multiplier is big enough:
mmc1: mmc_rescan_try_freq: trying to init card at 468750 Hz [for 480 MHz source clock divided by 1024]
The code in sdhci_calc_clk() already chooses a correct SDCLK clock mode.
--- drivers/mmc/host/sdhci.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci.c +6 -4
@@ -2945,11 +2945,13 @@ int sdhci_add_host(struct sdhci_host *hoif (host->ops->get_min_clock) mmc->f_min = host->ops->get_min_clock (host);else if (host->version >=SDHCI_SPEC_300 ) { -if (host->clk_mul) { - mmc->f_min = (host->max_clk * host->clk_mul) /1024 ; +if (host->clk_mul) mmc->f_max = host->max_clk * host->clk_mul; - }else - mmc->f_min = host->max_clk /SDHCI_MAX_DIV_SPEC_300 ; +/* +* Divided Clock Mode minimum clock rate is always less than +* Programmable Clock Mode minimum clock rate. +*/ + mmc->f_min = host->max_clk /SDHCI_MAX_DIV_SPEC_300 ; }else mmc->f_min = host->max_clk /SDHCI_MAX_DIV_SPEC_200 ;
PATCH 201/245 can, slip: Protect tty->disc_data in write_wakeup and close with RCU
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Richard Palethorpe <[email protected]>
commit 0ace17d56824165c7f4c68785d6b58971db954dd upstream.
write_wakeup can happen in parallel with close/hangup where tty->disc_data is set to NULL and the netdevice is freed thus also freeing disc_data. write_wakeup accesses disc_data so we must prevent close from freeing the netdev while write_wakeup has a non-NULL view of tty->disc_data.
We also need to make sure that accesses to disc_data are atomic. Which can all be done with RCU.
This problem was found by Syzkaller on SLCAN, but the same issue is reproducible with the SLIP line discipline using an LTP test based on the Syzkaller reproducer.
A fix which didn't use RCU was posted by Hillf Danton.
--- drivers/net/can/slcan.c | 12 ++++++++++-- drivers/net/slip/slip.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/net/can/slcan.c +10 -2
@@ -346,9 +346,16 @@ static void slcan_transmit(struct work_s*/ static void slcan_write_wakeup (struct tty_struct *tty) { -struct slcan *sl = tty->disc_data; +struct slcan *sl; + +rcu_read_lock (); + sl =rcu_dereference (tty->disc_data); +if (!sl) + goto out;schedule_work (&sl->tx_work); +out: +rcu_read_unlock (); }/* Send a can_frame to a TTY queue. */
@@ -640,10 +647,11 @@ static void slcan_close(struct tty_strucreturn ;spin_lock_bh (&sl->lock); - tty->disc_data =NULL ; +rcu_assign_pointer (tty->disc_data,NULL ); sl->tty =NULL ;spin_unlock_bh (&sl->lock); +synchronize_rcu ();flush_work (&sl->tx_work);/* Flush network side */
drivers/net/slip/slip.c +10 -2
@@ -452,9 +452,16 @@ static void slip_transmit(struct work_st*/ static void slip_write_wakeup (struct tty_struct *tty) { -struct slip *sl = tty->disc_data; +struct slip *sl; + +rcu_read_lock (); + sl =rcu_dereference (tty->disc_data); +if (!sl) + goto out;schedule_work (&sl->tx_work); +out: +rcu_read_unlock (); }static void sl_tx_timeout (struct net_device *dev)
@@ -885,10 +892,11 @@ static void slip_close(struct tty_structreturn ;spin_lock_bh (&sl->lock); - tty->disc_data =NULL ; +rcu_assign_pointer (tty->disc_data,NULL ); sl->tty =NULL ;spin_unlock_bh (&sl->lock); +synchronize_rcu ();flush_work (&sl->tx_work);/* VSV = very important to remove timers */
PATCH 202/245 net: sonic: return NETDEV_TX_OK if failed to map buffer
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mao Wenan <[email protected]>
commit 6e1cdedcf0362fed3aedfe051d46bd7ee2a85fe1 upstream.
NETDEV_TX_BUSY really should only be used by drivers that call netif_tx_stop_queue() at the wrong moment. If dma_map_single() is failed to map tx DMA buffer, it might trigger an infinite loop. This patch use NETDEV_TX_OK instead of NETDEV_TX_BUSY, and change printk to pr_err_ratelimited.
--- drivers/net/ethernet/natsemi/sonic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +2 -2
@@ -221,9 +221,9 @@ static int sonic_send_packet(struct sk_b laddr =dma_map_single (lp->device, skb->data, length,DMA_TO_DEVICE );if (!laddr) { -printk (KERN_ERR "%s: failed to map tx DMA buffer.\n" , dev->name); +pr_err_ratelimited ("%s: failed to map tx DMA buffer.\n" , dev->name);dev_kfree_skb (skb); -return NETDEV_TX_BUSY ; +return NETDEV_TX_OK ; }sonic_tda_put (dev, entry,SONIC_TD_STATUS ,0 );/* clear status */
PATCH 203/245 net/sonic: Add mutual exclusion for accessing shared state
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit 865ad2f2201dc18685ba2686f13217f8b3a9c52c upstream.
The netif_stop_queue() call in sonic_send_packet() races with the netif_wake_queue() call in sonic_interrupt(). This causes issues like "NETDEV WATCHDOG: eth0 (macsonic): transmit queue 0 timed out". Fix this by disabling interrupts when accessing tx_skb[] and next_tx. Update a comment to clarify the synchronization properties.
--- drivers/net/ethernet/natsemi/sonic.c | 49 ++++++++++++++++++++-------- drivers/net/ethernet/natsemi/sonic.h | 1 + 2 files changed, 36 insertions(+), 14 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +35 -14
@@ -50,6 +50,8 @@ static int sonic_open(struct net_deviceif (sonic_debug >2 )printk ("sonic_open: initializing sonic driver.\n" ); +spin_lock_init (&lp->lock); +for (i =0 ; i <SONIC_NUM_RRS ; i++) {struct sk_buff *skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 );if (skb ==NULL ) {
@@ -194,8 +196,6 @@ static void sonic_tx_timeout(struct net_* wake the tx queue * Concurrently with all of this, the SONIC is potentially writing to * the status flags of the TDs. -* Until some mutual exclusion is added, this code will not work with SMP. However, -* MIPS Jazz machines and m68k Macs were all uni-processor machines. */ static int sonic_send_packet (struct sk_buff *skb,struct net_device *dev)
@@ -203,7 +203,8 @@ static int sonic_send_packet(struct sk_bstruct sonic_local *lp =netdev_priv (dev);dma_addr_t laddr;int length; -int entry = lp->next_tx; +int entry; +unsigned long flags;if (sonic_debug >2 )printk ("sonic_send_packet: skb=%p, dev=%p\n" , skb, dev);
@@ -226,6 +227,10 @@ static int sonic_send_packet(struct sk_breturn NETDEV_TX_OK ; } +spin_lock_irqsave (&lp->lock, flags); + + entry = lp->next_tx; +sonic_tda_put (dev, entry,SONIC_TD_STATUS ,0 );/* clear status */ sonic_tda_put (dev, entry,SONIC_TD_FRAG_COUNT ,1 );/* single fragment */ sonic_tda_put (dev, entry,SONIC_TD_PKTSIZE , length);/* length of packet */
@@ -235,10 +240,6 @@ static int sonic_send_packet(struct sk_bsonic_tda_put (dev, entry,SONIC_TD_LINK ,sonic_tda_get (dev, entry,SONIC_TD_LINK ) |SONIC_EOL ); -/* -* Must set tx_skb[entry] only after clearing status, and -* before clearing EOL and before stopping queue -*/ wmb (); lp->tx_len[entry] = length; lp->tx_laddr[entry] = laddr;
@@ -263,6 +264,8 @@ static int sonic_send_packet(struct sk_bSONIC_WRITE (SONIC_CMD ,SONIC_CR_TXP ); +spin_unlock_irqrestore (&lp->lock, flags); +return NETDEV_TX_OK ; }
@@ -275,9 +278,21 @@ static irqreturn_t sonic_interrupt(int istruct net_device *dev = dev_id;struct sonic_local *lp =netdev_priv (dev);int status; +unsigned long flags; + +/* The lock has two purposes. Firstly, it synchronizes sonic_interrupt() +* with sonic_send_packet() so that the two functions can share state. +* Secondly, it makes sonic_interrupt() re-entrant, as that is required +* by macsonic which must use two IRQs with different priority levels. +*/ +spin_lock_irqsave (&lp->lock, flags); + + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; +if (!status) { +spin_unlock_irqrestore (&lp->lock, flags); -if (!(status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ))return IRQ_NONE ; + } do { if (status & SONIC_INT_PKTRX) {
@@ -292,11 +307,12 @@ static irqreturn_t sonic_interrupt(int iint td_status;int freed_some =0 ; -/* At this point, cur_tx is the index of a TD that is one of: -* unallocated/freed (status set & tx_skb[entry] clear) -* allocated and sent (status set & tx_skb[entry] set ) -* allocated and not yet sent (status clear & tx_skb[entry] set ) -* still being allocated by sonic_send_packet (status clear & tx_skb[entry] clear) +/* The state of a Transmit Descriptor may be inferred +* from { tx_skb[entry], td_status } as follows. +* { clear, clear } => the TD has never been used +* { set, clear } => the TD was handed to SONIC +* { set, set } => the TD was handed back +* { clear, set } => the TD is available for re-use */ if (sonic_debug >2 )
@@ -398,7 +414,12 @@ static irqreturn_t sonic_interrupt(int i/* load CAM done */ if (status &SONIC_INT_LCD )SONIC_WRITE (SONIC_ISR ,SONIC_INT_LCD );/* clear the interrupt */ - }while ((status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT )); + + status =SONIC_READ (SONIC_ISR ) &SONIC_IMR_DEFAULT ; + }while (status); + +spin_unlock_irqrestore (&lp->lock, flags); +return IRQ_HANDLED ; }
drivers/net/ethernet/natsemi/sonic.h +1 -0
@@ -320,6 +320,7 @@ struct sonic_local {unsigned int next_tx;/* next free TD */ struct device *device;/* generic device */ struct net_device_stats stats; +spinlock_t lock; };#define TX_TIMEOUT (3 * HZ)
PATCH 204/245 net/sonic: Use MMIO accessors
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit e3885f576196ddfc670b3d53e745de96ffcb49ab upstream.
The driver accesses descriptor memory which is simultaneously accessed by the chip, so the compiler must not be allowed to re-order CPU accesses. sonic_buf_get() used 'volatile' to prevent that. sonic_buf_put() should have done so too but was overlooked.
--- drivers/net/ethernet/natsemi/sonic.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/ethernet/natsemi/sonic.h +8 -8
@@ -342,30 +342,30 @@ static void sonic_tx_timeout(struct net_as far as we can tell. */ /* OpenBSD calls this "SWO". I'd like to think that sonic_buf_put() is a much better name. */ -static inline void sonic_buf_put (void * base,int bitmode, +static inline void sonic_buf_put (u16 *base,int bitmode,int offset,__u16 val) { if (bitmode)#ifdef __BIG_ENDIAN - ((__u16 *) base + (offset*2 ))[1 ] = val; +__raw_writew (val, base + (offset *2 ) +1 );#else - ((__u16 *) base + (offset*2 ))[0 ] = val; +__raw_writew (val, base + (offset *2 ) +0 );#endif else - ((__u16 *) base)[offset] = val; + __raw_writew(val, base + (offset * 1) + 0); } -static inline __u16 sonic_buf_get (void * base,int bitmode, +static inline __u16 sonic_buf_get (u16 *base,int bitmode,int offset) { if (bitmode)#ifdef __BIG_ENDIAN -return ((volatile __u16 *) base + (offset*2 ))[1 ]; +return __raw_readw (base + (offset *2 ) +1 );#else -return ((volatile __u16 *) base + (offset*2 ))[0 ]; +return __raw_readw (base + (offset *2 ) +0 );#endif else - return ((volatile __u16 *) base)[offset]; + return __raw_readw(base + (offset * 1) + 0); }/* Inlines that you should actually use for reading/writing DMA buffers */
PATCH 205/245 net/sonic: Fix receive buffer handling
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit 9e311820f67e740f4fb8dcb82b4c4b5b05bdd1a5 upstream.
The SONIC can sometimes advance its rx buffer pointer (RRP register) without advancing its rx descriptor pointer (CRDA register). As a result the index of the current rx descriptor may not equal that of the current rx buffer. The driver mistakenly assumes that they are always equal. This assumption leads to incorrect packet lengths and possible packet duplication. Avoid this by calling a new function to locate the buffer corresponding to a given descriptor.
--- drivers/net/ethernet/natsemi/sonic.c | 35 ++++++++++++++++++++++++---- drivers/net/ethernet/natsemi/sonic.h | 5 ++-- 2 files changed, 33 insertions(+), 7 deletions(-)
drivers/net/ethernet/natsemi/sonic.c +30 -5
@@ -423,6 +423,21 @@ static irqreturn_t sonic_interrupt(int ireturn IRQ_HANDLED ; } +/* Return the array index corresponding to a given Receive Buffer pointer. */ +static int index_from_addr (struct sonic_local *lp,dma_addr_t addr, +unsigned int last) +{ +unsigned int i = last; + +do { + i = (i +1 ) &SONIC_RRS_MASK ; +if (addr == lp->rx_laddr[i]) +return i; + }while (i != last); + +return -ENOENT ; +} +/* * We have a good packet(s), pass it/them up the network stack. */
@@ -442,6 +457,16 @@ static void sonic_rx(struct net_device * status =sonic_rda_get (dev, entry,SONIC_RD_STATUS );if (status &SONIC_RCR_PRX ) { +u32 addr = (sonic_rda_get (dev, entry, +SONIC_RD_PKTPTR_H ) <<16 ) | +sonic_rda_get (dev, entry,SONIC_RD_PKTPTR_L ); +int i =index_from_addr (lp, addr, entry); + +if (i <0 ) { +WARN_ONCE (1 ,"failed to find buffer!\n" ); +break ; + } +/* Malloc up new buffer. */ new_skb =netdev_alloc_skb (dev,SONIC_RBSIZE +2 );if (new_skb ==NULL ) {
@@ -463,7 +488,7 @@ static void sonic_rx(struct net_device */* now we have a new skb to replace it, pass the used one up the stack */ dma_unmap_single (lp->device, lp->rx_laddr[entry],SONIC_RBSIZE ,DMA_FROM_DEVICE ); - used_skb = lp->rx_skb[entry]; + used_skb = lp->rx_skb[i]; pkt_len =sonic_rda_get (dev, entry,SONIC_RD_PKTLEN );skb_trim (used_skb, pkt_len); used_skb->protocol =eth_type_trans (used_skb, dev);
@@ -472,13 +497,13 @@ static void sonic_rx(struct net_device * lp->stats.rx_bytes += pkt_len;/* and insert the new skb */ - lp->rx_laddr[entry] = new_laddr; - lp->rx_skb[entry] = new_skb; + lp->rx_laddr[i] = new_laddr; + lp->rx_skb[i] = new_skb; bufadr_l = (unsigned long )new_laddr &0xffff ; bufadr_h = (unsigned long )new_laddr >>16 ; -sonic_rra_put (dev, entry,SONIC_RR_BUFADR_L , bufadr_l); -sonic_rra_put (dev, entry,SONIC_RR_BUFADR_H , bufadr_h); +sonic_rra_put (dev, i,SONIC_RR_BUFADR_L , bufadr_l); +sonic_rra_put (dev, i,SONIC_RR_BUFADR_H , bufadr_h); }else {/* This should only happen, if we enable accepting broken packets. */ lp->stats.rx_errors++;
drivers/net/ethernet/natsemi/sonic.h +3 -2
@@ -273,8 +273,9 @@#define SONIC_NUM_RDS SONIC_NUM_RRS/* number of receive descriptors */ #define SONIC_NUM_TDS 16/* number of transmit descriptors */ -#define SONIC_RDS_MASK (SONIC_NUM_RDS-1) -#define SONIC_TDS_MASK (SONIC_NUM_TDS-1) +#define SONIC_RRS_MASK (SONIC_NUM_RRS - 1) +#define SONIC_RDS_MASK (SONIC_NUM_RDS - 1) +#define SONIC_TDS_MASK (SONIC_NUM_TDS - 1)#define SONIC_RBSIZE 1520/* size of one resource buffer */
PATCH 206/245 net/sonic: Quiesce SONIC before re-initializing descriptor memory
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit 3f4b7e6a2be982fd8820a2b54d46dd9c351db899 upstream.
Make sure the SONIC's DMA engine is idle before altering the transmit and receive descriptors. Add a helper for this as it will be needed again.
--- drivers/net/ethernet/natsemi/sonic.c | 25 +++++++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 3 +++ 2 files changed, 28 insertions(+)
drivers/net/ethernet/natsemi/sonic.c +25 -0
@@ -103,6 +103,24 @@ static int sonic_open(struct net_devicereturn 0 ; } +/* Wait for the SONIC to become idle. */ +static void sonic_quiesce (struct net_device *dev,u16 mask) +{ +struct sonic_local *__maybe_unused lp =netdev_priv (dev); +int i; +u16 bits; + +for (i =0 ; i <1000 ; ++i) { + bits =SONIC_READ (SONIC_CMD ) & mask; +if (!bits) +return ; +if (irqs_disabled () ||in_interrupt ()) +udelay (20 ); +else +usleep_range (100 ,200 ); + } +WARN_ONCE (1 ,"command deadline expired! 0x%04x\n" , bits); +}/* * Close the SONIC device
@@ -120,6 +138,9 @@ static int sonic_close(struct net_device/* * stop the SONIC, disable interrupts */ +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL ); +SONIC_WRITE (SONIC_IMR ,0 );SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RST );
@@ -159,6 +180,9 @@ static void sonic_tx_timeout(struct net_* put the Sonic into software-reset mode and * disable all interrupts before releasing DMA buffers */ +SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL ); +SONIC_WRITE (SONIC_IMR ,0 );SONIC_WRITE (SONIC_ISR ,0x7fff );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RST );
@@ -638,6 +662,7 @@ static int sonic_init(struct net_device*/ SONIC_WRITE (SONIC_CMD ,0 );SONIC_WRITE (SONIC_CMD ,SONIC_CR_RXDIS ); +sonic_quiesce (dev,SONIC_CR_ALL );/* * initialize the receive resource area
drivers/net/ethernet/natsemi/sonic.h +3 -0
@@ -109,6 +109,9 @@#define SONIC_CR_TXP 0x0002#define SONIC_CR_HTX 0x0001 +#define SONIC_CR_ALL (SONIC_CR_LCAM | SONIC_CR_RRRA | \ + SONIC_CR_RXEN | SONIC_CR_TXP) +/* * SONIC data configuration bits */
PATCH 207/245 net_sched: fix datalen for ematch
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 61678d28d4a45ef376f5d02a839cc37509ae9281 upstream.
syzbot reported an out-of-bound access in em_nbyte. As initially analyzed by Eric, this is because em_nbyte sets its own em->datalen in em_nbyte_change() other than the one specified by user, but this value gets overwritten later by its caller tcf_em_validate(). We should leave em->datalen untouched to respect their choices.
I audit all the in-tree ematch users, all of those implement ->change() set em->datalen, so we can just avoid setting it twice in this case.
--- net/sched/ematch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/ematch.c +1 -1
@@ -266,12 +266,12 @@ static int tcf_em_validate(struct tcf_pr } em->data = (unsigned long ) v; } + em->datalen = data_len; } } em->matchid = em_hdr->matchid; em->flags = em_hdr->flags; - em->datalen = data_len; err =0 ; errout:
PATCH 208/245 namei: allow restricted O_CREAT of FIFOs and regular files
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Salvatore Mesoraca <[email protected]>
commit 30aba6656f61ed44cba445a3c0d38b296fa9e8f5 upstream.
Disallows open of FIFOs or regular files not owned by the user in world writable sticky directories, unless the owner is the same as that of the directory or the file is opened without the O_CREAT flag. The purpose is to make data spoofing attacks harder. This protection can be turned on and off separately for FIFOs and regular files via sysctl, just like the symlinks/hardlinks protection. This patch is based on Openwall's "HARDEN_FIFO" feature by Solar Designer.
This is a brief list of old vulnerabilities that could have been prevented by this feature, some of them even allow for privilege escalation:
CVE-2000-1134
CVE-2007-3852
CVE-2008-0525
CVE-2009-0416
CVE-2011-4834
CVE-2015-1838
CVE-2015-7442
CVE-2016-7489
This list is not meant to be complete. It's difficult to track down all vulnerabilities of this kind because they were often reported without any mention of this particular attack vector. In fact, before hardlinks/symlinks restrictions, fifos/regular files weren't the favorite vehicle to exploit them.
--- Documentation/sysctl/fs.txt | 36 +++++++++++++++++++++++++ fs/namei.c | 53 ++++++++++++++++++++++++++++++++++--- include/linux/fs.h | 2 ++ kernel/sysctl.c | 18 +++++++++++++ 4 files changed, 106 insertions(+), 3 deletions(-)
Documentation/sysctl/fs.txt +36 -0
@@ -34,7 +34,9 @@ Currently, these files are in /proc/sys/ - overflowgid - pipe-user-pages-hard - pipe-user-pages-soft +- protected_fifos - protected_hardlinks +- protected_regular - protected_symlinks - suid_dumpable - super-max
@@ -182,6 +184,24 @@ applied. ============================================================== +protected_fifos: + +The intent of this protection is to avoid unintentional writes to +an attacker-controlled FIFO, where a program expected to create a regular +file. + +When set to "0", writing to FIFOs is unrestricted. + +When set to "1" don't allow O_CREAT open on FIFOs that we don't own +in world writable sticky directories, unless they are owned by the +owner of the directory. + +When set to "2" it also applies to group writable sticky directories. + +This protection is based on the restrictions in Openwall. + +============================================================== + protected_hardlinks: A long-standing class of security issues is the hardlink-based
@@ -202,6 +222,22 @@ This protection is based on the restrict ============================================================== +protected_regular: + +This protection is similar to protected_fifos, but it +avoids writes to an attacker-controlled regular file, where a program +expected to create one. + +When set to "0", writing to regular files is unrestricted. + +When set to "1" don't allow O_CREAT open on regular files that we +don't own in world writable sticky directories, unless they are +owned by the owner of the directory. + +When set to "2" it also applies to group writable sticky directories. + +============================================================== + protected_symlinks: A long-standing class of security issues is the symlink-based
fs/namei.c +50 -3
71 lines not on this page · raw message
include/linux/fs.h +2 -0
@@ -61,6 +61,8 @@ extern struct inodes_stat_t inodes_stat;extern int leases_enable, lease_break_time;extern int sysctl_protected_symlinks;extern int sysctl_protected_hardlinks; +extern int sysctl_protected_fifos; +extern int sysctl_protected_regular;struct buffer_head ; typedef int (get_block_t)(struct inode *inode, sector_t iblock,
kernel/sysctl.c +18 -0
@@ -1653,6 +1653,24 @@ static struct ctl_table fs_table[] = { .extra2 = &one, }, { + .procname = "protected_fifos", + .data = &sysctl_protected_fifos, + .maxlen = sizeof(int), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &two, + }, + { + .procname = "protected_regular", + .data = &sysctl_protected_regular, + .maxlen = sizeof(int), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &two, + }, + { .procname = "suid_dumpable", .data = &suid_dumpable, .maxlen = sizeof(int),
Re: [PATCH 3.16 208/245] namei: allow restricted O_CREAT of FIFOs and regular files
Quoted 1 line · Ben Hutchings
3.16.83-rc1 review patch. If anyone has any objections, please let me know.
I do. This patch is currently known-buggy, see this thread:
https://www.openwall.com/lists/oss-security/2020/01/28/2
It is (partially) fixed with these newer commits in 5.5 and 5.5.2:
commit d0cb50185ae942b03c4327be322055d622dc79f6
Author: Al Viro <[email protected]> Date: Sun Jan 26 09:29:34 2020 -0500
do_last(): fetch directory ->i_mode and ->i_uid before it's too late
may_create_in_sticky() call is done when we already have dropped the reference to dir.
commit d76341d93dedbcf6ed5a08dfc8bce82d3e9a772b
Author: Al Viro <[email protected]> Date: Sat Feb 1 16:26:45 2020 +0000
vfs: fix do_last() regression
commit 6404674acd596de41fd3ad5f267b4525494a891a upstream.
Brown paperbag time: fetching ->i_uid/->i_mode really should've been done from nd->inode. I even suggested that, but the reason for that has slipped through the cracks and I went for dir->d_inode instead - made for more "obvious" patch.
Analysis:
- at the entry into do_last() and all the way to step_into(): dir (aka nd->path.dentry) is known not to have been freed; so's nd->inode and it's equal to dir->d_inode unless we are already doomed to -ECHILD. inode of the file to get opened is not known.
- after step_into(): inode of the file to get opened is known; dir might be pointing to freed memory/be negative/etc.
- at the call of may_create_in_sticky(): guaranteed to be out of RCU mode; inode of the file to get opened is known and pinned; dir might be garbage.
The last was the reason for the original patch. Except that at the do_last() entry we can be in RCU mode and it is possible that nd->path.dentry->d_inode has already changed under us.
In that case we are going to fail with -ECHILD, but we need to be careful; nd->inode is pointing to valid struct inode and it's the same as nd->path.dentry->d_inode in "won't fail with -ECHILD" case, so we should use that.
Wearing-brown-paperbag: Al Viro <[email protected]>
At least inclusion of the above fixes is mandatory for any backports.
Also, I think no one has fixed the logic of may_create_in_sticky() so that it wouldn't unintentionally apply the "protection" when the file is neither a FIFO nor a regular file (something I found and mentioned in the oss-security posting above).
Quoted 28 lines
fs/namei.c +28
-0+/** +* may_create_in_sticky - Check whether an O_CREAT open in a sticky directory +* should be allowed, or not, on files that already +* exist. +* @dir: the sticky parent directory +* @inode: the inode of the file to open +* +* Block an O_CREAT open of a FIFO (or a regular file) when: +* - sysctl_protected_fifos (or sysctl_protected_regular) is enabled +* - the file already exists +* - we are in a sticky directory +* - we don't own the file +* - the owner of the directory doesn't own the file +* - the directory is world writable +* If the sysctl_protected_fifos (or sysctl_protected_regular) is set to 2 +* the directory doesn't have to be world writable: being group writable will +* be enough. +* +* Returns 0 if the open is allowed, -ve on error. +*/ +static int may_create_in_sticky (struct dentry *const dir, +struct inode *const inode) +{ +if ((!sysctl_protected_fifos &&S_ISFIFO (inode->i_mode)) || + (!sysctl_protected_regular &&S_ISREG (inode->i_mode)) || +likely (!(dir->d_inode->i_mode &S_ISVTX )) || +uid_eq (inode->i_uid, dir->d_inode->i_uid) || +uid_eq (current_fsuid (), inode->i_uid))
fs/namei.c static int may_linkat(struct path *link) · line 879
Quoted 10 lines
fs/namei.c +10
-0+return 0 ; + +if (likely (dir->d_inode->i_mode &0002 ) || + (dir->d_inode->i_mode &0020 && + ((sysctl_protected_fifos >=2 &&S_ISFIFO (inode->i_mode)) || + (sysctl_protected_regular >=2 &&S_ISREG (inode->i_mode))))) { +return -EACCES ; + } +return 0 ; +}
I think the implementation of may_create_in_sticky() should be rewritten such that it'd directly correspond to the textual description in the comment above. As we've seen, trying to write the code "more optimally" resulted in its logic actually being different from the description.
Meanwhile, I think backporting known-so-buggy code is a bad idea.
Alexander
Re: [PATCH 3.16 208/245] namei: allow restricted O_CREAT of FIFOs and regular files
Quoted 28 lines · Solar Designer
Quoted 1 line · Ben Hutchings
3.16.83-rc1 review patch. If anyone has any objections, please let me know.
I do. This patch is currently known-buggy, see this thread:
https://www.openwall.com/lists/oss-security/2020/01/28/2
It is (partially) fixed with these newer commits in 5.5 and 5.5.2:
commit
d0cb50185ae942b03c4327be322055d622dc79f6Author: Al Viro <[email protected]> Date: Sun Jan 26 09:29:34 2020 -0500
do_last(): fetch directory ->i_mode and ->i_uid before it's too late
may_create_in_sticky()call is done when we already have dropped the reference to dir.Fixes 30aba6656f61e (namei: allow restricted O_CREAT of FIFOs and regular files)Signed-off-by Al Viro <[email protected]>commit
d76341d93dedbcf6ed5a08dfc8bce82d3e9a772bAuthor: Al Viro <[email protected]> Date: Sat Feb 1 16:26:45 2020 +0000vfs: fix
do_last()regressioncommit
6404674acd596de41fd3ad5f267b4525494a891aupstream.
[...]
Quoted 1 line
At least inclusion of the above fixes is mandatory for any backports.
I know, and those are the next 2 patches in the series.
Quoted 4 lines
Also, I think no one has fixed the logic of
may_create_in_sticky()so that it wouldn't unintentionally apply the "protection" when the file is neither a FIFO nor a regular file (something I found and mentioned in the oss-security posting above).
[...]
Quoted 6 lines
I think the implementation of
may_create_in_sticky()should be rewritten such that it'd directly correspond to the textual description in the comment above. As we've seen, trying to write the code "more optimally" resulted in its logic actually being different from the description.Meanwhile, I think backporting known-so-buggy code is a bad idea.
I can see that it's not quite right, but does it matter in practice? Directories and symlinks are handled separately; sockets can't be opened anyway; block and character devices wonn't normally appear in a sticky directory.
Ben.
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
Re: [PATCH 3.16 208/245] namei: allow restricted O_CREAT of FIFOs and regular files
Quoted 26 lines · Ben Hutchings
Quoted 25 lines · Solar Designer
Quoted 1 line · Ben Hutchings
3.16.83-rc1 review patch. If anyone has any objections, please let me know.
I do. This patch is currently known-buggy, see this thread:
https://www.openwall.com/lists/oss-security/2020/01/28/2
It is (partially) fixed with these newer commits in 5.5 and 5.5.2:
commit
d0cb50185ae942b03c4327be322055d622dc79f6Author: Al Viro <[email protected]> Date: Sun Jan 26 09:29:34 2020 -0500
do_last(): fetch directory ->i_mode and ->i_uid before it's too late
may_create_in_sticky()call is done when we already have dropped the reference to dir.Fixes 30aba6656f61e (namei: allow restricted O_CREAT of FIFOs and regular files)Signed-off-by Al Viro <[email protected]>commit
d76341d93dedbcf6ed5a08dfc8bce82d3e9a772bAuthor: Al Viro <[email protected]> Date: Sat Feb 1 16:26:45 2020 +0000
Quoted 7 lines
Quoted 3 lines
vfs: fix
do_last()regressioncommit
6404674acd596de41fd3ad5f267b4525494a891aupstream.[...]
Quoted 1 line
At least inclusion of the above fixes is mandatory for any backports.
I know, and those are the next 2 patches in the series.
Ah, then no objections from me.
Quoted 10 lines
Quoted 4 lines
Also, I think no one has fixed the logic of
may_create_in_sticky()so that it wouldn't unintentionally apply the "protection" when the file is neither a FIFO nor a regular file (something I found and mentioned in the oss-security posting above).[...]
Quoted 5 lines
I think the implementation of
may_create_in_sticky()should be rewritten such that it'd directly correspond to the textual description in the comment above. As we've seen, trying to write the code "more optimally" resulted in its logic actually being different from the description.
Quoted 6 lines
Quoted 1 line
Meanwhile, I think backporting known-so-buggy code is a bad idea.
I can see that it's not quite right, but does it matter in practice? Directories and symlinks are handled separately; sockets can't be opened anyway; block and character devices wonn't normally appear in a sticky directory.
Clearly, it doesn't matter all that much in practice - I'm not aware of anyone having complained about it causing issues on their system.
I think it primarily mattered as an attack vector on the issue fixed with Al's commits above.
I think we should nevertheless fix the code to match its intent and the comment, but meanwhile this isn't a blocker for the backport.
Alexander
PATCH 209/245 do_last(): fetch directory ->i_mode and ->i_uid before it's too late
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit d0cb50185ae942b03c4327be322055d622dc79f6 upstream.
may_create_in_sticky() call is done when we already have dropped the reference to dir.
--- fs/namei.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
fs/namei.c +10 -7
@@ -843,7 +843,8 @@ static int may_linkat(struct path *link)* may_create_in_sticky - Check whether an O_CREAT open in a sticky directory * should be allowed, or not, on files that already * exist. -* @dir: the sticky parent directory +* @dir_mode: mode bits of directory +* @dir_uid: owner of directory * @inode: the inode of the file to open * * Block an O_CREAT open of a FIFO (or a regular file) when:
@@ -859,18 +860,18 @@ static int may_linkat(struct path *link)* * Returns 0 if the open is allowed, -ve on error. */ -static int may_create_in_sticky (struct dentry *const dir, +static int may_create_in_sticky (umode_t dir_mode,kuid_t dir_uid,struct inode *const inode) {if ((!sysctl_protected_fifos &&S_ISFIFO (inode->i_mode)) || (!sysctl_protected_regular &&S_ISREG (inode->i_mode)) || -likely (!(dir->d_inode->i_mode &S_ISVTX )) || -uid_eq (inode->i_uid, dir->d_inode->i_uid) || +likely (!(dir_mode &S_ISVTX )) || +uid_eq (inode->i_uid, dir_uid) ||uid_eq (current_fsuid (), inode->i_uid))return 0 ; -if (likely (dir->d_inode->i_mode &0002 ) || - (dir->d_inode->i_mode &0020 && +if (likely (dir_mode &0002 ) || + (dir_mode &0020 && ((sysctl_protected_fifos >=2 &&S_ISFIFO (inode->i_mode)) || (sysctl_protected_regular >=2 &&S_ISREG (inode->i_mode))))) {return -EACCES ;
@@ -2944,6 +2945,8 @@ static int do_last(struct nameidata *nd, int *opened, struct filename *name) { struct dentry *dir = nd->path.dentry; +kuid_t dir_uid = dir->d_inode->i_uid; +umode_t dir_mode = dir->d_inode->i_mode;int open_flag = op->open_flag;bool will_truncate = (open_flag &O_TRUNC ) !=0 ;bool got_write = false;
@@ -3102,7 +3105,7 @@ finish_open: error = -EISDIR ;if (d_is_dir (nd->path.dentry)) goto out; - error =may_create_in_sticky (dir, + error =may_create_in_sticky (dir_mode, dir_uid,d_backing_inode (nd->path.dentry));if (unlikely (error)) goto out;
PATCH 210/245 vfs: fix do_last() regression
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 6404674acd596de41fd3ad5f267b4525494a891a upstream.
Brown paperbag time: fetching ->i_uid/->i_mode really should've been done from nd->inode. I even suggested that, but the reason for that has slipped through the cracks and I went for dir->d_inode instead - made for more "obvious" patch.
Analysis:
- at the entry into do_last() and all the way to step_into(): dir (aka nd->path.dentry) is known not to have been freed; so's nd->inode and it's equal to dir->d_inode unless we are already doomed to -ECHILD. inode of the file to get opened is not known.
- after step_into(): inode of the file to get opened is known; dir might be pointing to freed memory/be negative/etc.
- at the call of may_create_in_sticky(): guaranteed to be out of RCU mode; inode of the file to get opened is known and pinned; dir might be garbage.
The last was the reason for the original patch. Except that at the do_last() entry we can be in RCU mode and it is possible that nd->path.dentry->d_inode has already changed under us.
In that case we are going to fail with -ECHILD, but we need to be careful; nd->inode is pointing to valid struct inode and it's the same as nd->path.dentry->d_inode in "won't fail with -ECHILD" case, so we should use that.
Wearing-brown-paperbag: Al Viro <[email protected]>
--- fs/namei.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/namei.c +2 -2
@@ -2945,8 +2945,8 @@ static int do_last(struct nameidata *nd, int *opened, struct filename *name) { struct dentry *dir = nd->path.dentry; -kuid_t dir_uid = dir->d_inode->i_uid; -umode_t dir_mode = dir->d_inode->i_mode; +kuid_t dir_uid = nd->inode->i_uid; +umode_t dir_mode = nd->inode->i_mode;int open_flag = op->open_flag;bool will_truncate = (open_flag &O_TRUNC ) !=0 ;bool got_write = false;
PATCH 211/245 blktrace: re-write setting q->blk_trace
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Davidlohr Bueso <[email protected]>
commit cdea01b2bf98affb7e9c44530108a4a28535eee8 upstream.
This is really about simplifying the double xchg patterns into a single cmpxchg, with the same logic. Other than the immediate cleanup, there are some subtleties this change deals with:
(i) While the load of the old bt is fully ordered wrt everything, ie:
old_bt = xchg(&q->blk_trace, bt); [barrier]
if (old_bt)
(void) xchg(&q->blk_trace, old_bt); [barrier]blk_trace could still be changed between the xchg and the old_bt load. Note that this description is merely theoretical and afaict very small, but doing everything in a single context with cmpxchg closes this potential race.
(ii) Ordering guarantees are obviously kept with cmpxchg.
(iii) Gets rid of the hacky-by-nature (void)xchg pattern.
--- kernel/trace/blktrace.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
kernel/trace/blktrace.c +5 -11
@@ -448,7 +448,7 @@ int do_blk_trace_setup(struct request_qustruct block_device *bdev, struct blk_user_trace_setup *buts) { - struct blk_trace *old_bt, *bt = NULL; + struct blk_trace *bt = NULL;struct dentry *dir =NULL ;int ret, i;
@@ -532,11 +532,8 @@ int do_blk_trace_setup(struct request_qu bt->trace_state = Blktrace_setup; ret = -EBUSY ; - old_bt =xchg (&q->blk_trace, bt); -if (old_bt) { - (void )xchg (&q->blk_trace, old_bt); +if (cmpxchg (&q->blk_trace,NULL , bt)) goto err; - }if (atomic_inc_return (&blk_probes_ref) ==1 )blk_register_tracepoints ();
@@ -1550,7 +1547,7 @@ static int blk_trace_remove_queue(structstatic int blk_trace_setup_queue (struct request_queue *q,struct block_device *bdev) { -struct blk_trace *old_bt, *bt =NULL ; +struct blk_trace *bt =NULL ;int ret = -ENOMEM ; bt =kzalloc (sizeof (*bt),GFP_KERNEL );
@@ -1566,12 +1563,9 @@ static int blk_trace_setup_queue(structblk_trace_setup_lba (bt, bdev); - old_bt =xchg (&q->blk_trace, bt); -if (old_bt !=NULL ) { - (void )xchg (&q->blk_trace, old_bt); - ret = -EBUSY ; + ret = -EBUSY ; +if (cmpxchg (&q->blk_trace,NULL , bt)) goto free_bt; - }if (atomic_inc_return (&blk_probes_ref) ==1 )blk_register_tracepoints ();
PATCH 212/245 blktrace: Protect q->blk_trace with RCU
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit c780e86dd48ef6467a1146cf7d0fe1e05a635039 upstream.
KASAN is reporting that __blk_add_trace() has a use-after-free issue when accessing q->blk_trace. Indeed the switching of block tracing (and thus eventual freeing of q->blk_trace) is completely unsynchronized with the currently running tracing and thus it can happen that the blk_trace structure is being freed just while __blk_add_trace() works on it. Protect accesses to q->blk_trace by RCU during tracing and make sure we wait for the end of RCU grace period when shutting down tracing. Luckily that is rare enough event that we can afford that. Note that postponing the freeing of blk_trace to an RCU callback should better be avoided as it could have unexpected user visible side-effects as debugfs files would be still existing for a short while block tracing has been shut down.
[bwh: Backported to 3.16:
- Drop changes in blk_trace_note_message_enabled(), blk_trace_bio_get_cgid()
- Adjust context]
---
include/linux/blkdev.h +1 -1
@@ -447,7 +447,7 @@ struct request_queue {unsigned int sg_reserved_size;int node;#ifdef CONFIG_BLK_DEV_IO_TRACE -struct blk_trace *blk_trace; +struct blk_trace __rcu *blk_trace;struct mutex blk_trace_mutex;#endif /*
include/linux/blktrace_api.h +5 -1
@@ -51,9 +51,13 @@ void __trace_note_message(struct blk_tra**/ #define blk_add_trace_msg (q, fmt, ...) \ do { \ - struct blk_trace *bt = (q)->blk_trace; \ + struct blk_trace *bt; \ + \ + rcu_read_lock(); \ + bt = rcu_dereference((q)->blk_trace); \ if (unlikely(bt)) \ __trace_note_message(bt, fmt, ##__VA_ARGS__); \ + rcu_read_unlock(); \ } while (0)#define BLK_TN_MAX_MSG 128
kernel/trace/blktrace.c +80 -30
306 lines not on this page · raw message
PATCH 213/245 blktrace: fix dereference after null check
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cengiz Can <[email protected]>
commit 153031a301bb07194e9c37466cfce8eacb977621 upstream.
There was a recent change in blktrace.c that added a RCU protection to q->blk_trace in order to fix a use-after-free issue during access.
However the change missed an edge case that can lead to dereferencing of bt pointer even when it's NULL:
Coverity static analyzer marked this as a FORWARD_NULL issue with CID 1460458.
```
/kernel/trace/blktrace.c: 1904 in sysfs_blk_trace_attr_store()
1898 ret = 0;
1899 if (bt == NULL)
1900 ret = blk_trace_setup_queue(q, bdev);
1901
1902 if (ret == 0) {
1903 if (attr == &dev_attr_act_mask)
>>> CID 1460458: Null pointer dereferences (FORWARD_NULL)
>>> Dereferencing null pointer "bt".
1904 bt->act_mask = value;
1905 else if (attr == &dev_attr_pid)
1906 bt->pid = value;
1907 else if (attr == &dev_attr_start_lba)
1908 bt->start_lba = value;
1909 else if (attr == &dev_attr_end_lba)
```Added a reassignment with RCU annotation to fix the issue.
--- kernel/trace/blktrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/blktrace.c +4 -1
@@ -1834,8 +1834,11 @@ static ssize_t sysfs_blk_trace_attr_stor } ret =0 ; -if (bt ==NULL ) +if (bt ==NULL ) { ret =blk_trace_setup_queue (q, bdev); + bt =rcu_dereference_protected (q->blk_trace, +lockdep_is_held (&q->blk_trace_mutex)); + }if (ret ==0 ) {if (attr == &dev_attr_act_mask)
PATCH 214/245 Input: add safety guards to input_set_keycode()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit cb222aed03d798fc074be55e59d9a112338ee784 upstream.
If we happen to have a garbage in input device's keycode table with values too big we'll end up doing clear_bit() with offset way outside of our bitmaps, damaging other objects within an input device or even outside of it. Let's add sanity checks to the returned old keycodes.
--- drivers/input/input.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/input/input.c +16 -10
@@ -841,16 +841,18 @@ static int input_default_setkeycode(stru } } -__clear_bit (*old_keycode, dev->keybit); -__set_bit (ke->keycode, dev->keybit); - -for (i =0 ; i < dev->keycodemax; i++) { -if (input_fetch_keycode (dev, i) == *old_keycode) { -__set_bit (*old_keycode, dev->keybit); -break ;/* Setting the bit twice is useless, so break */ +if (*old_keycode <=KEY_MAX ) { +__clear_bit (*old_keycode, dev->keybit); +for (i =0 ; i < dev->keycodemax; i++) { +if (input_fetch_keycode (dev, i) == *old_keycode) { +__set_bit (*old_keycode, dev->keybit); +/* Setting the bit twice is useless, so break */ +break ; + } } } +__set_bit (ke->keycode, dev->keybit);return 0 ; }
@@ -906,9 +908,13 @@ int input_set_keycode(struct input_dev ** Simulate keyup event if keycode is not present * in the keymap anymore */ -if (test_bit (EV_KEY , dev->evbit) && - !is_event_supported (old_keycode, dev->keybit,KEY_MAX ) && -__test_and_clear_bit (old_keycode, dev->key)) { +if (old_keycode >KEY_MAX ) { +dev_warn (dev->dev.parent ?: &dev->dev, +"%s: got too big old keycode %#x\n" , + __func__, old_keycode); + }else if (test_bit (EV_KEY , dev->evbit) && + !is_event_supported (old_keycode, dev->keybit,KEY_MAX ) && +__test_and_clear_bit (old_keycode, dev->key)) {struct input_value vals[] = { {EV_KEY , old_keycode,0 }, input_value_sync
PATCH 215/245 staging: android: ashmem: Disallow ashmem memory from being remapped
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Suren Baghdasaryan <[email protected]>
commit 6d67b0290b4b84c477e6a2fc6e005e174d3c7786 upstream.
When ashmem file is mmapped, the resulting vma->vm_file points to the backing shmem file with the generic fops that do not check ashmem permissions like fops of ashmem do. If an mremap is done on the ashmem region, then the permission checks will be skipped. Fix that by disallowing mapping operation on the backing shmem file.
--- drivers/staging/android/ashmem.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/staging/android/ashmem.c +28 -0
@@ -351,8 +351,23 @@ static inline vm_flags_t calc_vm_may_fla_calc_vm_trans (prot,PROT_EXEC ,VM_MAYEXEC ); } +static int ashmem_vmfile_mmap (struct file *file,struct vm_area_struct *vma) +{ +/* do not allow to mmap ashmem backing shmem file directly */ +return -EPERM ; +} + +static unsigned long +ashmem_vmfile_get_unmapped_area (struct file *file,unsigned long addr, +unsigned long len,unsigned long pgoff, +unsigned long flags) +{ +return current->mm->get_unmapped_area (file, addr, len, pgoff, flags); +} +static int ashmem_mmap (struct file *file,struct vm_area_struct *vma) { +static struct file_operations vmfile_fops;struct ashmem_area *asma = file->private_data;int ret =0 ;
@@ -386,6 +401,19 @@ static int ashmem_mmap(struct file *file goto out; } asma->file = vmfile; +/* +* override mmap operation of the vmfile so that it can't be +* remapped which would lead to creation of a new vma with no +* asma permission checks. Have to override get_unmapped_area +* as well to prevent VM_BUG_ON check for f_ops modification. +*/ +if (!vmfile_fops.mmap) { + vmfile_fops = *vmfile->f_op; + vmfile_fops.mmap = ashmem_vmfile_mmap; + vmfile_fops.get_unmapped_area = + ashmem_vmfile_get_unmapped_area; + } + vmfile->f_op = &vmfile_fops; }get_file (asma->file);
PATCH 216/245 net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sabrina Dubroca <[email protected]>
commit 6c8991f41546c3c472503dff1ea9daaddf9331c2 upstream.
ipv6_stub uses the ip6_dst_lookup function to allow other modules to perform IPv6 lookups. However, this function skips the XFRM layer entirely.
All users of ipv6_stub->ip6_dst_lookup use ip_route_output_flow (via the ip_route_output_key and ip_route_output helpers) for their IPv4 lookups, which calls xfrm_lookup_route(). This patch fixes this inconsistent behavior by switching the stub to ip6_dst_lookup_flow, which also calls xfrm_lookup_route().
This requires some changes in all the callers, as these two functions take different arguments and have different return types.
[bwh: Backported to 3.16:
- Only vxlan uses this operation
- Neither ip6_dst_lookup() nor ip6_dst_lookup_flow() takes a struct net pointer argument here
- Adjust filename, context]
---
drivers/net/vxlan.c +2 -1
@@ -1929,7 +1929,8 @@ static void vxlan_xmit_one(struct sk_buf fl6.saddr = vxlan->saddr.sin6.sin6_addr; fl6.flowi6_proto =IPPROTO_UDP ; -if (ipv6_stub->ipv6_dst_lookup (sk, &ndst, &fl6)) { + ndst = ipv6_stub->ipv6_dst_lookup_flow (sk, &fl6,NULL ); +if (unlikely (IS_ERR (ndst))) {netdev_dbg (dev,"no route to %pI6\n" , &dst->sin6.sin6_addr); dev->stats.tx_carrier_errors++;
include/net/addrconf.h +3 -2
@@ -156,8 +156,9 @@ struct ipv6_stub { const struct in6_addr *addr);int (*ipv6_sock_mc_drop)(struct sock *sk,int ifindex,const struct in6_addr *addr); -int (*ipv6_dst_lookup)(struct sock *sk,struct dst_entry **dst, -struct flowi6 *fl6); +struct dst_entry *(*ipv6_dst_lookup_flow)(struct sock *sk, +struct flowi6 *fl6, +const struct in6_addr *final_dst);void (*udpv6_encap_enable)(void ); void (*ndisc_send_na)(struct net_device *dev, struct neighbour *neigh, const struct in6_addr *daddr,
net/ipv6/af_inet6.c +1 -1
@@ -820,7 +820,7 @@ static struct pernet_operations inet6_nestatic const struct ipv6_stub ipv6_stub_impl = { .ipv6_sock_mc_join = ipv6_sock_mc_join, .ipv6_sock_mc_drop = ipv6_sock_mc_drop, - .ipv6_dst_lookup = ip6_dst_lookup, + .ipv6_dst_lookup_flow = ip6_dst_lookup_flow, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na, .nd_tbl = &nd_tbl,
PATCH 217/245 KVM: nVMX: Don't emulate instructions in guest mode
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Bonzini <[email protected]>
commit 07721feee46b4b248402133228235318199b05ec upstream.
vmx_check_intercept is not yet fully implemented. To avoid emulating instructions disallowed by the L1 hypervisor, refuse to emulate instructions by default.
--- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx.c +1 -1
@@ -8938,7 +8938,7 @@ static int vmx_check_intercept(struct kvstruct x86_instruction_info *info, enum x86_intercept_stage stage) { - return X86EMUL_CONTINUE; + return X86EMUL_UNHANDLEABLE; } static struct kvm_x86_ops vmx_x86_ops = {
PATCH 218/245 vgacon: Fix a UAF in vgacon_invert_region
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Xiaoxu <[email protected]>
commit 513dc792d6060d5ef572e43852683097a8420f56 upstream.
When syzkaller tests, there is a UAF:
BUG: KASan: use after free in vgacon_invert_region+0x9d/0x110 at addr
ffff880000100000
Read of size 2 by task syz-executor.1/16489
page:ffffea0000004000 count:0 mapcount:-127 mapping: (null)
index:0x0
page flags: 0xfffff00000000()
page dumped because: kasan: bad access detected
CPU: 1 PID: 16489 Comm: syz-executor.1 Not tainted
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
Call Trace:
[<ffffffffb119f309>] dump_stack+0x1e/0x20
[<ffffffffb04af957>] kasan_report+0x577/0x950
[<ffffffffb04ae652>] __asan_load2+0x62/0x80
[<ffffffffb090f26d>] vgacon_invert_region+0x9d/0x110
[<ffffffffb0a39d95>] invert_screen+0xe5/0x470
[<ffffffffb0a21dcb>] set_selection+0x44b/0x12f0
[<ffffffffb0a3bfae>] tioclinux+0xee/0x490
[<ffffffffb0a1d114>] vt_ioctl+0xff4/0x2670
[<ffffffffb0a0089a>] tty_ioctl+0x46a/0x1a10
[<ffffffffb052db3d>] do_vfs_ioctl+0x5bd/0xc40
[<ffffffffb052e2f2>] SyS_ioctl+0x132/0x170
[<ffffffffb11c9b1b>] system_call_fastpath+0x22/0x27
Memory state around the buggy address:
ffff8800000fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00
ffff8800000fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00
>ffff880000100000: ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ffIt can be reproduce in the linux mainline by the program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
struct tiocl_selection {
unsigned short xs; /* X start */
unsigned short ys; /* Y start */
unsigned short xe; /* X end */
unsigned short ye; /* Y end */ unsigned short sel_mode; /* selection mode */
};
#define TIOCL_SETSEL 2
struct tiocl {
unsigned char type;
unsigned char pad;
struct tiocl_selection sel;
};
int main()
{
int fd = 0;
const char *dev = "/dev/char/4:1"; struct vt_consize v = {0};
struct tiocl tioc = {0};
fd = open(dev, O_RDWR, 0);
v.v_rows = 3346;
ioctl(fd, VT_RESIZEX, &v);
tioc.type = TIOCL_SETSEL;
ioctl(fd, TIOCLINUX, &tioc);
return 0;}
When resize the screen, update the 'vc->vc_size_row' to the new_row_size, but when 'set_origin' in 'vgacon_set_origin', vgacon use 'vga_vram_base' for 'vc_origin' and 'vc_visible_origin', not 'vc_screenbuf'. It maybe smaller than 'vc_screenbuf'. When TIOCLINUX, use the new_row_size to calc the offset, it maybe larger than the vga_vram_size in vgacon driver, then bad access.
Also, if set an larger screenbuf firstly, then set an more larger screenbuf, when copy old_origin to new_origin, a bad access may happen.
So, If the screen size larger than vga_vram, resize screen should be failed. This alse fix CVE-2020-8649 and CVE-2020-8647.
Linus pointed out that overflow checking seems absent. We're saved by the existing bounds checks in vc_do_resize() with rather strict limits:
if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW) return -EINVAL;
Reference: CVE-2020-8647 and CVE-2020-8649
--- drivers/video/console/vgacon.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/video/console/vgacon.c +3 -0
@@ -1312,6 +1312,9 @@ static int vgacon_font_get(struct vc_datstatic int vgacon_resize (struct vc_data *c,unsigned int width,unsigned int height,unsigned int user) { +if ((width <<1 ) * height > vga_vram_size) +return -EINVAL ; +if (width %2 || width > screen_info.orig_video_cols || height > (screen_info.orig_video_lines * vga_default_font_height)/ c->vc_font.height)
PATCH 219/245 tty: vt: Fix !TASK_RUNNING diagnostic warning from paste_selection()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Hurley <[email protected]>
commit 61e86cc90af49cecef9c54ccea1f572fbcb695ac upstream.
Pasting text with gpm on a VC produced warning [1]. Reset task state to TASK_RUNNING in the paste_selection() loop, if the loop did not sleep.
[1]
WARNING: CPU: 6 PID: 1960 at /home/peter/src/kernels/mainline/kernel/sched/core.c:7286 __might_sleep+0x7f/0x90() do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffff8151805e>] paste_selection+0x9e/0x1a0 Modules linked in: btrfs xor raid6_pq ufs qnx4 hfsplus hfs minix ntfs msdos jfs xfs libcrc32c ..... CPU: 6 PID: 1960 Comm: gpm Not tainted 4.1.0-rc7+tty-xeon+debug #rc7+tty Hardware name: Dell Inc. Precision WorkStation T5400 /0RW203, BIOS A11 04/30/2012 ffffffff81c9c0a0 ffff8802b0fd3ac8 ffffffff8185778a 0000000000000001 ffff8802b0fd3b18 ffff8802b0fd3b08 ffffffff8108039a ffffffff82ae8510 ffffffff81c9ce00 0000000000000015 0000000000000000 0000000000000000 Call Trace: [<ffffffff8185778a>] dump_stack+0x4f/0x7b [<ffffffff8108039a>] warn_slowpath_common+0x8a/0xc0 [<ffffffff81080416>] warn_slowpath_fmt+0x46/0x50 [<ffffffff810ddced>] ? __lock_acquire+0xe2d/0x13a0 [<ffffffff8151805e>] ? paste_selection+0x9e/0x1a0 [<ffffffff8151805e>] ? paste_selection+0x9e/0x1a0 [<ffffffff810ad4ff>] __might_sleep+0x7f/0x90 [<ffffffff8185f76a>] down_read+0x2a/0xa0 [<ffffffff810bb1d8>] ? sched_clock_cpu+0xb8/0xe0 [<ffffffff8150d1dc>] n_tty_receive_buf_common+0x4c/0xba0 [<ffffffff810dc875>] ? mark_held_locks+0x75/0xa0 [<ffffffff81861c95>] ? _raw_spin_unlock_irqrestore+0x65/0x80 [<ffffffff810b49a1>] ? get_parent_ip+0x11/0x50 [<ffffffff8150dd44>] n_tty_receive_buf2+0x14/0x20 [<ffffffff81518117>] paste_selection+0x157/0x1a0 [<ffffffff810b77b0>] ? wake_up_state+0x20/0x20 [<ffffffff815203f8>] tioclinux+0xb8/0x2c0 [<ffffffff81515bfe>] vt_ioctl+0xaee/0x11a0 [<ffffffff810baf75>] ? sched_clock_local+0x25/0x90 [<ffffffff810bbe11>] ? vtime_account_user+0x91/0xa0 [<ffffffff8150810c>] tty_ioctl+0x20c/0xe20 [<ffffffff810bbe11>] ? vtime_account_user+0x91/0xa0 [<ffffffff810b49a1>] ? get_parent_ip+0x11/0x50 [<ffffffff810b4a69>] ? preempt_count_sub+0x49/0x50 [<ffffffff811ab71c>] ? context_tracking_exit+0x5c/0x290 [<ffffffff811ab71c>] ? context_tracking_exit+0x5c/0x290 [<ffffffff81248b98>] do_vfs_ioctl+0x318/0x570 [<ffffffff810dca8d>] ? trace_hardirqs_on+0xd/0x10 [<ffffffff810dc9b5>] ? trace_hardirqs_on_caller+0x115/0x1e0 [<ffffffff81254acc>] ? __fget_light+0x6c/0xa0 [<ffffffff81248e71>] SyS_ioctl+0x81/0xa0 [<ffffffff81862832>] system_call_fastpath+0x16/0x7a
--- drivers/tty/vt/selection.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/vt/selection.c +1 -0
@@ -356,6 +356,7 @@ int paste_selection(struct tty_struct *tschedule ();continue ; } +__set_current_state (TASK_RUNNING ); count = sel_buffer_lth - pasted; count =tty_ldisc_receive_buf (ld, sel_buffer + pasted,NULL , count);
PATCH 220/245 vt: selection, handle pending signals in paste_selection
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby <[email protected]>
commit 687bff0cd08f790d540cfb7b2349f0d876cdddec upstream.
When pasting a selection to a vt, the task is set as INTERRUPTIBLE while waiting for a tty to unthrottle. But signals are not handled at all. Normally, this is not a problem as tty_ldisc_receive_buf receives all the goods and a user has no reason to interrupt the task.
There are two scenarios where this matters:
1) when the tty is throttled and a signal is sent to the process, it spins on a CPU until the tty is unthrottled. schedule() does not really echedule, but returns immediately, of course.
2) when the sel_buffer becomes invalid, KASAN prevents any reads from it and the loop simply does not proceed and spins forever (causing the tty to throttle, but the code never sleeps, the same as above). This sometimes happens as there is a race in the sel_buffer handling code.
So add signal handling to this ioctl (TIOCL_PASTESEL) and return -EINTR in case a signal is pending.
[bwh: Backported to 3.16:
- No need to include <linux/sched/signal.h>
- Adjust context]
---
drivers/tty/vt/selection.c +6 -1
@@ -341,6 +341,7 @@ int paste_selection(struct tty_struct *tunsigned int count;struct tty_ldisc *ld;DECLARE_WAITQUEUE (wait, current); +int ret =0 ;console_lock ();poke_blanked_console ();
@@ -352,6 +353,10 @@ int paste_selection(struct tty_struct *tadd_wait_queue (&vc->paste_wait, &wait);while (sel_buffer && sel_buffer_lth > pasted) {set_current_state (TASK_INTERRUPTIBLE ); +if (signal_pending (current)) { + ret = -EINTR ; +break ; + }if (test_bit (TTY_THROTTLED , &tty->flags)) {schedule ();continue ;
@@ -367,5 +372,5 @@ int paste_selection(struct tty_struct *ttty_buffer_unlock_exclusive (&vc->port);tty_ldisc_deref (ld); -return 0 ; +return ret; }
PATCH 221/245 vt: selection, close sel_buffer race
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby <[email protected]>
commit 07e6124a1a46b4b5a9b3cacc0c306b50da87abf5 upstream.
syzkaller reported this UAF:
BUG: KASAN: use-after-free in n_tty_receive_buf_common+0x2481/0x2940 drivers/tty/n_tty.c:1741 Read of size 1 at addr ffff8880089e40e9 by task syz-executor.1/13184 CPU: 0 PID: 13184 Comm: syz-executor.1 Not tainted 5.4.7 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 Call Trace: ... kasan_report+0xe/0x20 mm/kasan/common.c:634 n_tty_receive_buf_common+0x2481/0x2940 drivers/tty/n_tty.c:1741 tty_ldisc_receive_buf+0xac/0x190 drivers/tty/tty_buffer.c:461 paste_selection+0x297/0x400 drivers/tty/vt/selection.c:372 tioclinux+0x20d/0x4e0 drivers/tty/vt/vt.c:3044 vt_ioctl+0x1bcf/0x28d0 drivers/tty/vt/vt_ioctl.c:364 tty_ioctl+0x525/0x15a0 drivers/tty/tty_io.c:2657 vfs_ioctl fs/ioctl.c:47 [inline]
It is due to a race between parallel paste_selection (TIOCL_PASTESEL) and set_selection_user (TIOCL_SETSEL) invocations. One uses sel_buffer, while the other frees it and reallocates a new one for another selection. Add a mutex to close this race.
The mutex takes care properly of sel_buffer and sel_buffer_lth only. The other selection global variables (like sel_start, sel_end, and sel_cons) are protected only in set_selection_user. The other functions need quite some more work to close the races of the variables there. This is going to happen later.
This likely fixes (I am unsure as there is no reproducer provided) bug 206361 too. It was marked as CVE-2020-8648.
References: https://bugzilla.kernel.org/show_bug.cgi?id=206361
--- drivers/tty/vt/selection.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/tty/vt/selection.c +17 -6
@@ -13,6 +13,7 @@#include <linux/tty.h> #include <linux/sched.h> #include <linux/mm.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <linux/types.h>
@@ -40,6 +41,7 @@ static volatile int sel_start = -1; /*static int sel_end;static int sel_buffer_lth;static char *sel_buffer; +static DEFINE_MUTEX (sel_lock);/* clear_selection, highlight and highlight_pointer can be called from interrupt (via scrollback/front) */
@@ -163,7 +165,7 @@ int set_selection(const struct tiocl_selchar *bp, *obp;int i, ps, pe, multiplier;u16 c; -int mode; +int mode, ret =0 ;poke_blanked_console ();
@@ -203,6 +205,7 @@ int set_selection(const struct tiocl_sel pe = tmp; } +mutex_lock (&sel_lock);if (sel_cons != vc_cons[fg_console].d) {clear_selection (); sel_cons = vc_cons[fg_console].d;
@@ -248,9 +251,10 @@ int set_selection(const struct tiocl_selbreak ;case TIOCL_SELPOINTER :highlight_pointer (pe); -return 0 ; + goto unlock;default : -return -EINVAL ; + ret = -EINVAL ; + goto unlock; }/* remove the pointer */
@@ -272,7 +276,7 @@ int set_selection(const struct tiocl_selelse if (new_sel_start == sel_start) {if (new_sel_end == sel_end)/* no action required */ -return 0 ; + goto unlock;else if (new_sel_end > sel_end)/* extend to right */ highlight (sel_end +2 , new_sel_end);else /* contract from right */
@@ -299,7 +303,8 @@ int set_selection(const struct tiocl_selif (!bp) {printk (KERN_WARNING "selection: kmalloc() failed\n" );clear_selection (); -return -ENOMEM ; + ret = -ENOMEM ; + goto unlock; }kfree (sel_buffer); sel_buffer = bp;
@@ -324,7 +329,9 @@ int set_selection(const struct tiocl_sel } } sel_buffer_lth = bp - sel_buffer; -return 0 ; +unlock: +mutex_unlock (&sel_lock); +return ret; }/* Insert the contents of the selection buffer into the
@@ -351,6 +358,7 @@ int paste_selection(struct tty_struct *ttty_buffer_lock_exclusive (&vc->port);add_wait_queue (&vc->paste_wait, &wait); +mutex_lock (&sel_lock);while (sel_buffer && sel_buffer_lth > pasted) {set_current_state (TASK_INTERRUPTIBLE );if (signal_pending (current)) {
@@ -358,7 +366,9 @@ int paste_selection(struct tty_struct *tbreak ; }if (test_bit (TTY_THROTTLED , &tty->flags)) { +mutex_unlock (&sel_lock);schedule (); +mutex_lock (&sel_lock);continue ; }__set_current_state (TASK_RUNNING );
@@ -367,6 +377,7 @@ int paste_selection(struct tty_struct *t count); pasted += count; } +mutex_unlock (&sel_lock);remove_wait_queue (&vc->paste_wait, &wait);__set_current_state (TASK_RUNNING );
PATCH 222/245 vt: selection, push console lock down
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby <[email protected]>
commit 4b70dd57a15d2f4685ac6e38056bad93e81e982f upstream.
We need to nest the console lock in sel_lock, so we have to push it down a bit. Fortunately, the callers of set_selection_* just lock the console lock around the function call. So moving it down is easy.
In the next patch, we switch the order.
--- drivers/tty/vt/selection.c | 13 ++++++++++++- drivers/tty/vt/vt.c | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/tty/vt/selection.c +12 -1
@@ -158,7 +158,7 @@ static int store_utf8(u16 c, char *p)* The entire selection process is managed under the console_lock. It's * a lot under the lock but its hardly a performance path */ -int set_selection (const struct tiocl_selection __user *sel,struct tty_struct *tty) +static int __set_selection (const struct tiocl_selection __user *sel,struct tty_struct *tty) {struct vc_data *vc = vc_cons[fg_console].d;int sel_mode, new_sel_start, new_sel_end, spc;
@@ -334,6 +334,17 @@ unlock:return ret; } +int set_selection (const struct tiocl_selection __user *v,struct tty_struct *tty) +{ +int ret; + +console_lock (); + ret =__set_selection (v, tty); +console_unlock (); + +return ret; +} +/* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl().
drivers/tty/vt/vt.c +0 -2
@@ -2670,9 +2670,7 @@ int tioclinux(struct tty_struct *tty, unswitch (type) {case TIOCL_SETSEL : -console_lock (); ret =set_selection ((struct tiocl_selection __user *)(p+1 ), tty); -console_unlock ();break ;case TIOCL_PASTESEL : ret =paste_selection (tty);
PATCH 223/245 vt: selection, push sel_lock up
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby <[email protected]>
commit e8c75a30a23c6ba63f4ef6895cbf41fd42f21aa2 upstream.
sel_lock cannot nest in the console lock. Thanks to syzkaller, the kernel states firmly:
Quoted 11 lines
WARNING: possible circular locking dependency detected
5.6.0-rc3-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor.4/20336 is trying to acquire lock:ffff8880a2e952a0(&tty->termios_rwsem){++++}, at:tty_unthrottle+0x22/0x100drivers/tty/tty_ioctl.c:136but task is already holding lock:
ffffffff89462e70(sel_lock){+.+.}, at:paste_selection+0x118/0x470drivers/tty/vt/selection.c:374which lock already depends on the new lock.
Quoted 8 lines
the existing dependency chain (in reverse order) is:
-> #2 (sel_lock){+.+.}:
mutex_lock_nested+0x1b/0x30 kernel/locking/mutex.c:1118 set_selection_kernel+0x3b8/0x18a0 drivers/tty/vt/selection.c:217 set_selection_user+0x63/0x80 drivers/tty/vt/selection.c:181 tioclinux+0x103/0x530 drivers/tty/vt/vt.c:3050 vt_ioctl+0x3f1/0x3a30 drivers/tty/vt/vt_ioctl.c:364
This is ioctl(TIOCL_SETSEL).
Locks held on the path: console_lock -> sel_lock
Quoted 6 lines
-> #1 (console_lock){+.+.}:
console_lock+0x46/0x70 kernel/printk/printk.c:2289 con_flush_chars+0x50/0x650 drivers/tty/vt/vt.c:3223 n_tty_write+0xeae/0x1200 drivers/tty/n_tty.c:2350 do_tty_write drivers/tty/tty_io.c:962 [inline] tty_write+0x5a1/0x950 drivers/tty/tty_io.c:1046
This is write().
Locks held on the path: termios_rwsem -> console_lock
Quoted 8 lines
-> #0 (&tty->termios_rwsem){++++}:
down_write+0x57/0x140 kernel/locking/rwsem.c:1534 tty_unthrottle+0x22/0x100 drivers/tty/tty_ioctl.c:136 mkiss_receive_buf+0x12aa/0x1340 drivers/net/hamradio/mkiss.c:902 tty_ldisc_receive_buf+0x12f/0x170 drivers/tty/tty_buffer.c:465 paste_selection+0x346/0x470 drivers/tty/vt/selection.c:389 tioclinux+0x121/0x530 drivers/tty/vt/vt.c:3055 vt_ioctl+0x3f1/0x3a30 drivers/tty/vt/vt_ioctl.c:364
This is ioctl(TIOCL_PASTESEL).
Locks held on the path: sel_lock -> termios_rwsem
Quoted 4 lines
other info that might help us debug this:
Chain exists of: &tty->termios_rwsem --> console_lock --> sel_lock
Clearly. From the above, we have:
console_lock -> sel_lock
sel_lock -> termios_rwsem
termios_rwsem -> console_lock
Fix this by reversing the console_lock -> sel_lock dependency in ioctl(TIOCL_SETSEL). First, lock sel_lock, then console_lock.
--- drivers/tty/vt/selection.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/tty/vt/selection.c +7 -9
@@ -205,7 +205,6 @@ static int __set_selection(const struct pe = tmp; } -mutex_lock (&sel_lock);if (sel_cons != vc_cons[fg_console].d) {clear_selection (); sel_cons = vc_cons[fg_console].d;
@@ -251,10 +250,9 @@ static int __set_selection(const structbreak ;case TIOCL_SELPOINTER :highlight_pointer (pe); - goto unlock; +return 0 ;default : - ret = -EINVAL ; - goto unlock; +return -EINVAL ; }/* remove the pointer */
@@ -276,7 +274,7 @@ static int __set_selection(const structelse if (new_sel_start == sel_start) {if (new_sel_end == sel_end)/* no action required */ - goto unlock; +return 0 ;else if (new_sel_end > sel_end)/* extend to right */ highlight (sel_end +2 , new_sel_end);else /* contract from right */
@@ -303,8 +301,7 @@ static int __set_selection(const structif (!bp) {printk (KERN_WARNING "selection: kmalloc() failed\n" );clear_selection (); - ret = -ENOMEM ; - goto unlock; +return -ENOMEM ; }kfree (sel_buffer); sel_buffer = bp;
@@ -329,8 +326,7 @@ static int __set_selection(const struct } } sel_buffer_lth = bp - sel_buffer; -unlock: -mutex_unlock (&sel_lock); +return ret; }
@@ -338,9 +334,11 @@ int set_selection(const struct tiocl_sel {int ret; +mutex_lock (&sel_lock);console_lock (); ret =__set_selection (v, tty);console_unlock (); +mutex_unlock (&sel_lock);return ret; }
PATCH 224/245 floppy: check FDC index for errors before assigning it
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
commit 2e90ca68b0d2f5548804f22f0dd61145516171e3 upstream.
Jordy Zomer reported a KASAN out-of-bounds read in the floppy driver in wait_til_ready().
Which on the face of it can't happen, since as Willy Tarreau points out, the function does no particular memory access. Except through the FDCS macro, which just indexes a static allocation through teh current fdc, which is always checked against N_FDC.
Except the checking happens after we've already assigned the value.
The floppy driver is a disgrace (a lot of it going back to my original horrd "design"), and has no real maintainer. Nobody has the hardware, and nobody really cares. But it still gets used in virtual environment because it's one of those things that everybody supports.
The whole thing should be re-written, or at least parts of it should be seriously cleaned up. The 'current fdc' index, which is used by the FDCS macro, and which is often shadowed by a local 'fdc' variable, is a prime example of how not to write code.
But because nobody has the hardware or the motivation, let's just fix up the immediate problem with a nasty band-aid: test the fdc index before actually assigning it to the static 'fdc' variable.
--- drivers/block/floppy.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/block/floppy.c +5 -2
@@ -847,14 +847,17 @@ static void reset_fdc_info(int mode)/* selects the fdc and drive, and enables the fdc's input/dma. */ static void set_fdc (int drive) { +unsigned int new_fdc = fdc; +if (drive >=0 && drive <N_DRIVE ) { - fdc =FDC (drive); + new_fdc =FDC (drive); current_drive = drive; } -if (fdc !=1 && fdc !=0 ) { +if (new_fdc >=N_FDC ) {pr_info ("bad fdc value\n" );return ; } + fdc = new_fdc;set_dor (fdc, ~0 ,8 );#if N_FDC >1 set_dor (1 - fdc, ~8 ,0 );
PATCH 225/245 vhost: Check docket sk_family instead of call getname
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eugenio Pérez <[email protected]>
commit 42d84c8490f9f0931786f1623191fcab397c3d64 upstream.
Doing so, we save one call to get data we already have in the struct.
Also, since there is no guarantee that getname use sockaddr_ll parameter beyond its size, we add a little bit of security here. It should do not do beyond MAX_ADDR_LEN, but syzbot found that ax25_getname writes more (72 bytes, the size of full_sockaddr_ax25, versus 20 + 32 bytes of sockaddr_ll + MAX_ADDR_LEN in syzbot repro).
---
drivers/vhost/net.c +2 -11
@@ -843,11 +843,7 @@ static int vhost_net_release(struct inodstatic struct socket *get_raw_socket (int fd) { -struct { -struct sockaddr_ll sa; -char buf[MAX_ADDR_LEN ]; - } uaddr; -int uaddr_len =sizeof uaddr, r; +int r;struct socket *sock =sockfd_lookup (fd, &r);if (!sock)
@@ -859,12 +855,7 @@ static struct socket *get_raw_socket(int goto err; } - r = sock->ops->getname (sock, (struct sockaddr *)&uaddr.sa, - &uaddr_len,0 ); -if (r) - goto err; - -if (uaddr.sa.sll_family !=AF_PACKET ) { +if (sock->sk->sk_family !=AF_PACKET ) { r = -EPFNOSUPPORT ; goto err; }
PATCH 226/245 mm: mempolicy: require at least one nodeid for MPOL_PREFERRED
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
commit aa9f7d5172fac9bf1f09e678c35e287a40a7b7dd upstream.
Using an empty (malformed) nodelist that is not caught during mount option parsing leads to a stack-out-of-bounds access.
The option string that was used was: "mpol=prefer:,". However, MPOL_PREFERRED requires a single node number, which is not being provided here.
Add a check that 'nodes' is not empty after parsing for MPOL_PREFERRED's nodeid.
--- mm/mempolicy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/mempolicy.c +5 -1
@@ -2711,7 +2711,9 @@ int mpol_parse_str(char *str, struct memswitch (mode) {case MPOL_PREFERRED :/* -* Insist on a nodelist of one node only +* Insist on a nodelist of one node only, although later +* we use first_node(nodes) to grab a single node, so here +* nodelist (or nodes) cannot be empty. */ if (nodelist) {char *rest = nodelist;
@@ -2719,6 +2721,8 @@ int mpol_parse_str(char *str, struct mem rest++;if (*rest) goto out; +if (nodes_empty (nodes)) + goto out; }break ;case MPOL_INTERLEAVE :
PATCH 227/245 media: ov519: add missing endpoint sanity checks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 998912346c0da53a6dbb71fab3a138586b596b30 upstream.
Make sure to check that we have at least one endpoint before accessing the endpoint array to avoid dereferencing a NULL-pointer on stream start.
Note that these sanity checks are not redundant as the driver is mixing looking up altsettings by index and by number, which need not coincide.
--- drivers/media/usb/gspca/ov519.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/media/usb/gspca/ov519.c +10 -0
@@ -3497,6 +3497,11 @@ static void ov511_mode_init_regs(structreturn ; } +if (alt->desc.bNumEndpoints <1 ) { + sd->gspca_dev.usb_err = -ENODEV ; +return ; + } + packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize);reg_w (sd, R51x_FIFO_PSIZE, packet_size >>5 );
@@ -3622,6 +3627,11 @@ static void ov518_mode_init_regs(structreturn ; } +if (alt->desc.bNumEndpoints <1 ) { + sd->gspca_dev.usb_err = -ENODEV ; +return ; + } + packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize);ov518_reg_w32 (sd, R51x_FIFO_PSIZE, packet_size & ~7 ,2 );
PATCH 228/245 media: stv06xx: add missing descriptor sanity checks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 485b06aadb933190f4bc44e006076bc27a23f205 upstream.
Make sure to check that we have two alternate settings and at least one endpoint before accessing the second altsetting structure and dereferencing the endpoint arrays.
This specifically avoids dereferencing NULL-pointers or corrupting memory when a device does not have the expected descriptors.
Note that the sanity checks in stv06xx_start() and pb0100_start() are not redundant as the driver is mixing looking up altsettings by index and by number, which may not coincide.
--- drivers/media/usb/gspca/stv06xx/stv06xx.c | 19 ++++++++++++++++++- .../media/usb/gspca/stv06xx/stv06xx_pb0100.c | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/stv06xx/stv06xx.c +18 -1
@@ -293,6 +293,9 @@ static int stv06xx_start(struct gspca_dereturn -EIO ; } +if (alt->desc.bNumEndpoints <1 ) +return -ENODEV ; + packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize); err =stv06xx_write_bridge (sd,STV_ISO_SIZE_L , packet_size);if (err <0 )
@@ -317,11 +320,21 @@ out:static int stv06xx_isoc_init (struct gspca_dev *gspca_dev) { +struct usb_interface_cache *intfc;struct usb_host_interface *alt;struct sd *sd = (struct sd *) gspca_dev; + intfc = gspca_dev->dev->actconfig->intf_cache[0 ]; + +if (intfc->num_altsetting <2 ) +return -ENODEV ; + + alt = &intfc->altsetting[1 ]; + +if (alt->desc.bNumEndpoints <1 ) +return -ENODEV ; +/* Start isoc bandwidth "negotiation" at max isoc bandwidth */ - alt = &gspca_dev->dev->actconfig->intf_cache[0 ]->altsetting[1 ]; alt->endpoint[0 ].desc.wMaxPacketSize =cpu_to_le16 (sd->sensor->max_packet_size[gspca_dev->curr_mode]);
@@ -334,6 +347,10 @@ static int stv06xx_isoc_nego(struct gspcstruct usb_host_interface *alt;struct sd *sd = (struct sd *) gspca_dev; +/* +* Existence of altsetting and endpoint was verified in +* stv06xx_isoc_init() +*/ alt = &gspca_dev->dev->actconfig->intf_cache[0 ]->altsetting[1 ]; packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize); min_packet_size = sd->sensor->min_packet_size[gspca_dev->curr_mode];
drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c +4 -0
@@ -198,6 +198,10 @@ static int pb0100_start(struct sd *sd) alt =usb_altnum_to_altsetting (intf, sd->gspca_dev.alt);if (!alt)return -ENODEV ; + +if (alt->desc.bNumEndpoints <1 ) +return -ENODEV ; + packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize);/* If we don't have enough bandwidth use a lower framerate */
PATCH 229/245 media: xirlink_cit: add missing descriptor sanity checks
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit a246b4d547708f33ff4d4b9a7a5dbac741dc89d8 upstream.
Make sure to check that we have two alternate settings and at least one endpoint before accessing the second altsetting structure and dereferencing the endpoint arrays.
This specifically avoids dereferencing NULL-pointers or corrupting memory when a device does not have the expected descriptors.
Note that the sanity check in cit_get_packet_size() is not redundant as the driver is mixing looking up altsettings by index and by number, which may not coincide.
--- drivers/media/usb/gspca/xirlink_cit.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/xirlink_cit.c +17 -1
@@ -1455,6 +1455,9 @@ static int cit_get_packet_size(struct gsreturn -EIO ; } +if (alt->desc.bNumEndpoints <1 ) +return -ENODEV ; +return le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize); }
@@ -2632,6 +2635,7 @@ static int sd_start(struct gspca_dev *gsstatic int sd_isoc_init (struct gspca_dev *gspca_dev) { +struct usb_interface_cache *intfc;struct usb_host_interface *alt;int max_packet_size;
@@ -2647,8 +2651,17 @@ static int sd_isoc_init(struct gspca_devbreak ; } + intfc = gspca_dev->dev->actconfig->intf_cache[0 ]; + +if (intfc->num_altsetting <2 ) +return -ENODEV ; + + alt = &intfc->altsetting[1 ]; + +if (alt->desc.bNumEndpoints <1 ) +return -ENODEV ; +/* Start isoc bandwidth "negotiation" at max isoc bandwidth */ - alt = &gspca_dev->dev->actconfig->intf_cache[0 ]->altsetting[1 ]; alt->endpoint[0 ].desc.wMaxPacketSize =cpu_to_le16 (max_packet_size);return 0 ;
@@ -2671,6 +2684,9 @@ static int sd_isoc_nego(struct gspca_devbreak ; } +/* +* Existence of altsetting and endpoint was verified in sd_isoc_init() +*/ alt = &gspca_dev->dev->actconfig->intf_cache[0 ]->altsetting[1 ]; packet_size =le16_to_cpu (alt->endpoint[0 ].desc.wMaxPacketSize);if (packet_size <= min_packet_size)
PATCH 230/245 ptp: do not explicitly set drvdata in ptp_clock_register()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 882f312dc0751c973db26478f07f082c584d16aa upstream.
We do not need explicitly call dev_set_drvdata(), as it is done for us by device_create().
--- drivers/ptp/ptp_clock.c | 2 -- 1 file changed, 2 deletions(-)
drivers/ptp/ptp_clock.c +0 -2
@@ -216,8 +216,6 @@ struct ptp_clock *ptp_clock_register(strif (IS_ERR (ptp->dev)) goto no_device; -dev_set_drvdata (ptp->dev, ptp); - err =ptp_populate_sysfs (ptp);if (err) goto no_sysfs;
PATCH 231/245 ptp: use is_visible method to hide unused attributes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit af59e717d5ff9c8dbf9bcc581c0dfb3b2a9c9030 upstream.
Instead of creating selected attributes after the device is created (and after userspace potentially seen uevent), lets use attribute group is_visible() method to control which attributes are shown. This will allow us to create all attributes (except "pins" group, which will be taken care of later) before userspace gets notified about new ptp class device.
--- drivers/ptp/ptp_sysfs.c | 125 ++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 70 deletions(-)
drivers/ptp/ptp_sysfs.c +55 -70
@@ -46,27 +46,6 @@ PTP_SHOW_INT(n_periodic_outputs, n_per_oPTP_SHOW_INT (n_programmable_pins, n_pins);PTP_SHOW_INT (pps_available, pps); -static struct attribute *ptp_attrs[] = { - &dev_attr_clock_name.attr, - &dev_attr_max_adjustment.attr, - &dev_attr_n_alarms.attr, - &dev_attr_n_external_timestamps.attr, - &dev_attr_n_periodic_outputs.attr, - &dev_attr_n_programmable_pins.attr, - &dev_attr_pps_available.attr, -NULL , -}; - -static const struct attribute_group ptp_group = { - .attrs = ptp_attrs, -}; - -const struct attribute_group *ptp_groups[] = { - &ptp_group, -NULL , -}; - -static ssize_t extts_enable_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -91,6 +70,7 @@ static ssize_t extts_enable_store(struct out:return err; } +static DEVICE_ATTR(extts_enable, 0220, NULL, extts_enable_store);static ssize_t extts_fifo_show (struct device *dev,struct device_attribute *attr,char *page)
@@ -124,6 +104,7 @@ out:mutex_unlock (&ptp->tsevq_mux);return cnt; } +static DEVICE_ATTR(fifo, 0444, extts_fifo_show, NULL); static ssize_t period_store(struct device *dev, struct device_attribute *attr,
@@ -151,6 +132,7 @@ static ssize_t period_store(struct devic out:return err; } +static DEVICE_ATTR(period, 0220, NULL, period_store); static ssize_t pps_enable_store(struct device *dev, struct device_attribute *attr,
@@ -177,6 +159,57 @@ static ssize_t pps_enable_store(struct d out:return err; } +static DEVICE_ATTR(pps_enable, 0220, NULL, pps_enable_store); + +static struct attribute *ptp_attrs[] = { + &dev_attr_clock_name.attr, + + &dev_attr_max_adjustment.attr, + &dev_attr_n_alarms.attr, + &dev_attr_n_external_timestamps.attr, + &dev_attr_n_periodic_outputs.attr, + &dev_attr_n_programmable_pins.attr, + &dev_attr_pps_available.attr, + + &dev_attr_extts_enable.attr, + &dev_attr_fifo.attr, + &dev_attr_period.attr, + &dev_attr_pps_enable.attr, +NULL +}; + +static umode_t ptp_is_attribute_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct device *dev =kobj_to_dev (kobj); +struct ptp_clock *ptp =dev_get_drvdata (dev); +struct ptp_clock_info *info = ptp->info; +umode_t mode = attr->mode; + +if (attr == &dev_attr_extts_enable.attr || + attr == &dev_attr_fifo.attr) { +if (!info->n_ext_ts) + mode =0 ; + }else if (attr == &dev_attr_period.attr) { +if (!info->n_per_out) + mode =0 ; + }else if (attr == &dev_attr_pps_enable.attr) { +if (!info->pps) + mode =0 ; + } + +return mode; +} + +static const struct attribute_group ptp_group = { + .is_visible = ptp_is_attribute_visible, + .attrs = ptp_attrs, +}; + +const struct attribute_group *ptp_groups[] = { + &ptp_group, +NULL +};static int ptp_pin_name2index (struct ptp_clock *ptp,const char *name) {
@@ -235,26 +268,11 @@ static ssize_t ptp_pin_store(struct devireturn count; } -static DEVICE_ATTR(extts_enable, 0220, NULL, extts_enable_store); -static DEVICE_ATTR(fifo, 0444, extts_fifo_show, NULL); -static DEVICE_ATTR(period, 0220, NULL, period_store); -static DEVICE_ATTR(pps_enable, 0220, NULL, pps_enable_store); -int ptp_cleanup_sysfs (struct ptp_clock *ptp) {struct device *dev = ptp->dev;struct ptp_clock_info *info = ptp->info; -if (info->n_ext_ts) { -device_remove_file (dev, &dev_attr_extts_enable); -device_remove_file (dev, &dev_attr_fifo); - } -if (info->n_per_out) -device_remove_file (dev, &dev_attr_period); - -if (info->pps) -device_remove_file (dev, &dev_attr_pps_enable); -if (info->n_pins) {sysfs_remove_group (&dev->kobj, &ptp->pin_attr_group);kfree (ptp->pin_attr);
@@ -307,46 +325,13 @@ no_dev_attr:int ptp_populate_sysfs (struct ptp_clock *ptp) { -struct device *dev = ptp->dev;struct ptp_clock_info *info = ptp->info;int err; -if (info->n_ext_ts) { - err =device_create_file (dev, &dev_attr_extts_enable); -if (err) - goto out1; - err =device_create_file (dev, &dev_attr_fifo); -if (err) - goto out2; - } -if (info->n_per_out) { - err =device_create_file (dev, &dev_attr_period); -if (err) - goto out3; - } -if (info->pps) { - err =device_create_file (dev, &dev_attr_pps_enable); -if (err) - goto out4; - }if (info->n_pins) { err =ptp_populate_pins (ptp);if (err) - goto out5; +return err; }return 0 ; -out5: -if (info->pps) -device_remove_file (dev, &dev_attr_pps_enable); -out4: -if (info->n_per_out) -device_remove_file (dev, &dev_attr_period); -out3: -if (info->n_ext_ts) -device_remove_file (dev, &dev_attr_fifo); -out2: -if (info->n_ext_ts) -device_remove_file (dev, &dev_attr_extts_enable); -out1: -return err; }
PATCH 232/245 ptp: create "pins" together with the rest of attributes
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 85a66e55019583da1e0f18706b7a8281c9f6de5b upstream.
Let's switch to using device_create_with_groups(), which will allow us to create "pins" attribute group together with the rest of ptp device attributes, and before userspace gets notified about ptp device creation.
--- drivers/ptp/ptp_clock.c | 20 +++++++++++--------- drivers/ptp/ptp_private.h | 7 ++++--- drivers/ptp/ptp_sysfs.c | 39 +++++++++------------------------------ 3 files changed, 24 insertions(+), 42 deletions(-)
drivers/ptp/ptp_clock.c +11 -9
@@ -210,16 +210,17 @@ struct ptp_clock *ptp_clock_register(strmutex_init (&ptp->pincfg_mux);init_waitqueue_head (&ptp->tsev_wq); + err =ptp_populate_pin_groups (ptp); +if (err) + goto no_pin_groups; +/* Create a new device in our class. */ - ptp->dev =device_create (ptp_class, parent, ptp->devid, ptp, -"ptp%d" , ptp->index); + ptp->dev =device_create_with_groups (ptp_class, parent, ptp->devid, + ptp, ptp->pin_attr_groups, +"ptp%d" , ptp->index);if (IS_ERR (ptp->dev)) goto no_device; - err =ptp_populate_sysfs (ptp); -if (err) - goto no_sysfs; -/* Register a new PPS source. */ if (info->pps) {struct pps_source_info pps;
@@ -247,10 +248,10 @@ no_clock:if (ptp->pps_source)pps_unregister_source (ptp->pps_source); no_pps: -ptp_cleanup_sysfs (ptp); -no_sysfs:device_destroy (ptp_class, ptp->devid); no_device: +ptp_cleanup_pin_groups (ptp); +no_pin_groups:mutex_destroy (&ptp->tsevq_mux);mutex_destroy (&ptp->pincfg_mux); no_slot:
@@ -268,8 +269,9 @@ int ptp_clock_unregister(struct ptp_cloc/* Release the clock's resources. */ if (ptp->pps_source)pps_unregister_source (ptp->pps_source); -ptp_cleanup_sysfs (ptp); +device_destroy (ptp_class, ptp->devid); +ptp_cleanup_pin_groups (ptp);posix_clock_unregister (&ptp->clock);return 0 ;
drivers/ptp/ptp_private.h +4 -3
@@ -54,6 +54,8 @@ struct ptp_clock {struct device_attribute *pin_dev_attr;struct attribute **pin_attr;struct attribute_group pin_attr_group; +/* 1st entry is a pointer to the real group, 2nd is NULL terminator */ +const struct attribute_group *pin_attr_groups[2 ]; };/*
@@ -94,8 +96,7 @@ uint ptp_poll(struct posix_clock *pc,extern const struct attribute_group *ptp_groups[]; -int ptp_cleanup_sysfs (struct ptp_clock *ptp); - -int ptp_populate_sysfs (struct ptp_clock *ptp); +int ptp_populate_pin_groups (struct ptp_clock *ptp); +void ptp_cleanup_pin_groups (struct ptp_clock *ptp);#endif
drivers/ptp/ptp_sysfs.c +9 -30
@@ -268,25 +268,14 @@ static ssize_t ptp_pin_store(struct devireturn count; } -int ptp_cleanup_sysfs (struct ptp_clock *ptp) +int ptp_populate_pin_groups (struct ptp_clock *ptp) { -struct device *dev = ptp->dev; -struct ptp_clock_info *info = ptp->info; - -if (info->n_pins) { -sysfs_remove_group (&dev->kobj, &ptp->pin_attr_group); -kfree (ptp->pin_attr); -kfree (ptp->pin_dev_attr); - } -return 0 ; -} - -static int ptp_populate_pins (struct ptp_clock *ptp) -{ -struct device *dev = ptp->dev;struct ptp_clock_info *info = ptp->info;int err = -ENOMEM , i, n_pins = info->n_pins; +if (!n_pins) +return 0 ; + ptp->pin_dev_attr =kzalloc (n_pins *sizeof (*ptp->pin_dev_attr),GFP_KERNEL );if (!ptp->pin_dev_attr)
@@ -310,28 +299,18 @@ static int ptp_populate_pins(struct ptp_ ptp->pin_attr_group.name ="pins" ; ptp->pin_attr_group.attrs = ptp->pin_attr; - err =sysfs_create_group (&dev->kobj, &ptp->pin_attr_group); -if (err) - goto no_group; + ptp->pin_attr_groups[0 ] = &ptp->pin_attr_group; +return 0 ; -no_group: -kfree (ptp->pin_attr); no_pin_attr:kfree (ptp->pin_dev_attr); no_dev_attr:return err; } -int ptp_populate_sysfs (struct ptp_clock *ptp) +void ptp_cleanup_pin_groups (struct ptp_clock *ptp) { -struct ptp_clock_info *info = ptp->info; -int err; - -if (info->n_pins) { - err =ptp_populate_pins (ptp); -if (err) -return err; - } -return 0 ; +kfree (ptp->pin_attr); +kfree (ptp->pin_dev_attr); }
PATCH 233/245 chardev: add helper function to register char devs with a struct device
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Logan Gunthorpe <[email protected]>
commit 233ed09d7fdacf592ee91e6c97ce5f4364fbe7c0 upstream.
Credit for this patch goes is shared with Dan Williams [1]. I've taken things one step further to make the helper function more useful and clean up calling code.
There's a common pattern in the kernel whereby a struct cdev is placed in a structure along side a struct device which manages the life-cycle of both. In the naive approach, the reference counting is broken and the struct device can free everything before the chardev code is entirely released.
Many developers have solved this problem by linking the internal kobjs in this fashion:
cdev.kobj.parent = &parent_dev.kobj;
The cdev code explicitly gets and puts a reference to it's kobj parent. So this seems like it was intended to be used this way. Dmitrty Torokhov first put this in place in 2012 with this commit:
2f0157f char_dev: pin parent kobject
and the first instance of the fix was then done in the input subsystem in the following commit:
4a215aa Input: fix use-after-free introduced with dynamic minor changes
Subsequently over the years, however, this issue seems to have tripped up multiple developers independently. For example, see these commits:
0d5b7da iio: Prevent race between IIO chardev opening and IIO device (by Lars-Peter Clausen in 2013)
ba0ef85 tpm: Fix initialization of the cdev
(by Jason Gunthorpe in 2015)
5b28dde [media] media: fix use-after-free in cdev_put() when app exits after driver unbind
(by Shauh Khan in 2016)
This technique is similarly done in at least 15 places within the kernel and probably should have been done so in another, at least, 5 places. The kobj line also looks very suspect in that one would not expect drivers to have to mess with kobject internals in this way. Even highly experienced kernel developers can be surprised by this code, as seen in [2].
To help alleviate this situation, and hopefully prevent future wasted effort on this problem, this patch introduces a helper function to register a char device along with its parent struct device. This creates a more regular API for tying a char device to its parent without the developer having to set members in the underlying kobject.
This patch introduce cdev_device_add and cdev_device_del which replaces a common pattern including setting the kobj parent, calling cdev_add and then calling device_add. It also introduces cdev_set_parent for the few cases that set the kobject parent without using device_add.
[1] https://lkml.org/lkml/2017/2/13/700
[2] https://lkml.org/lkml/2017/2/10/370
--- fs/char_dev.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/cdev.h | 5 +++ 2 files changed, 91 insertions(+)
fs/char_dev.c +86 -0
@@ -488,6 +488,85 @@ int cdev_add(struct cdev *p, dev_t dev,return 0 ; } +/** +* cdev_set_parent() - set the parent kobject for a char device +* @p: the cdev structure +* @kobj: the kobject to take a reference to +* +* cdev_set_parent() sets a parent kobject which will be referenced +* appropriately so the parent is not freed before the cdev. This +* should be called before cdev_add. +*/ +void cdev_set_parent (struct cdev *p,struct kobject *kobj) +{ +WARN_ON (!kobj->state_initialized); + p->kobj.parent = kobj; +} + +/** +* cdev_device_add() - add a char device and it's corresponding +* struct device, linkink +* @dev: the device structure +* @cdev: the cdev structure +* +* cdev_device_add() adds the char device represented by @cdev to the system, +* just as cdev_add does. It then adds @dev to the system using device_add +* The dev_t for the char device will be taken from the struct device which +* needs to be initialized first. This helper function correctly takes a +* reference to the parent device so the parent will not get released until +* all references to the cdev are released. +* +* This helper uses dev->devt for the device number. If it is not set +* it will not add the cdev and it will be equivalent to device_add. +* +* This function should be used whenever the struct cdev and the +* struct device are members of the same structure whose lifetime is +* managed by the struct device. +* +* NOTE: Callers must assume that userspace was able to open the cdev and +* can call cdev fops callbacks at any time, even if this function fails. +*/ +int cdev_device_add (struct cdev *cdev,struct device *dev) +{ +int rc =0 ; + +if (dev->devt) { +cdev_set_parent (cdev, &dev->kobj); + + rc =cdev_add (cdev, dev->devt,1 ); +if (rc) +return rc; + } + + rc =device_add (dev); +if (rc) +cdev_del (cdev); + +return rc; +} + +/** +* cdev_device_del() - inverse of cdev_device_add +* @dev: the device structure +* @cdev: the cdev structure +* +* cdev_device_del() is a helper function to call cdev_del and device_del. +* It should be used whenever cdev_device_add is used. +* +* If dev->devt is not set it will not remove the cdev and will be equivalent +* to device_del. +* +* NOTE: This guarantees that associated sysfs callbacks are not running +* or runnable, however any cdevs already open will remain and their fops +* will still be callable even after this function returns. +*/ +void cdev_device_del (struct cdev *cdev,struct device *dev) +{ +device_del (dev); +if (dev->devt) +cdev_del (cdev); +} +static void cdev_unmap (dev_t dev,unsigned count) {kobj_unmap (cdev_map, dev, count);
@@ -499,6 +578,10 @@ static void cdev_unmap(dev_t dev, unsign* * cdev_del() removes @p from the system, possibly freeing the structure * itself. +* +* NOTE: This guarantees that cdev device will no longer be able to be +* opened, however any cdevs already open will remain and their fops will +* still be callable even after cdev_del returns. */ void cdev_del (struct cdev *p) {
@@ -589,6 +672,9 @@ EXPORT_SYMBOL(cdev_init);EXPORT_SYMBOL (cdev_alloc);EXPORT_SYMBOL (cdev_del);EXPORT_SYMBOL (cdev_add); +EXPORT_SYMBOL (cdev_set_parent); +EXPORT_SYMBOL (cdev_device_add); +EXPORT_SYMBOL (cdev_device_del);EXPORT_SYMBOL (__register_chrdev);EXPORT_SYMBOL (__unregister_chrdev);EXPORT_SYMBOL (directly_mappable_cdev_bdi);
include/linux/cdev.h +5 -0
@@ -4,6 +4,7 @@#include <linux/kobject.h> #include <linux/kdev_t.h> #include <linux/list.h> +#include <linux/device.h> struct file_operations ;struct inode ;
@@ -26,6 +27,10 @@ void cdev_put(struct cdev *p);int cdev_add (struct cdev *,dev_t ,unsigned ); +void cdev_set_parent (struct cdev *p,struct kobject *kobj); +int cdev_device_add (struct cdev *cdev,struct device *dev); +void cdev_device_del (struct cdev *cdev,struct device *dev); +void cdev_del (struct cdev *);void cd_forget (struct inode *);
PATCH 234/245 ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: YueHaibing <[email protected]>
commit aea0a897af9e44c258e8ab9296fad417f1bc063a upstream.
Fix smatch warning:
drivers/ptp/ptp_clock.c:298 ptp_clock_register() warn:
passing zero to 'ERR_PTR'
'err' should be set while device_create_with_groups and pps_register_source fails
--- drivers/ptp/ptp_clock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/ptp/ptp_clock.c +4 -1
@@ -218,8 +218,10 @@ struct ptp_clock *ptp_clock_register(str ptp->dev =device_create_with_groups (ptp_class, parent, ptp->devid, ptp, ptp->pin_attr_groups,"ptp%d" , ptp->index); -if (IS_ERR (ptp->dev)) +if (IS_ERR (ptp->dev)) { + err =PTR_ERR (ptp->dev); goto no_device; + }/* Register a new PPS source. */ if (info->pps) {
@@ -230,6 +232,7 @@ struct ptp_clock *ptp_clock_register(str pps.owner = info->owner; ptp->pps_source =pps_register_source (&pps,PTP_PPS_DEFAULTS );if (!ptp->pps_source) { + err = -EINVAL ;pr_err ("failed to register pps source\n" ); goto no_pps; }
PATCH 235/245 ptp: fix the race between the release of ptp_clock and cdev
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Vladis Dronov <[email protected]>
commit a33121e5487b424339636b25c35d3a180eaa5f5e upstream.
In a case when a ptp chardev (like /dev/ptp0) is open but an underlying device is removed, closing this file leads to a race. This reproduces easily in a kvm virtual machine:
ts# cat openptp0.c
int main() { ... fp = fopen("/dev/ptp0", "r"); ... sleep(10); } ts# uname -r
5.5.0-rc3-46cf053e
ts# cat /proc/cmdline
... slub_debug=FZP
ts# modprobe ptp_kvm
ts# ./openptp0 &
[1] 670
opened /dev/ptp0, sleeping 10s...
ts# rmmod ptp_kvm
ts# ls /dev/ptp*
ls: cannot access '/dev/ptp*': No such file or directory ts# ...woken up
[ 48.010809] general protection fault: 0000 [#1] SMP [ 48.012502] CPU: 6 PID: 658 Comm: openptp0 Not tainted 5.5.0-rc3-46cf053e #25 [ 48.014624] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), ... [ 48.016270] RIP: 0010:module_put.part.0+0x7/0x80 [ 48.017939] RSP: 0018:ffffb3850073be00 EFLAGS: 00010202 [ 48.018339] RAX: 000000006b6b6b6b RBX: 6b6b6b6b6b6b6b6b RCX: ffff89a476c00ad0 [ 48.018936] RDX: fffff65a08d3ea08 RSI: 0000000000000247 RDI: 6b6b6b6b6b6b6b6b [ 48.019470] ... ^^^ a slub poison [ 48.023854] Call Trace: [ 48.024050] __fput+0x21f/0x240 [ 48.024288] task_work_run+0x79/0x90 [ 48.024555] do_exit+0x2af/0xab0 [ 48.024799] ? vfs_write+0x16a/0x190 [ 48.025082] do_group_exit+0x35/0x90 [ 48.025387] __x64_sys_exit_group+0xf/0x10 [ 48.025737] do_syscall_64+0x3d/0x130 [ 48.026056] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 48.026479] RIP: 0033:0x7f53b12082f6 [ 48.026792] ... [ 48.030945] Modules linked in: ptp i6300esb watchdog [last unloaded: ptp_kvm] [ 48.045001] Fixing recursive fault but reboot is needed!
This happens in:
static void __fput(struct file *file)
{ ...
if (file->f_op->release)
file->f_op->release(inode, file); <<< cdev is kfree'd here
if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
!(mode & FMODE_PATH))) {
cdev_put(inode->i_cdev); <<< cdev fields are accessed hereNamely:
__fput()
posix_clock_release()
kref_put(&clk->kref, delete_clock) <<< the last reference
delete_clock()
delete_ptp_clock()
kfree(ptp) <<< cdev is embedded in ptp
cdev_put
module_put(p->owner) <<< *p is kfree'd, bang!
Here cdev is embedded in posix_clock which is embedded in ptp_clock. The race happens because ptp_clock's lifetime is controlled by two
refcounts: kref and cdev.kobj in posix_clock. This is wrong.
Make ptp_clock's sysfs device a parent of cdev with cdev_device_add() created especially for such cases. This way the parent device with its ptp_clock is not released until all references to the cdev are released. This adds a requirement that an initialized but not exposed struct device should be provided to posix_clock_register() by a caller instead of a simple dev_t.
This approach was adopted from the commit 72139dfa2464 ("watchdog: Fix the race between the release of watchdog_core_data and cdev"). See details of the implementation in the commit 233ed09d7fda ("chardev: add helper function to register char devs with a struct device").
--- drivers/ptp/ptp_clock.c | 31 ++++++++++++++----------------- drivers/ptp/ptp_private.h | 2 +- include/linux/posix-clock.h | 19 +++++++++++-------- kernel/time/posix-clock.c | 31 +++++++++++++------------------ 4 files changed, 39 insertions(+), 44 deletions(-)
drivers/ptp/ptp_clock.c +14 -17
@@ -167,9 +167,9 @@ static struct posix_clock_operations ptp .read = ptp_read, }; -static void delete_ptp_clock (struct posix_clock *pc) +static void ptp_clock_release (struct device *dev) { - struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); + struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev);mutex_destroy (&ptp->tsevq_mux);mutex_destroy (&ptp->pincfg_mux);
@@ -201,7 +201,6 @@ struct ptp_clock *ptp_clock_register(str } ptp->clock.ops = ptp_clock_ops; - ptp->clock.release = delete_ptp_clock; ptp->info = info; ptp->devid =MKDEV (major, index); ptp->index = index;
@@ -214,15 +213,6 @@ struct ptp_clock *ptp_clock_register(strif (err) goto no_pin_groups; -/* Create a new device in our class. */ - ptp->dev =device_create_with_groups (ptp_class, parent, ptp->devid, - ptp, ptp->pin_attr_groups, -"ptp%d" , ptp->index); -if (IS_ERR (ptp->dev)) { - err =PTR_ERR (ptp->dev); - goto no_device; - } -/* Register a new PPS source. */ if (info->pps) {struct pps_source_info pps;
@@ -238,8 +228,18 @@ struct ptp_clock *ptp_clock_register(str } } -/* Create a posix clock. */ - err =posix_clock_register (&ptp->clock, ptp->devid); +/* Initialize a new device of our class in our clock structure. */ +device_initialize (&ptp->dev); + ptp->dev.devt = ptp->devid; + ptp->dev.class = ptp_class; + ptp->dev.parent = parent; + ptp->dev.groups = ptp->pin_attr_groups; + ptp->dev.release = ptp_clock_release; +dev_set_drvdata (&ptp->dev, ptp); +dev_set_name (&ptp->dev,"ptp%d" , ptp->index); + +/* Create a posix clock and link it to the device. */ + err =posix_clock_register (&ptp->clock, &ptp->dev);if (err) {pr_err ("failed to create posix clock\n" ); goto no_clock;
@@ -251,8 +251,6 @@ no_clock:if (ptp->pps_source)pps_unregister_source (ptp->pps_source); no_pps: -device_destroy (ptp_class, ptp->devid); -no_device:ptp_cleanup_pin_groups (ptp); no_pin_groups:mutex_destroy (&ptp->tsevq_mux);
@@ -273,7 +271,6 @@ int ptp_clock_unregister(struct ptp_clocif (ptp->pps_source)pps_unregister_source (ptp->pps_source); -device_destroy (ptp_class, ptp->devid);ptp_cleanup_pin_groups (ptp);posix_clock_unregister (&ptp->clock);
drivers/ptp/ptp_private.h +1 -1
@@ -40,7 +40,7 @@ struct timestamp_event_queue {struct ptp_clock {struct posix_clock clock; -struct device *dev; +struct device dev;struct ptp_clock_info *info;dev_t devid;int index;/* index into clocks.map */
include/linux/posix-clock.h +11 -8
@@ -104,29 +104,32 @@ struct posix_clock_operations {* * @ops: Functional interface to the clock * @cdev: Character device instance for this clock -* @kref: Reference count. +* @dev: Pointer to the clock's device. * @rwsem: Protects the 'zombie' field from concurrent access. * @zombie: If 'zombie' is true, then the hardware has disappeared. -* @release: A function to free the structure when the reference count reaches -* zero. May be NULL if structure is statically allocated. * * Drivers should embed their struct posix_clock within a private * structure, obtaining a reference to it during callbacks using * container_of(). +* +* Drivers should supply an initialized but not exposed struct device +* to posix_clock_register(). It is used to manage lifetime of the +* driver's private structure. It's 'release' field should be set to +* a release function for this private structure. */ struct posix_clock {struct posix_clock_operations ops;struct cdev cdev; -struct kref kref; +struct device *dev;struct rw_semaphore rwsem;bool zombie; -void (*release)(struct posix_clock *clk); };/** * posix_clock_register() - register a new clock -* @clk: Pointer to the clock. Caller must provide 'ops' and 'release' -* @devid: Allocated device id +* @clk: Pointer to the clock. Caller must provide 'ops' field +* @dev: Pointer to the initialized device. Caller must provide +* 'release' field * * A clock driver calls this function to register itself with the * clock device subsystem. If 'clk' points to dynamically allocated
@@ -135,7 +138,7 @@ struct posix_clock {* * Returns zero on success, non-zero otherwise. */ -int posix_clock_register (struct posix_clock *clk,dev_t devid); +int posix_clock_register (struct posix_clock *clk,struct device *dev);/** * posix_clock_unregister() - unregister a clock
kernel/time/posix-clock.c +13 -18
@@ -25,8 +25,6 @@#include <linux/syscalls.h> #include <linux/uaccess.h> -static void delete_clock (struct kref *kref); -/* * Returns NULL if the posix_clock instance attached to 'fp' is old and stale. */
@@ -168,7 +166,7 @@ static int posix_clock_open(struct inode err =0 ;if (!err) { -kref_get (&clk->kref); +get_device (clk->dev); fp->private_data = clk; } out:
@@ -184,7 +182,7 @@ static int posix_clock_release(struct inif (clk->ops.release) err = clk->ops.release (clk); -kref_put (&clk->kref, delete_clock); +put_device (clk->dev); fp->private_data =NULL ;
@@ -206,38 +204,35 @@ static const struct file_operations posi#endif }; -int posix_clock_register (struct posix_clock *clk,dev_t devid) +int posix_clock_register (struct posix_clock *clk,struct device *dev) {int err; -kref_init (&clk->kref);init_rwsem (&clk->rwsem);cdev_init (&clk->cdev, &posix_clock_file_operations); + err =cdev_device_add (&clk->cdev, dev); +if (err) { +pr_err ("%s unable to add device %d:%d\n" , +dev_name (dev),MAJOR (dev->devt),MINOR (dev->devt)); +return err; + } clk->cdev.owner = clk->ops.owner; - err =cdev_add (&clk->cdev, devid,1 ); + clk->dev = dev; -return err; +return 0 ; }EXPORT_SYMBOL_GPL (posix_clock_register); -static void delete_clock (struct kref *kref) -{ - struct posix_clock *clk = container_of(kref, struct posix_clock, kref); - -if (clk->release) - clk->release (clk); -} -void posix_clock_unregister (struct posix_clock *clk) { -cdev_del (&clk->cdev); +cdev_device_del (&clk->cdev, clk->dev);down_write (&clk->rwsem); clk->zombie = true;up_write (&clk->rwsem); -kref_put (&clk->kref, delete_clock); +put_device (clk->dev); }EXPORT_SYMBOL_GPL (posix_clock_unregister);
PATCH 236/245 ptp: free ptp device pin descriptors properly
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Vladis Dronov <[email protected]>
commit 75718584cb3c64e6269109d4d54f888ac5a5fd15 upstream.
There is a bug in ptp_clock_unregister(), where ptp_cleanup_pin_groups() first frees ptp->pin_{,dev_}attr, but then posix_clock_unregister() needs them to destroy a related sysfs device.
These functions can not be just swapped, as posix_clock_unregister() frees ptp which is needed in the ptp_cleanup_pin_groups(). Fix this by calling ptp_cleanup_pin_groups() in ptp_clock_release(), right before ptp is freed.
This makes this patch fix an UAF bug in a patch which fixes an UAF bug.
--- drivers/ptp/ptp_clock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ptp/ptp_clock.c +2 -2
@@ -171,6 +171,7 @@ static void ptp_clock_release(struct dev { struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); +ptp_cleanup_pin_groups (ptp);mutex_destroy (&ptp->tsevq_mux);mutex_destroy (&ptp->pincfg_mux);ida_simple_remove (&ptp_clocks_map, ptp->index);
@@ -271,9 +272,8 @@ int ptp_clock_unregister(struct ptp_clocif (ptp->pps_source)pps_unregister_source (ptp->pps_source); -ptp_cleanup_pin_groups (ptp); -posix_clock_unregister (&ptp->clock); +return 0 ; }EXPORT_SYMBOL (ptp_clock_unregister);
PATCH 237/245 media-devnode: just return 0 instead of using a var
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 8b37c6455fc8f43e0e95db2847284e618db6a4f8 upstream.
Instead of allocating a var to store 0 and just return it, change the code to return 0 directly.
--- drivers/media/media-devnode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/media-devnode.c +1 -2
@@ -192,7 +192,6 @@ static int media_open(struct inode *inodstatic int media_release (struct inode *inode,struct file *filp) {struct media_devnode *mdev =media_devnode_data (filp); -int ret =0 ;if (mdev->fops->release) mdev->fops->release (filp);
@@ -201,7 +200,7 @@ static int media_release(struct inode *ireturn value is ignored. */ put_device (&mdev->dev); filp->private_data =NULL ; -return ret; +return 0 ; }static const struct file_operations media_devnode_fops = {
PATCH 238/245 media: Fix media_open() to clear filp->private_data in error leg
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit d40ec6fdb0b03b7be4c7923a3da0e46bf943740a upstream.
Fix media_open() to clear filp->private_data when file open fails.
--- drivers/media/media-devnode.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/media-devnode.c +1 -0
@@ -181,6 +181,7 @@ static int media_open(struct inode *inod ret = mdev->fops->open (filp);if (ret) {put_device (&mdev->dev); + filp->private_data =NULL ;return ret; } }
PATCH 239/245 drivers/media/media-devnode: clear private_data before put_device()
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
commit bf244f665d76d20312c80524689b32a752888838 upstream.
Callbacks invoked from put_device() may free the struct media_devnode pointer, so any cleanup needs to be done before put_device().
--- drivers/media/media-devnode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/media-devnode.c +2 -1
@@ -197,10 +197,11 @@ static int media_release(struct inode *iif (mdev->fops->release) mdev->fops->release (filp); + filp->private_data =NULL ; +/* decrease the refcount unconditionally since the release() return value is ignored. */ put_device (&mdev->dev); - filp->private_data =NULL ;return 0 ; }
PATCH 240/245 media-devnode: add missing mutex lock in error handler
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
commit 88336e174645948da269e1812f138f727cd2896b upstream.
We should protect the device unregister patch too, at the error condition.
--- drivers/media/media-devnode.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/media-devnode.c +3 -0
@@ -282,8 +282,11 @@ int __must_check media_devnode_register(return 0 ; error: +mutex_lock (&media_devnode_lock);cdev_del (&mdev->cdev);clear_bit (mdev->minor, media_devnode_nums); +mutex_unlock (&media_devnode_lock); +return ret; }
PATCH 241/245 media-devnode: fix namespace mess
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 163f1e93e995048b894c5fc86a6034d16beed740 upstream.
Along all media controller code, "mdev" is used to represent a pointer to struct media_device, and "devnode" for a pointer to struct media_devnode.
However, inside media-devnode.[ch], "mdev" is used to represent a pointer to struct media_devnode.
This is very confusing and may lead to development errors.
So, let's change all occurrences at media-devnode.[ch] to also use "devnode" for such pointers.
This patch doesn't make any functional changes.
--- drivers/media/media-devnode.c | 110 +++++++++++++++++----------------- include/media/media-devnode.h | 16 ++--- 2 files changed, 63 insertions(+), 63 deletions(-)
drivers/media/media-devnode.c +57 -57
@@ -59,21 +59,21 @@ static DECLARE_BITMAP(media_devnode_nums/* Called when the last user of the media device exits. */ static void media_devnode_release (struct device *cd) { -struct media_devnode *mdev =to_media_devnode (cd); +struct media_devnode *devnode =to_media_devnode (cd);mutex_lock (&media_devnode_lock);/* Delete the cdev on this minor as well */ -cdev_del (&mdev->cdev); +cdev_del (&devnode->cdev);/* Mark device node number as free */ -clear_bit (mdev->minor, media_devnode_nums); +clear_bit (devnode->minor, media_devnode_nums);mutex_unlock (&media_devnode_lock);/* Release media_devnode and perform other cleanups as needed. */ -if (mdev->release) - mdev->release (mdev); +if (devnode->release) + devnode->release (devnode); }static struct bus_type media_bus_type = {
@@ -83,37 +83,37 @@ static struct bus_type media_bus_type =static ssize_t media_read (struct file *filp,char __user *buf,size_t sz,loff_t *off) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -if (!mdev->fops->read) +if (!devnode->fops->read)return -EINVAL ; -if (!media_devnode_is_registered (mdev)) +if (!media_devnode_is_registered (devnode))return -EIO ; -return mdev->fops->read (filp, buf, sz, off); +return devnode->fops->read (filp, buf, sz, off); }static ssize_t media_write (struct file *filp,const char __user *buf,size_t sz,loff_t *off) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -if (!mdev->fops->write) +if (!devnode->fops->write)return -EINVAL ; -if (!media_devnode_is_registered (mdev)) +if (!media_devnode_is_registered (devnode))return -EIO ; -return mdev->fops->write (filp, buf, sz, off); +return devnode->fops->write (filp, buf, sz, off); }static unsigned int media_poll (struct file *filp,struct poll_table_struct *poll) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -if (!media_devnode_is_registered (mdev)) +if (!media_devnode_is_registered (devnode))return POLLERR |POLLHUP ; -if (!mdev->fops->poll) +if (!devnode->fops->poll)return DEFAULT_POLLMASK ; -return mdev->fops->poll (filp, poll); +return devnode->fops->poll (filp, poll); } static long
@@ -121,12 +121,12 @@ __media_ioctl(struct file *filp, unsignelong (*ioctl_func)(struct file *filp,unsigned int cmd, unsigned long arg)) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp);if (!ioctl_func)return -ENOTTY ; -if (!media_devnode_is_registered (mdev)) +if (!media_devnode_is_registered (devnode))return -EIO ;return ioctl_func (filp, cmd, arg);
@@ -134,9 +134,9 @@ __media_ioctl(struct file *filp, unsignestatic long media_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -return __media_ioctl (filp, cmd, arg, mdev->fops->ioctl); +return __media_ioctl (filp, cmd, arg, devnode->fops->ioctl); }#ifdef CONFIG_COMPAT
@@ -144,9 +144,9 @@ static long media_ioctl(struct file *filstatic long media_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -return __media_ioctl (filp, cmd, arg, mdev->fops->compat_ioctl); +return __media_ioctl (filp, cmd, arg, devnode->fops->compat_ioctl); }#endif /* CONFIG_COMPAT */
@@ -154,7 +154,7 @@ static long media_compat_ioctl(struct fi/* Override for the open function */ static int media_open (struct inode *inode,struct file *filp) { -struct media_devnode *mdev; +struct media_devnode *devnode;int ret;/* Check if the media device is available. This needs to be done with
@@ -164,23 +164,23 @@ static int media_open(struct inode *inod* a crash. */ mutex_lock (&media_devnode_lock); - mdev = container_of(inode->i_cdev, struct media_devnode, cdev); + devnode = container_of(inode->i_cdev, struct media_devnode, cdev);/* return ENXIO if the media device has been removed already or if it is not registered anymore. */ -if (!media_devnode_is_registered (mdev)) { +if (!media_devnode_is_registered (devnode)) {mutex_unlock (&media_devnode_lock);return -ENXIO ; }/* and increase the device refcount */ -get_device (&mdev->dev); +get_device (&devnode->dev);mutex_unlock (&media_devnode_lock); - filp->private_data = mdev; + filp->private_data = devnode; -if (mdev->fops->open) { - ret = mdev->fops->open (filp); +if (devnode->fops->open) { + ret = devnode->fops->open (filp);if (ret) { -put_device (&mdev->dev); +put_device (&devnode->dev); filp->private_data =NULL ;return ret; }
@@ -192,16 +192,16 @@ static int media_open(struct inode *inod/* Override for the release function */ static int media_release (struct inode *inode,struct file *filp) { -struct media_devnode *mdev =media_devnode_data (filp); +struct media_devnode *devnode =media_devnode_data (filp); -if (mdev->fops->release) - mdev->fops->release (filp); +if (devnode->fops->release) + devnode->fops->release (filp); filp->private_data =NULL ;/* decrease the refcount unconditionally since the release() return value is ignored. */ -put_device (&mdev->dev); +put_device (&devnode->dev);return 0 ; }
@@ -221,7 +221,7 @@ static const struct file_operations medi/** * media_devnode_register - register a media device node -* @mdev: media device node structure we want to register +* @devnode: media device node structure we want to register * * The registration code assigns minor numbers and registers the new device node * with the kernel. An error is returned if no free minor number can be found,
@@ -233,7 +233,7 @@ static const struct file_operations medi* the media_devnode structure is *not* called, so the caller is responsible for * freeing any data. */ -int __must_check media_devnode_register (struct media_devnode *mdev, +int __must_check media_devnode_register (struct media_devnode *devnode,struct module *owner) {int minor;
@@ -251,40 +251,40 @@ int __must_check media_devnode_register(set_bit (minor, media_devnode_nums);mutex_unlock (&media_devnode_lock); - mdev->minor = minor; + devnode->minor = minor;/* Part 2: Initialize and register the character device */ -cdev_init (&mdev->cdev, &media_devnode_fops); - mdev->cdev.owner = owner; +cdev_init (&devnode->cdev, &media_devnode_fops); + devnode->cdev.owner = owner; - ret =cdev_add (&mdev->cdev,MKDEV (MAJOR (media_dev_t), mdev->minor),1 ); + ret =cdev_add (&devnode->cdev,MKDEV (MAJOR (media_dev_t), devnode->minor),1 );if (ret <0 ) {pr_err ("%s: cdev_add failed\n" , __func__); goto error; }/* Part 3: Register the media device */ - mdev->dev.bus = &media_bus_type; - mdev->dev.devt =MKDEV (MAJOR (media_dev_t), mdev->minor); - mdev->dev.release = media_devnode_release; -if (mdev->parent) - mdev->dev.parent = mdev->parent; -dev_set_name (&mdev->dev,"media%d" , mdev->minor); - ret =device_register (&mdev->dev); + devnode->dev.bus = &media_bus_type; + devnode->dev.devt =MKDEV (MAJOR (media_dev_t), devnode->minor); + devnode->dev.release = media_devnode_release; +if (devnode->parent) + devnode->dev.parent = devnode->parent; +dev_set_name (&devnode->dev,"media%d" , devnode->minor); + ret =device_register (&devnode->dev);if (ret <0 ) {pr_err ("%s: device_register failed\n" , __func__); goto error; }/* Part 4: Activate this minor. The char device can now be used. */ -set_bit (MEDIA_FLAG_REGISTERED , &mdev->flags); +set_bit (MEDIA_FLAG_REGISTERED , &devnode->flags);return 0 ; error:mutex_lock (&media_devnode_lock); -cdev_del (&mdev->cdev); -clear_bit (mdev->minor, media_devnode_nums); +cdev_del (&devnode->cdev); +clear_bit (devnode->minor, media_devnode_nums);mutex_unlock (&media_devnode_lock);return ret;
@@ -292,7 +292,7 @@ error:/** * media_devnode_unregister - unregister a media device node -* @mdev: the device node to unregister +* @devnode: the device node to unregister * * This unregisters the passed device. Future open calls will be met with * errors.
@@ -300,16 +300,16 @@ error:* This function can safely be called if the device node has never been * registered or has already been unregistered. */ -void media_devnode_unregister (struct media_devnode *mdev) +void media_devnode_unregister (struct media_devnode *devnode) { -/* Check if mdev was ever registered at all */ -if (!media_devnode_is_registered (mdev)) +/* Check if devnode was ever registered at all */ +if (!media_devnode_is_registered (devnode))return ;mutex_lock (&media_devnode_lock); -clear_bit (MEDIA_FLAG_REGISTERED , &mdev->flags); +clear_bit (MEDIA_FLAG_REGISTERED , &devnode->flags);mutex_unlock (&media_devnode_lock); -device_unregister (&mdev->dev); +device_unregister (&devnode->dev); }/*
include/media/media-devnode.h +5 -5
@@ -76,24 +76,24 @@ struct media_devnode {unsigned long flags;/* Use bitops to access flags */ /* callbacks */ - void (*release)(struct media_devnode *mdev); + void (*release)(struct media_devnode *devnode); };/* dev to media_devnode */ #define to_media_devnode (cd) container_of(cd, struct media_devnode, dev) -int __must_check media_devnode_register (struct media_devnode *mdev, +int __must_check media_devnode_register (struct media_devnode *devnode,struct module *owner); -void media_devnode_unregister (struct media_devnode *mdev); +void media_devnode_unregister (struct media_devnode *devnode);static inline struct media_devnode *media_devnode_data (struct file *filp) {return filp->private_data; } -static inline int media_devnode_is_registered (struct media_devnode *mdev) +static inline int media_devnode_is_registered (struct media_devnode *devnode) { -return test_bit (MEDIA_FLAG_REGISTERED , &mdev->flags); +return test_bit (MEDIA_FLAG_REGISTERED , &devnode->flags); }#endif /* _MEDIA_DEVNODE_H */
PATCH 242/245 media-device: dynamically allocate struct media_devnode
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit a087ce704b802becbb4b0f2a20f2cb3f6911802e upstream.
struct media_devnode is currently embedded at struct media_device.
While this works fine during normal usage, it leads to a race condition during devnode unregister. the problem is that drivers assume that, after calling media_device_unregister(), the struct that contains media_device can be freed. This is not true, as it can't be freed until userspace closes all opened /dev/media devnodes.
In other words, if the media devnode is still open, and media_device gets freed, any call to an ioctl will make the core to try to access struct media_device, with will cause an use-after-free and even GPF.
Fix this by dynamically allocating the struct media_devnode and only freeing it when it is safe.
[bwh: Backported to 3.16:
- Drop change in au0828
- Include <linux/slab.h> in media-device.c
- Adjust context]
---
drivers/media/media-device.c +28 -12
@@ -24,6 +24,7 @@#include <linux/export.h> #include <linux/ioctl.h> #include <linux/media.h> +#include <linux/slab.h> #include <linux/types.h> #include <media/media-device.h>
@@ -236,7 +237,7 @@ static long media_device_ioctl(struct fi unsigned long arg) {struct media_devnode *devnode =media_devnode_data (filp); -struct media_device *dev =to_media_device (devnode); +struct media_device *dev = devnode->media_dev;long ret;switch (cmd) {
@@ -305,7 +306,7 @@ static long media_device_compat_ioctl(st unsigned long arg) {struct media_devnode *devnode =media_devnode_data (filp); -struct media_device *dev =to_media_device (devnode); +struct media_device *dev = devnode->media_dev;long ret;switch (cmd) {
@@ -346,7 +347,8 @@ static const struct media_file_operationstatic ssize_t show_model (struct device *cd,struct device_attribute *attr,char *buf) { -struct media_device *mdev =to_media_device (to_media_devnode (cd)); +struct media_devnode *devnode =to_media_devnode (cd); +struct media_device *mdev = devnode->media_dev;return sprintf (buf,"%.*s\n" , (int )sizeof (mdev->model), mdev->model); }
@@ -374,6 +376,7 @@ static void media_device_release(structint __must_check __media_device_register (struct media_device *mdev,struct module *owner) { +struct media_devnode *devnode;int ret;if (WARN_ON (mdev->dev ==NULL || mdev->model[0 ] ==0 ))
@@ -384,17 +387,27 @@ int __must_check __media_device_registerspin_lock_init (&mdev->lock);mutex_init (&mdev->graph_mutex); + devnode =kzalloc (sizeof (*devnode),GFP_KERNEL ); +if (!devnode) +return -ENOMEM ; +/* Register the device node. */ - mdev->devnode.fops = &media_device_fops; - mdev->devnode.parent = mdev->dev; - mdev->devnode.release = media_device_release; - ret =media_devnode_register (&mdev->devnode, owner); -if (ret <0 ) + mdev->devnode = devnode; + devnode->fops = &media_device_fops; + devnode->parent = mdev->dev; + devnode->release = media_device_release; + ret =media_devnode_register (mdev, devnode, owner); +if (ret <0 ) { + mdev->devnode =NULL ; +kfree (devnode);return ret; + } - ret =device_create_file (&mdev->devnode.dev, &dev_attr_model); + ret =device_create_file (&devnode->dev, &dev_attr_model);if (ret <0 ) { -media_devnode_unregister (&mdev->devnode); + mdev->devnode =NULL ; +media_devnode_unregister (devnode); +kfree (devnode);return ret; }
@@ -415,8 +428,11 @@ void media_device_unregister(struct medilist_for_each_entry_safe (entity, next, &mdev->entities, list)media_device_unregister_entity (entity); -device_remove_file (&mdev->devnode.dev, &dev_attr_model); -media_devnode_unregister (&mdev->devnode); +/* Check if mdev devnode was registered */ +if (media_devnode_is_registered (mdev->devnode)) { +device_remove_file (&mdev->devnode->dev, &dev_attr_model); +media_devnode_unregister (mdev->devnode); + } }EXPORT_SYMBOL_GPL (media_device_unregister);
drivers/media/media-devnode.c +7 -1
@@ -44,6 +44,7 @@#include <linux/uaccess.h> #include <media/media-devnode.h> +#include <media/media-device.h> #define MEDIA_NUM_DEVICES 256#define MEDIA_NAME "media"
@@ -74,6 +75,8 @@ static void media_devnode_release(struct/* Release media_devnode and perform other cleanups as needed. */ if (devnode->release) devnode->release (devnode); + +kfree (devnode); }static struct bus_type media_bus_type = {
@@ -221,6 +224,7 @@ static const struct file_operations medi/** * media_devnode_register - register a media device node +* @media_dev: struct media_device we want to register a device node * @devnode: media device node structure we want to register * * The registration code assigns minor numbers and registers the new device node
@@ -233,7 +237,8 @@ static const struct file_operations medi* the media_devnode structure is *not* called, so the caller is responsible for * freeing any data. */ -int __must_check media_devnode_register (struct media_devnode *devnode, +int __must_check media_devnode_register (struct media_device *mdev, +struct media_devnode *devnode,struct module *owner) {int minor;
@@ -252,6 +257,7 @@ int __must_check media_devnode_register(mutex_unlock (&media_devnode_lock); devnode->minor = minor; + devnode->media_dev = mdev;/* Part 2: Initialize and register the character device */ cdev_init (&devnode->cdev, &media_devnode_fops);
include/media/media-device.h +1 -4
@@ -60,7 +60,7 @@ struct device;struct media_device {/* dev->driver_data points to this struct. */ struct device *dev; -struct media_devnode devnode; +struct media_devnode *devnode;char model[32 ];char serial[40 ];
@@ -84,9 +84,6 @@ struct media_device {#define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0#define MEDIA_DEV_NOTIFY_POST_LINK_CH 1 -/* media_devnode to media_device */ -#define to_media_device (node) container_of(node, struct media_device, devnode) -int __must_check __media_device_register (struct media_device *mdev,struct module *owner);#define media_device_register (mdev) __media_device_register(mdev, THIS_MODULE)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -1640,7 +1640,7 @@ static void uvc_delete(struct uvc_deviceif (dev->vdev.dev)v4l2_device_unregister (&dev->vdev);#ifdef CONFIG_MEDIA_CONTROLLER -if (media_devnode_is_registered (&dev->mdev.devnode)) +if (media_devnode_is_registered (dev->mdev.devnode))media_device_unregister (&dev->mdev);#endif
include/media/media-devnode.h +9 -1
@@ -33,6 +33,8 @@#include <linux/device.h> #include <linux/cdev.h> +struct media_device ; +/* * Flag to mark the media_devnode struct as registered. Drivers must not touch * this flag directly, it will be set and cleared by media_devnode_register and
@@ -63,6 +65,8 @@ struct media_file_operations {* before registering the node. */ struct media_devnode { +struct media_device *media_dev; +/* device ops */ const struct media_file_operations *fops;
@@ -82,7 +86,8 @@ struct media_devnode {/* dev to media_devnode */ #define to_media_devnode (cd) container_of(cd, struct media_devnode, dev) -int __must_check media_devnode_register (struct media_devnode *devnode, +int __must_check media_devnode_register (struct media_device *mdev, +struct media_devnode *devnode,struct module *owner);void media_devnode_unregister (struct media_devnode *devnode);
@@ -93,6 +98,9 @@ static inline struct media_devnode *medistatic inline int media_devnode_is_registered (struct media_devnode *devnode) { +if (!devnode) +return false; +return test_bit (MEDIA_FLAG_REGISTERED , &devnode->flags); }
PATCH 243/245 media: fix use-after-free in cdev_put() when app exits after driver unbind
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 5b28dde51d0ccc54cee70756e1800d70bed7114a upstream.
When driver unbinds while media_ioctl is in progress, cdev_put() fails with when app exits after driver unbinds.
Add devnode struct device kobj as the cdev parent kobject. cdev_add() gets a reference to it and releases it in cdev_del() ensuring that the devnode is not deallocated as long as the application has the device file open.
media_devnode_register() initializes the struct device kobj before calling cdev_add(). media_devnode_unregister() does cdev_del() and then deletes the device. devnode is released when the last reference to the struct device is gone.
This problem is found on uvcvideo, em28xx, and au0828 drivers and fix has been tested on all three.
kernel: [ 193.599736] BUG: KASAN: use-after-free in cdev_put+0x4e/0x50
kernel: [ 193.599745] Read of size 8 by task media_device_te/1851
kernel: [ 193.599792] INFO: Allocated in __media_device_register+0x54
kernel: [ 193.599951] INFO: Freed in media_devnode_release+0xa4/0xc0
kernel: [ 193.601083] Call Trace:
kernel: [ 193.601093] [<ffffffff81aecac3>] dump_stack+0x67/0x94
kernel: [ 193.601102] [<ffffffff815359b2>] print_trailer+0x112/0x1a0
kernel: [ 193.601111] [<ffffffff8153b5e4>] object_err+0x34/0x40
kernel: [ 193.601119] [<ffffffff8153d9d4>] kasan_report_error+0x224/0x530
kernel: [ 193.601128] [<ffffffff814a2c3d>] ? kzfree+0x2d/0x40
kernel: [ 193.601137] [<ffffffff81539d72>] ? kfree+0x1d2/0x1f0
kernel: [ 193.601154] [<ffffffff8157ca7e>] ? cdev_put+0x4e/0x50
kernel: [ 193.601162] [<ffffffff8157ca7e>] cdev_put+0x4e/0x50
kernel: [ 193.601170] [<ffffffff815767eb>] __fput+0x52b/0x6c0
kernel: [ 193.601179] [<ffffffff8117743a>] ? switch_task_namespaces+0x2a
kernel: [ 193.601188] [<ffffffff815769ee>] ____fput+0xe/0x10
kernel: [ 193.601196] [<ffffffff81170023>] task_work_run+0x133/0x1f0
kernel: [ 193.601204] [<ffffffff8117746e>] ? switch_task_namespaces+0x5e
kernel: [ 193.601213] [<ffffffff8111b50c>] do_exit+0x72c/0x2c20
kernel: [ 193.601224] [<ffffffff8111ade0>] ? release_task+0x1250/0x1250 -
-
-
kernel: [ 193.601360] [<ffffffff81003587>] ? exit_to_usermode_loop+0xe7
kernel: [ 193.601368] [<ffffffff810035c0>] exit_to_usermode_loop+0x120
kernel: [ 193.601376] [<ffffffff810061da>] syscall_return_slowpath+0x16a
kernel: [ 193.601386] [<ffffffff82848b33>] entry_SYSCALL_64_fastpath+0xa6
--- drivers/media/media-device.c | 6 +++-- drivers/media/media-devnode.c | 48 +++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-)
drivers/media/media-device.c +4 -2
@@ -398,16 +398,16 @@ int __must_check __media_device_register devnode->release = media_device_release; ret =media_devnode_register (mdev, devnode, owner);if (ret <0 ) { +/* devnode free is handled in media_devnode_*() */ mdev->devnode =NULL ; -kfree (devnode);return ret; } ret =device_create_file (&devnode->dev, &dev_attr_model);if (ret <0 ) { +/* devnode free is handled in media_devnode_*() */ mdev->devnode =NULL ;media_devnode_unregister (devnode); -kfree (devnode);return ret; }
@@ -432,6 +432,8 @@ void media_device_unregister(struct mediif (media_devnode_is_registered (mdev->devnode)) {device_remove_file (&mdev->devnode->dev, &dev_attr_model);media_devnode_unregister (mdev->devnode); +/* devnode free is handled in media_devnode_*() */ + mdev->devnode =NULL ; } }EXPORT_SYMBOL_GPL (media_device_unregister);
drivers/media/media-devnode.c +29 -19
107 lines not on this page · raw message
PATCH 244/245 media: fix media devnode ioctl/syscall and unregister race
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 6f0dd24a084a17f9984dd49dffbf7055bf123993 upstream.
Media devnode open/ioctl could be in progress when media device unregister is initiated. System calls and ioctls check media device registered status at the beginning, however, there is a window where unregister could be in progress without changing the media devnode status to unregistered.
process 1 process 2
fd = open(/dev/media0)media_devnode_is_registered()
(returns true here)
media_device_unregister()
(unregister is in progress and devnode isn't unregistered yet)
...ioctl(fd, ...)__media_ioctl()media_devnode_is_registered()
(returns true here) ... media_devnode_unregister() ... (driver releases the media device memory)
media_device_ioctl()
(By this point
devnode->media_dev does not
point to allocated memory.
use-after free in in mutex_lock_nested)
BUG: KASAN: use-after-free in mutex_lock_nested+0x79c/0x800 at addr
ffff8801ebe914f0
Fix it by clearing register bit when unregister starts to avoid the race.
process 1 process 2
fd = open(/dev/media0)media_devnode_is_registered()
(could return true here)
media_device_unregister()
(clear the register bit,
then start unregister.)
...ioctl(fd, ...)__media_ioctl()media_devnode_is_registered()
(return false here, ioctl
returns I/O error, and
will not access media
device memory)
...
media_devnode_unregister()
...
(driver releases the media device
memory)
---
drivers/media/media-device.c +8 -7
@@ -407,6 +407,7 @@ int __must_check __media_device_registerif (ret <0 ) {/* devnode free is handled in media_devnode_*() */ mdev->devnode =NULL ; +media_devnode_unregister_prepare (devnode);media_devnode_unregister (devnode);return ret; }
@@ -425,16 +426,16 @@ void media_device_unregister(struct medistruct media_entity *entity;struct media_entity *next; +/* Clear the devnode register bit to avoid races with media dev open */ +media_devnode_unregister_prepare (mdev->devnode); +list_for_each_entry_safe (entity, next, &mdev->entities, list)media_device_unregister_entity (entity); -/* Check if mdev devnode was registered */ -if (media_devnode_is_registered (mdev->devnode)) { -device_remove_file (&mdev->devnode->dev, &dev_attr_model); -media_devnode_unregister (mdev->devnode); -/* devnode free is handled in media_devnode_*() */ - mdev->devnode =NULL ; - } +device_remove_file (&mdev->devnode->dev, &dev_attr_model); +media_devnode_unregister (mdev->devnode); +/* devnode free is handled in media_devnode_*() */ + mdev->devnode =NULL ; }EXPORT_SYMBOL_GPL (media_device_unregister);
drivers/media/media-devnode.c +12 -7
@@ -302,6 +302,17 @@ cdev_add_error:return ret; } +void media_devnode_unregister_prepare (struct media_devnode *devnode) +{ +/* Check if devnode was ever registered at all */ +if (!media_devnode_is_registered (devnode)) +return ; + +mutex_lock (&media_devnode_lock); +clear_bit (MEDIA_FLAG_REGISTERED , &devnode->flags); +mutex_unlock (&media_devnode_lock); +} +/** * media_devnode_unregister - unregister a media device node * @devnode: the device node to unregister
@@ -309,17 +320,11 @@ cdev_add_error:* This unregisters the passed device. Future open calls will be met with * errors. * -* This function can safely be called if the device node has never been -* registered or has already been unregistered. +* Should be called after media_devnode_unregister_prepare() */ void media_devnode_unregister (struct media_devnode *devnode) { -/* Check if devnode was ever registered at all */ -if (!media_devnode_is_registered (devnode)) -return ; -mutex_lock (&media_devnode_lock); -clear_bit (MEDIA_FLAG_REGISTERED , &devnode->flags);/* Delete the cdev on this minor as well */ cdev_del (&devnode->cdev);mutex_unlock (&media_devnode_lock);
include/media/media-devnode.h +14 -0
@@ -89,6 +89,20 @@ struct media_devnode {int __must_check media_devnode_register (struct media_device *mdev,struct media_devnode *devnode,struct module *owner); + +/** +* media_devnode_unregister_prepare - clear the media device node register bit +* @devnode: the device node to prepare for unregister +* +* This clears the passed device register bit. Future open calls will be met +* with errors. Should be called before media_devnode_unregister() to avoid +* races with unregister and device file open calls. +* +* This function can safely be called if the device node has never been +* registered or has already been unregistered. +*/ +void media_devnode_unregister_prepare (struct media_devnode *devnode); +void media_devnode_unregister (struct media_devnode *devnode);static inline struct media_devnode *media_devnode_data (struct file *filp)
PATCH 245/245 slcan: Don't transmit uninitialized stack data in padding
In reply to Ben Hutchings3.16.83-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Richard Palethorpe <[email protected]>
commit b9258a2cece4ec1f020715fe3554bc2e360f6264 upstream.
struct can_frame contains some padding which is not explicitly zeroed in slc_bump. This uninitialized data will then be transmitted if the stack initialization hardening feature is not enabled (CONFIG_INIT_STACK_ALL).
This commit just zeroes the whole struct including the padding.
--- drivers/net/can/slcan.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/can/slcan.c +1 -3
@@ -150,7 +150,7 @@ static void slc_bump(struct slcan *sl)u32 tmpid;char *cmd = sl->rbuff; - cf.can_id =0 ; +memset (&cf,0 ,sizeof (cf));switch (*cmd) {case 'r' :
@@ -189,8 +189,6 @@ static void slc_bump(struct slcan *sl)else return ; - *(u64 *) (&cf.data) =0 ;/* clear payload */ -/* RTR frames may have a dlc > 0 but they never have any data bytes */ if (!(cf.can_id &CAN_RTR_FLAG )) {for (i =0 ; i < cf.can_dlc; i++) {
Quoted 7 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 245 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
Can you please add backports of the following patches? I asked for
that in <https://lore.kernel.org/stable/CAG48ez29d-JJOw8XMp1Z=7sDj8Kvmt+9KXC9-ux-0OBhUP02Xg@mail.gmail.com/>,
but I guess that fell through the cracks somehow.
8019ad13ef7f64be44d4f892af9c840179009254 "futex: Fix inode life-time issue" 8d67743653dce5a0e7aa500fcccb237cde7ad88e "futex: Unbreak futex hashing"
Can those still go into 3.16.83, or is it too late for that now?
Quoted 6 lines · Jann Horn
Quoted 5 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 245 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Quoted 6 lines
Quoted 2 lines
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
Can you please add backports of the following patches? I asked for
that in <https://lore.kernel.org/stable/CAG48ez29d-JJOw8XMp1Z=7sDj8Kvmt+9KXC9-ux-0OBhUP02Xg@mail.gmail.com/>;,
but I guess that fell through the cracks somehow.
Sorry I forgot about this,
Quoted 4 lines
8019ad13ef7f64be44d4f892af9c840179009254"futex: Fix inode life-time issue"8d67743653dce5a0e7aa500fcccb237cde7ad88e"futex: Unbreak futex hashing"Can those still go into 3.16.83, or is it too late for that now?
I'll add them and send an -rc2.
Ben.
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 245 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
For v3.16.82-245-g6e963df:
Build results:
total: 135 pass: 135 fail: 0 Qemu test results: total: 233 pass: 233 fail: 0
Guenter
Quoted 10 lines · Guenter Roeck
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 245 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
Quoted 6 lines
For v3.16.82-245-g6e963df:
Build results:
total: 135 pass: 135 fail: 0 Qemu test results: total: 233 pass: 233 fail: 0
Thanks for checking,
Ben.
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
cover 3.16.83-rc2 review
In reply to Ben HutchingsThis is the start of the stable review cycle for the 3.16.83 release. There are 247 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
All the patches have also been committed to the linux-3.16.y-rc branch of
https://git.kernel.org/pub/scm/linux/kernel/git/bwh/linux-stable-rc.git . A shortlog and diffstat can be found below.
Ben.
-------------
Al Viro (2):
do_last(): fetch directory ->i_mode and ->i_uid before it's too late
[d0cb50185ae942b03c4327be322055d622dc79f6]
vfs: fix do_last() regression
[6404674acd596de41fd3ad5f267b4525494a891a]Alan Cox (1):
usb: dwc3: pci: Add PCI ID for Intel Braswell
[7d643664ea559b36188cae264047ce3c9bfec3a2]
Alan Stern (1):
HID: Fix slab-out-of-bounds read in hid_field_extract
[8ec321e96e056de84022c032ffea253431a83c3c]
Alberto Aguirre (2):
ALSA: usb-audio: add implicit fb quirk for Axe-Fx II
[17f08b0d9aafccdb10038ab6dbd9ddb6433c13e2]
ALSA: usb-audio: simplify set_sync_ep_implicit_fb_quirk
[103e9625647ad74d201e26fb74afcd8479142a37]
Alex Sverdlin (1):
ARM: 8950/1: ftrace/recordmcount: filter relocation types
[927d780ee371d7e121cea4fc7812f6ef2cea461c]
Amir Goldstein (1):
locks: print unsigned ino in /proc/locks
[98ca480a8f22fdbd768e3dad07024c8d4856576c]
Ard Biesheuvel (1):
x86/efistub: Disable paging at mixed mode entry
[4911ee401b7ceff8f38e0ac597cbf503d71e690c]
Arnd Bergmann (2):
btrfs: tree-checker: use %zu format string for size_t
[7cfad65297bfe0aa2996cd72d21c898aa84436d9]
scsi: fnic: fix invalid stack access
[42ec15ceaea74b5f7a621fc6686cbf69ca66c4cf]
Avinash Patil (1):
mwifiex: fix probable memory corruption while processing TDLS frame
[3c99832d74777c9ec5545a92450fac5d37b0d0e1]
Brian Norris (1):
mwifiex: fix unbalanced locking in mwifiex_process_country_ie()
[65b1aae0d9d5962faccc06bdb8e91a2a0b09451c]
Cengiz Can (1):
blktrace: fix dereference after null check
[153031a301bb07194e9c37466cfce8eacb977621]
Chao Yu (1):
quota: fix wrong condition in is_quota_modification()
[6565c182094f69e4ffdece337d395eb7ec760efc]
Chen-Yu Tsai (1):
net: stmmac: dwmac-sunxi: Allow all RGMII modes
[52cc73e5404c7ba0cbfc50cb4c265108c84b3d5a]
Christian Brauner (1):
taskstats: fix data-race
[0b8d616fb5a8ffa307b1d3af37f55c15dae14f28]
Christophe Leroy (1):
powerpc/irq: fix stack overflow verification
[099bc4812f09155da77eeb960a983470249c9ce1]
Cong Wang (2):
net_sched: fix datalen for ematch
[61678d28d4a45ef376f5d02a839cc37509ae9281]
netfilter: fix a use-after-free in mtype_destroy()
[c120959387efa51479056fd01dc90adfba7a590c]
Dan Carpenter (1):
scsi: iscsi: qla4xxx: fix double free in probe
[fee92f25777789d73e1936b91472e9c4644457c8]
David Hildenbrand (1):
virtio-balloon: fix managed page counts when migrating pages between zones
[63341ab03706e11a31e3dd8ccc0fbc9beaf723f0]
David Sterba (6):
btrfs: add more checks to btrfs_read_sys_array
[e3540eab29e1b2260bc4b9b3979a49a00e3e3af8]
btrfs: cleanup, rename a few variables in btrfs_read_sys_array
[1ffb22cf8c322bbfea6b35fe23d025841b49fede]
btrfs: handle invalid num_stripes in sys_array
[f5cdedd73fa71b74dcc42f2a11a5735d89ce7c4f]
btrfs: kill extent_buffer_page helper
[fb85fc9a675738ee2746b51c3aedde944b18ca02]
btrfs: new define for the inline extent data start
[7ec20afbcb7b257aec82ea5d66e6b0b7499abaca]
btrfs: tree-check: reduce stack consumption in check_dir_item
[e2683fc9d219430f5b78889b50cde7f40efeba7b]
Davidlohr Bueso (1):
blktrace: re-write setting q->blk_trace
[cdea01b2bf98affb7e9c44530108a4a28535eee8]Dedy Lansky (1):
cfg80211/mac80211: make ieee80211_send_layer2_update a public function
[30ca1aa536211f5ac3de0173513a7a99a98a97f3]Dmitry Torokhov (5):
HID: hid-input: clear unmapped usages
[4f3882177240a1f55e45a3d241d3121341bead78]
Input: add safety guards to input_set_keycode()
[cb222aed03d798fc074be55e59d9a112338ee784]
ptp: create "pins" together with the rest of attributes
[85a66e55019583da1e0f18706b7a8281c9f6de5b]
ptp: do not explicitly set drvdata in ptp_clock_register()
[882f312dc0751c973db26478f07f082c584d16aa]
ptp: use is_visible method to hide unused attributes
[af59e717d5ff9c8dbf9bcc581c0dfb3b2a9c9030]
Emiliano Ingrassia (1):
usb: core: urb: fix URB structure initialization function
[1cd17f7f0def31e3695501c4f86cd3faf8489840]
Eric Dumazet (9):
6pack,mkiss: fix possible deadlock
[5c9934b6767b16ba60be22ec3cbd4379ad64170d]
bonding: fix bond_neigh_init()
[9e99bfefdbce2e23ef37487a3bcb4adf90a791d1]
macvlan: do not assume mac_header is set in macvlan_broadcast()
[96cc4b69581db68efc9749ef32e9cf8e0160c509]
macvlan: use skb_reset_mac_header() in macvlan_queue_xmit()
[1712b2fff8c682d145c7889d2290696647d82dab]
neighbour: remove neigh_cleanup() method
[f394722fb0d0f701119368959d7cd0ecbc46363a]
netfilter: bridge: make sure to pull arp header in br_nf_forward_arp()
[5604285839aaedfb23ebe297799c6e558939334d]
pkt_sched: fq: do not accept silly TCA_FQ_QUANTUM
[d9e15a2733067c9328fb56d98fe8e574fa19ec31]
tcp: do not send empty skb from tcp_write_xmit()
[1f85e6267caca44b30c54711652b0726fadbb131]
vlan: vlan_changelink() should propagate errors
[eb8ef2a3c50092bb018077c047b8dba1ce0e78e3]
Erkka Talvitie (1):
USB: EHCI: Do not return -EPIPE when hub is disconnected
[64cc3f12d1c7dd054a215bc1ff9cc2abcfe35832]
Eryu Guan (1):
ext4: update c/mtime on truncate up
[911af577de4e444622d46500c1f9a37ab4335d3a]
Eugenio Pérez (1):
vhost: Check docket sk_family instead of call getname
[42d84c8490f9f0931786f1623191fcab397c3d64]
Fabian Henneke (1):
hidraw: Return EPOLLOUT from hidraw_poll
[378b80370aa1fe50f9c48a3ac8af3e416e73b89f]
Felipe Balbi (3):
usb: dwc3: pci: Add Support for Intel Elkhart Lake Devices
[dbb0569de852fb4576d6f62078d515f989a181ca]
usb: dwc3: pci: add support for Comet Lake PCH ID
[7ae622c978db6b2e28b4fced6ecd2a174492059d]
usb: dwc3: pci: add support for TigerLake Devices
[b3649dee5fbb0f6585010e6e9313dfcbb075b22b]
Filipe Manana (3):
Btrfs: fix emptiness check for dirtied extent buffers at check_leaf()
[f177d73949bf758542ca15a1c1945bd2e802cc65]
Btrfs: fix infinite loop during nocow writeback due to race
[de7999afedff02c6631feab3ea726a0e8f8c3d40]
Btrfs: fix removal logic of the tree mod log that leads to use-after-free issues
[6609fee8897ac475378388238456c84298bff802]
Finn Thain (4):
net/sonic: Add mutual exclusion for accessing shared state
[865ad2f2201dc18685ba2686f13217f8b3a9c52c]
net/sonic: Fix receive buffer handling
[9e311820f67e740f4fb8dcb82b4c4b5b05bdd1a5]
net/sonic: Quiesce SONIC before re-initializing descriptor memory
[3f4b7e6a2be982fd8820a2b54d46dd9c351db899]
net/sonic: Use MMIO accessors
[e3885f576196ddfc670b3d53e745de96ffcb49ab]
Florian Faber (1):
can: mscan: mscan_rx_poll(): fix rx path lockup when returning from polling to irq mode
[2d77bd61a2927be8f4e00d9478fe6996c47e8d45]
Florian Westphal (6):
netfilter: arp_tables: init netns pointer in xt_tgchk_param struct
[1b789577f655060d98d20ed0c6f9fbd469d6ba63]
netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct
[212e7f56605ef9688d0846db60c6c6ec06544095]
netfilter: ctnetlink: netns exit must wait for callbacks
[18a110b022a5c02e7dc9f6109d0bd93e58ac6ebb]
netfilter: ebtables: compat: reject all padding in matches/watchers
[e608f631f0ba5f1fc5ee2e260a3a35d13107cbfe]
netfilter: ebtables: convert BUG_ONs to WARN_ONs
[fc6a5d0601c5ac1d02f283a46f60b87b2033e5ca]
netfilter: ipset: avoid null deref when IPSET_ATTR_LINENO is present
[22dad713b8a5ff488e07b821195270672f486eb2]
Geert Uytterhoeven (1):
gpio: Fix error message on out-of-range GPIO in lookup table
[d935bd50dd14a7714cbdba9a76435dbb56edb1ae]
Goldwyn Rodrigues (1):
dm flakey: check for null arg_name in parse_features()
[7690e25302dc7d0cd42b349e746fe44b44a94f2b]
Gu Jinxiang (1):
btrfs: validate type when reading a chunk
[315409b0098fb2651d86553f0436b70502b29bb2]
Hangbin Liu (1):
vxlan: fix tos value before xmit
[71130f29979c7c7956b040673e6b9d5643003176]
Hans de Goede (2):
pinctrl: baytrail: Really serialize all register accesses
[40ecab551232972a39cdd8b6f17ede54a3fdb296]
platform/x86: hp-wmi: Make buffer for HPWMI_FEATURE2_QUERY 128 bytes
[133b2acee3871ae6bf123b8fe34be14464aa3d2c]
Heikki Krogerus (8):
usb: dwc3: pci: add ID for one more Intel Broxton platform
[1ffb4d5cc78a3a99109ff0808ce6915de07a0588]
usb: dwc3: pci: add ID for the Intel Comet Lake -H variant
[3c3caae4cd6e122472efcf64759ff6392fb6bce2]
usb: dwc3: pci: add Intel Cannonlake PCI IDs
[682179592e48fa66056fbad1a86604be4992f885]
usb: dwc3: pci: add Intel Gemini Lake PCI ID
[8f8983a5683623b62b339d159573f95a1fce44f3]
usb: dwc3: pci: add Intel Kabylake PCI ID
[4491ed5042f0419b22a4b08331adb54af31e2caa]
usb: dwc3: pci: add support for Intel Broxton SOC
[b4c580a43d520b7812c0fd064fbab929ce2f1da0]
usb: dwc3: pci: add support for Intel IceLake
[00908693c481f7298adf8cf4d2ff3dfbea8c375f]
usb: dwc3: pci: add support for Intel Sunrise Point PCH
[84a2b61b6eb94036093531cdabc448dddfbae45a]
Hou Tao (1):
dm btree: increase rebalance threshold in __rebalance2()
[474e559567fa631dea8fb8407ab1b6090c903755]
James Bottomley (1):
scsi: enclosure: Fix stale device oops with hot replug
[529244bd1afc102ab164429d338d310d5d65e60d]
Jan Kara (7):
blktrace: Protect q->blk_trace with RCU
[c780e86dd48ef6467a1146cf7d0fe1e05a635039]
ext4: check for directory entries too close to block end
[109ba779d6cca2d519c5dd624a3276d03e21948e]
ext4: fix races between buffered IO and collapse / insert range
[32ebffd3bbb4162da5ff88f9a35dd32d0a28ea70]
ext4: fix races between page faults and hole punching
[ea3d7209ca01da209cda6f0dea8be9cc4b7a933b]
ext4: fix races of writeback with punch hole and zero range
[011278485ecc3cd2a3954b5d4c73101d919bf1fa]
ext4: move unlocked dio protection from ext4_alloc_file_blocks()
[17048e8a083fec7ad841d88ef0812707fbc7e39f]
kobject: Export kobject_get_unless_zero()
[c70c176ff8c3ff0ac6ef9a831cd591ea9a66bd1a]Jari Ruusu (1):
Fix built-in early-load Intel microcode alignment
[f5ae2ea6347a308cfe91f53b53682ce635497d0d]
Jeff Mahoney (2):
btrfs: cleanup, stop casting for extent_map->lookup everywhere
[95617d69326ce386c95e33db7aeb832b45ee9f8f]
btrfs: struct-funcs, constify readers
[1cbb1f454e5321e47fc1e6b233066c7ccc979d15]Jerónimo Borque (1):
USB: serial: simple: Add Motorola Solutions TETRA MTP3xxx and MTP85xx
[260e41ac4dd3e5acb90be624c03ba7f019615b75]
Jian-Hong Pan (1):
platform/x86: asus-wmi: Fix keyboard brightness cannot be set to 0
[176a7fca81c5090a7240664e3002c106d296bf31]
Jim Mattson (1):
kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD
[396d2e878f92ec108e4293f1c77ea3bc90b414ff]
Jiri Kosina (1):
HID: hidraw, uhid: Always report EPOLLOUT
[9e635c2851df6caee651e589fbf937b637973c91]
Jiri Slaby (4):
vt: selection, close sel_buffer race
[07e6124a1a46b4b5a9b3cacc0c306b50da87abf5]
vt: selection, handle pending signals in paste_selection
[687bff0cd08f790d540cfb7b2349f0d876cdddec]
vt: selection, push console lock down
[4b70dd57a15d2f4685ac6e38056bad93e81e982f]
vt: selection, push sel_lock up
[e8c75a30a23c6ba63f4ef6895cbf41fd42f21aa2]
Johan Hovold (29):
ALSA: usb-audio: fix sync-ep altsetting sanity check
[5d1b71226dc4d44b4b65766fa9d74492f9d4587b]
Input: aiptek - fix endpoint sanity check
[3111491fca4f01764e0c158c5e0f7ced808eef51]
Input: gtco - fix endpoint sanity check
[a8eeb74df5a6bdb214b2b581b14782c5f5a0cf83]
Input: keyspan-remote - fix control-message timeouts
[ba9a103f40fc4a3ec7558ec9b0b97d4f92034249]
Input: sur40 - fix interface sanity checks
[6b32391ed675827f8425a414abbc6fbd54ea54fe]
USB: adutux: fix interface sanity check
[3c11c4bed02b202e278c0f5c319ae435d7fb9815]
USB: atm: ueagle-atm: add missing endpoint check
[09068c1ad53fb077bdac288869dec2435420bdc4]
USB: core: add endpoint-blacklist quirk
[73f8bda9b5dc1c69df2bc55c0cbb24461a6391a9]
USB: core: fix check for duplicate endpoints
[3e4f8e21c4f27bcf30a48486b9dcc269512b79ff]
USB: idmouse: fix interface sanity checks
[59920635b89d74b9207ea803d5e91498d39e8b69]
USB: quirks: blacklist duplicate ep on Sound Devices USBPre2
[bdd1b147b8026df0e4260b387026b251d888ed01]
USB: serial: ch341: handle unbound port at reset_resume
[4d5ef53f75c22d28f490bcc5c771fcc610a9afa4]
USB: serial: io_edgeport: add missing active-port sanity check
[1568c58d11a7c851bd09341aeefd6a1c308ac40d]
USB: serial: io_edgeport: fix epic endpoint lookup
[7c5a2df3367a2c4984f1300261345817d95b71f8]
USB: serial: io_edgeport: handle unbound ports on URB completion
[e37d1aeda737a20b1846a91a3da3f8b0f00cf690]
USB: serial: keyspan: handle unbound ports
[3018dd3fa114b13261e9599ddb5656ef97a1fa17]
USB: serial: opticon: fix control-message timeouts
[5e28055f340275a8616eee88ef19186631b4d136]
USB: serial: quatech2: handle unbound ports
[9715a43eea77e42678a1002623f2d9a78f5b81a1]
USB: serial: suppress driver bind attributes
[fdb838efa31e1ed9a13ae6ad0b64e30fdbd00570]
can: gs_usb: gs_usb_probe(): use descriptors of current altsetting
[2f361cd9474ab2c4ab9ac8db20faf81e66c6279b]
media: ov519: add missing endpoint sanity checks
[998912346c0da53a6dbb71fab3a138586b596b30]
media: stv06xx: add missing descriptor sanity checks
[485b06aadb933190f4bc44e006076bc27a23f205]
media: xirlink_cit: add missing descriptor sanity checks
[a246b4d547708f33ff4d4b9a7a5dbac741dc89d8]
r8152: add missing endpoint sanity check
[86f3f4cd53707ceeec079b83205c8d3c756eca93]
staging: gigaset: add endpoint-type sanity check
[ed9ed5a89acba51b82bdff61144d4e4a4245ec8a]
staging: gigaset: fix general protection fault on probe
[53f35a39c3860baac1e5ca80bf052751cfb24a99]
staging: gigaset: fix illegal free on probe errors
[84f60ca7b326ed8c08582417493982fe2573a9ad]
staging: rtl8188eu: fix interface sanity check
[74ca34118a0e05793935d804ccffcedd6eb56596]
staging: rtl8712: fix interface sanity check
[c724f776f048538ecfdf53a52b7a522309f5c504]
Johannes Thumshirn (1):
btrfs: ensure that a DUP or RAID1 block group has exactly two stripes
[349ae63f40638a28c6fce52e8447c2d14b84cc0c]
Jose Abreu (2):
net: stmmac: 16KB buffer must be 16 byte aligned
[8605131747e7e1fd8f6c9f97a00287aae2b2c640]
net: stmmac: Enable 16KB buffer size
[b2f3a481c4cd62f78391b836b64c0a6e72b503d2]
Josef Bacik (9):
Btrfs: fix em leak in find_first_block_group
[187ee58c62c1d0d238d3dc4835869d33e1869906]
btrfs: abort transaction after failed inode updates in create_subvol
[c7e54b5102bf3614cadb9ca32d7be73bad6cecf0]
btrfs: check rw_devices, not num_devices for balance
[b35cf1f0bf1f2b0b193093338414b9bd63b29015]
btrfs: do not call synchronize_srcu() in inode_tree_del
[f72ff01df9cf5db25c76674cac16605992d15467]
btrfs: do not delete mismatched root refs
[423a716cd7be16fb08690760691befe3be97d3fc]
btrfs: do not leak reloc root if we fail to read the fs root
[ca1aa2818a53875cfdd175fb5e9a2984e997cce9]
btrfs: handle ENOENT in btrfs_uuid_tree_iterate
[714cd3e8cba6841220dce9063a7388a81de03825]
btrfs: skip log replay on orphaned roots
[9bc574de590510eff899c3ca8dbaf013566b5efe]
ext4: only call ext4_truncate when size <= isize
[3da40c7b089810ac9cf2bb1e59633f619f3a7312]
Jouni Malinen (1):
mac80211: Do not send Layer 2 Update frame before authorization
[3e493173b7841259a08c5c8e5cbe90adb349da7e]
Kaitao Cheng (1):
kernel/trace: Fix do not unregister tracepoints when register sched_migrate_task fail
[50f9ad607ea891a9308e67b81f774c71736d1098]
Keiya Nobuta (1):
usb: core: hub: Improved device recognition on remote wakeup
[9c06ac4c83df6d6fbdbf7488fbad822b4002ba19]
Kenneth Klette Jonassen (1):
pkt_sched: fq: avoid hang when quantum 0
[3725a269815ba6dbb415feddc47da5af7d1fac58]
Lars Möllendorf (1):
iio: buffer: align the size of scan bytes to size of the largest element
[883f616530692d81cb70f8a32d85c0d2afc05f69]
Leo Yan (1):
tty: serial: msm_serial: Fix lockup for sysrq and oops
[0e4f7f920a5c6bfe5e851e989f27b35a0cc7fb7e]
Linus Torvalds (1):
floppy: check FDC index for errors before assigning it
[2e90ca68b0d2f5548804f22f0dd61145516171e3]
Liu Bo (9):
Btrfs: add validadtion checks for chunk loading
[e06cd3dd7cea50e87663a88acdfdb7ac1c53a5ca]
Btrfs: check btree node's nritems
[053ab70f0604224c7893b43f9d9d5efa283580d6]
Btrfs: check inconsistence between chunk and block group
[6fb37b756acce6d6e045f79c3764206033f617b4]
Btrfs: detect corruption when non-root leaf has zero item
[1ba98d086fe3a14d6a31f2f66dbab70c45d00f63]
Btrfs: fix BUG_ON in btrfs_mark_buffer_dirty
[ef85b25e982b5bba1530b936e283ef129f02ab9d]
Btrfs: improve check_node to avoid reading corrupted nodes
[6b722c1747d533ac6d4df110dc8233db46918b65]
Btrfs: kill BUG_ON in run_delayed_tree_ref
[02794222c4132ac003e7281fb71f4ec1645ffc87]
Btrfs: memset to avoid stale content in btree leaf
[851cd173f06045816528176001cf82948282029c]
Btrfs: memset to avoid stale content in btree node block
[3eb548ee3a8042d95ad81be254e67a5222c24e03]
Logan Gunthorpe (1):
chardev: add helper function to register char devs with a struct device
[233ed09d7fdacf592ee91e6c97ce5f4364fbe7c0]
Lu Fengqi (1):
btrfs: Remove redundant btrfs_release_path from btrfs_unlink_subvol
[5b7d687ad5913a56b6a8788435d7a53990b4176d]
Lukas Czerner (1):
ext4: wait for existing dio workers in ext4_alloc_file_blocks()
[0d306dcf86e8f065dff42a4a934ae9d99af35ba5]
Luuk Paulussen (1):
hwmon: (adt7475) Make volt2reg return same reg as reg2volt input
[cf3ca1877574a306c0207cbf7fdf25419d9229df]
Mao Wenan (2):
af_packet: set defaule value for tmo
[b43d1f9f7067c6759b1051e8ecb84e82cef569fe]
net: sonic: return NETDEV_TX_OK if failed to map buffer
[6e1cdedcf0362fed3aedfe051d46bd7ee2a85fe1]
Marcel Holtmann (2):
HID: hidraw: Fix returning EPOLLOUT from hidraw_poll
[9f3b61dc1dd7b81e99e7ed23776bb64a35f39e1a]
HID: uhid: Fix returning EPOLLOUT from uhid_char_poll
[be54e7461ffdc5809b67d2aeefc1ddc9a91470c7]
Mathias Nyman (2):
xhci: handle some XHCI_TRUST_TX_LENGTH quirks cases as default behaviour.
[7ff11162808cc2ec66353fc012c58bb449c892c3]
xhci: make sure interrupts are restored to correct state
[bd82873f23c9a6ad834348f8b83f3b6a5bca2c65]
Mauro Carvalho Chehab (3):
[media] media-device: dynamically allocate struct media_devnode
[a087ce704b802becbb4b0f2a20f2cb3f6911802e]
[media] media-devnode: fix namespace mess
[163f1e93e995048b894c5fc86a6034d16beed740]
[media] media-devnode: just return 0 instead of using a var
[8b37c6455fc8f43e0e95db2847284e618db6a4f8]
Max Kellermann (2):
[media] drivers/media/media-devnode: clear private_data before put_device()
[bf244f665d76d20312c80524689b32a752888838]
[media] media-devnode: add missing mutex lock in error handler
[88336e174645948da269e1812f138f727cd2896b]
Michael Straube (1):
staging: rtl8188eu: Add device code for TP-Link TL-WN727N v5.21
[58dcc5bf4030cab548d5c98cd4cd3632a5444d5a]
Michał Mirosław (1):
mmc: sdhci: fix minimum clock rate for v3 controller
[2a187d03352086e300daa2044051db00044cd171]
Mika Westerberg (4):
pinctrl: baytrail: Clear interrupt triggering from pins that are in GPIO mode
[95f0972c7e4cbf3fc68160131c5ac2f033481d00]
pinctrl: baytrail: Relax GPIO request rules
[f8323b6bb2cc7d26941d4838dd4375952980a88a]
pinctrl: baytrail: Rework interrupt handling
[31e4329f99062a06dca5a493bb4495a63b2dc6ba]
pinctrl: baytrail: Serialize all register access
[39ce8150a079e3ae6ed9abf26d7918a558ef7c19]
Mike Snitzer (1):
dm flakey: fix reads to be issued if drop_writes configured
[299f6230bc6d0ccd5f95bb0fb865d80a9c7d5ccc]
Mikulas Patocka (1):
block: fix an integer overflow in logical block size
[ad6bf88a6c19a39fb3b0045d78ea880325dfcf15]
Moni Shoua (1):
IB/mlx4: Avoid executing gid task when device is being removed
[4bf9715f184969dc703bde7be94919995024a6a9]
Nicolai Stange (2):
libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held
[c7bf1fb7ddca331780b9a733ae308737b39f1ad4]
libertas: make lbs_ibss_join_existing() return error code on rates overflow
[1754c4f60aaf1e17d886afefee97e94d7f27b4cb]
Nikos Tsironis (1):
dm thin metadata: Add support for a pre-commit callback
[ecda7c0280e6b3398459dc589b9a41c1adb45529]
Pablo Neira Ayuso (2):
netfilter: nf_tables: missing sanitization in data from userspace
[71df14b0ce094be46d105b5a3ededd83b8e779a0]
netfilter: nf_tables: validate NFT_DATA_VALUE after nft_data_init()
[0d2c96af797ba149e559c5875c0151384ab6dd14]
Paolo Bonzini (1):
KVM: nVMX: Don't emulate instructions in guest mode
[07721feee46b4b248402133228235318199b05ec]
Parav Pandit (1):
IB/mlx4: Follow mirror sequence of device add during device removal
[89f988d93c62384758b19323c886db917a80c371]
Paul Cercueil (1):
usb: musb: dma: Correct parameter passed to IRQ handler
[c80d0f4426c7fdc7efd6ae8d8b021dcfc89b4254]
Pavel Tatashin (1):
x86/pti/efi: broken conversion from efi to kernel page table
[not upstream; fixes a bug specific to KAISER]
Pengcheng Yang (1):
tcp: fix "old stuff" D-SACK causing SACK to be treated as D-SACK
[c9655008e7845bcfdaac10a1ed8554ec167aea88]
Pete Zaitcev (1):
usb: mon: Fix a deadlock in usbmon between mmap and read
[19e6317d24c25ee737c65d1ffb7483bdda4bb54a]
Peter Hurley (1):
tty: vt: Fix !TASK_RUNNING diagnostic warning from paste_selection()
[61e86cc90af49cecef9c54ccea1f572fbcb695ac]
Peter Zijlstra (1):
futex: Fix inode life-time issue
[8019ad13ef7f64be44d4f892af9c840179009254]
Qize Wang (1):
mwifiex: Fix heap overflow in mmwifiex_process_tdls_action_frame()
[1e58252e334dc3f3756f424a157d1b7484464c40]
Qu Wenruo (14):
btrfs: Add checker for EXTENT_CSUM
[4b865cab96fe2a30ed512cf667b354bd291b3b0a]
btrfs: Add sanity check for EXTENT_DATA when reading out leaf
[40c3c40947324d9f40bf47830c92c59a9bbadf4a]
btrfs: Check if item pointer overlaps with the item itself
[7f43d4affb2a254d421ab20b0cf65ac2569909fb]
btrfs: Check that each block group has corresponding chunk at mount time
[514c7dca85a0bf40be984dab0b477403a6db901f]
btrfs: Enhance chunk validation check
[f04b772bfc17f502703794f4d100d12155c1a1a9]
btrfs: Move leaf and node validation checker to tree-checker.c
[557ea5dd003d371536f6b4e8f7c8209a2b6fd4e3]
btrfs: Refactor check_leaf function for later expansion
[c3267bbaa9cae09b62960eafe33ad19196803285]
btrfs: Verify that every chunk has corresponding block group at mount time
[7ef49515fa6727cb4b6f2f5b0ffbc5fc20a9f8c6]
btrfs: tree-checker: Add checker for dir item
[ad7b0368f33cffe67fecd302028915926e50ef7e]
btrfs: tree-checker: Check level for leaves and nodes
[f556faa46eb4e96d0d0772e74ecf66781e132f72]
btrfs: tree-checker: Detect invalid and empty essential trees
[ba480dd4db9f1798541eb2d1c423fc95feee8d36]
btrfs: tree-checker: Enhance btrfs_check_node output
[bba4f29896c986c4cec17bc0f19f2ce644fceae1]
btrfs: tree-checker: Fix false panic for sanity test
[69fc6cbbac542c349b3d350d10f6e394c253c81d]
btrfs: tree-checker: Verify block_group_item
[fce466eab7ac6baa9d2dcd88abcf945be3d4a089]
Radoslaw Tyl (1):
ixgbevf: Remove limit of 10 entries for unicast filter list
[aa604651d523b1493988d0bf6710339f3ee60272]
Rafael J. Wysocki (1):
ACPI: PM: Avoid attaching ACPI PM domain to certain devices
[b9ea0bae260f6aae546db224daa6ac1bd9d94b91]
Randy Dunlap (1):
mm: mempolicy: require at least one nodeid for MPOL_PREFERRED
[aa9f7d5172fac9bf1f09e678c35e287a40a7b7dd]
Richard Palethorpe (2):
can, slip: Protect tty->disc_data in write_wakeup and close with RCU
[0ace17d56824165c7f4c68785d6b58971db954dd]
slcan: Don't transmit uninitialized stack data in padding
[b9258a2cece4ec1f020715fe3554bc2e360f6264]Russell King (2):
gpiolib: fix up emulated open drain outputs
[256efaea1fdc4e38970489197409a26125ee0aaa]
mod_devicetable: fix PHY module format
[d2ed49cf6c13e379c5819aa5ac20e1f9674ebc89]
Sabrina Dubroca (1):
net: ipv6_stub: use ip6_dst_lookup_flow instead of ip6_dst_lookup
[6c8991f41546c3c472503dff1ea9daaddf9331c2]
Salvatore Mesoraca (1):
namei: allow restricted O_CREAT of FIFOs and regular files
[30aba6656f61ed44cba445a3c0d38b296fa9e8f5]
Shaokun Zhang (1):
btrfs: tree-checker: Fix misleading group system information
[761333f2f50ccc887aa9957ae829300262c0d15b]
Shengjiu Wang (1):
ASoC: wm8962: fix lambda value
[556672d75ff486e0b6786056da624131679e0576]
Shuah Khan (3):
[media] media: Fix media_open() to clear filp->private_data in error leg
[d40ec6fdb0b03b7be4c7923a3da0e46bf943740a]
[media] media: fix media devnode ioctl/syscall and unregister race
[6f0dd24a084a17f9984dd49dffbf7055bf123993]
[media] media: fix use-after-free in cdev_put() when app exits after driver unbind
[5b28dde51d0ccc54cee70756e1800d70bed7114a]Steven Rostedt (1):
tracing: Have stack tracer compile when MCOUNT_INSN_SIZE is not defined
[b8299d362d0837ae39e87e9019ebe6b736e0f035]
Sudip Mukherjee (2):
tty: always relink the port
[273f632912f1b24b642ba5b7eb5022e43a72f3b5]
tty: link tty and port before configuring it as console
[fb2b90014d782d80d7ebf663e50f96d8c507a73c]
Suren Baghdasaryan (1):
staging: android: ashmem: Disallow ashmem memory from being remapped
[6d67b0290b4b84c477e6a2fc6e005e174d3c7786]
Suwan Kim (1):
usbip: Fix error path of vhci_recv_ret_submit()
[aabb5b833872524eaf28f52187e5987984982264]
Sven Eckelmann (1):
batman-adv: Fix DAT candidate selection on little endian systems
[4cc4a1708903f404d2ca0dfde30e71e052c6cbc9]
Takashi Iwai (4):
ALSA: hda/ca0132 - Avoid endless loop
[cb04fc3b6b076f67d228a0b7d096c69ad486c09c]
ALSA: ice1724: Fix sleep-in-atomic in Infrasonic Quartet support code
[0aec96f5897ac16ad9945f531b4bef9a2edd2ebd]
ALSA: pcm: Avoid possible info leaks from PCM stream buffers
[add9d56d7b3781532208afbff5509d7382fb6efe]
ALSA: seq: Fix racy access for queue timer in proc read
[60adcfde92fa40fcb2dbf7cc52f9b096e0cd109a]
Thomas Gleixner (1):
futex: Unbreak futex hashing
[8d67743653dce5a0e7aa500fcccb237cde7ad88e]
Tom Lendacky (1):
x86/microcode/AMD: Add support for fam17h microcode loading
[f4e9b7af0cd58dd039a0fb2cd67d57cea4889abf]
Vivek Goyal (1):
dm: do not override error code returned from dm_get_device()
[e80d1c805a3b2f0ad2081369be5dc5deedd5ee59]
Vladis Dronov (2):
ptp: fix the race between the release of ptp_clock and cdev
[a33121e5487b424339636b25c35d3a180eaa5f5e]
ptp: free ptp device pin descriptors properly
[75718584cb3c64e6269109d4d54f888ac5a5fd15]
Wang Shilong (1):
Btrfs: fix wrong max inline data size limit
[c01a5c074c0f6f85a3b02e39432b9e5576ab51de]
Wei Yongjun (1):
dm flakey: return -EINVAL on interval bounds error in flakey_ctr()
[bff7e067ee518f9ed7e1cbc63e4c9e01670d0b71]
Wen Huang (1):
libertas: Fix two buffer overflows at parsing bss descriptor
[e5e884b42639c74b5b57dc277909915c0aefc8bb]
Wen Yang (1):
ftrace: Avoid potential division by zero in function profiler
[e31f7939c1c27faa5d0e3f14519eaf7c89e8a69d]
Will Deacon (1):
chardev: Avoid potential use-after-free in 'chrdev_open()'
[68faa679b8be1a74e6663c21c3a9d25d32f1c079]
Xiang Chen (1):
scsi: sd: Clear sdkp->protection_type if disk is reformatted without PI
[465f4edaecc6c37f81349233e84d46246bcac11a]Xin Long (1):
sctp: free cmd->obj.chunk for the unprocessed SCTP_CMD_REPLY
[be7a7729207797476b6666f046d765bdf9630407]YueHaibing (1):
ptp: Fix pass zero to ERR_PTR() in ptp_clock_register
[aea0a897af9e44c258e8ab9296fad417f1bc063a]
Zhang Xiaoxu (1):
vgacon: Fix a UAF in vgacon_invert_region
[513dc792d6060d5ef572e43852683097a8420f56]
Documentation/sysctl/fs.txt | 36 ++ Makefile | 4 +- arch/powerpc/kernel/irq.c | 4 +- arch/x86/boot/compressed/head_64.S | 5 + arch/x86/include/asm/kaiser.h | 10 + arch/x86/kernel/cpu/microcode/amd.c | 4 + arch/x86/kvm/cpuid.c | 3 +- arch/x86/kvm/vmx.c | 2 +- arch/x86/realmode/init.c | 4 +- arch/x86/realmode/rm/trampoline_64.S | 3 +- block/blk-settings.c | 2 +- drivers/acpi/device_pm.c | 12 +- drivers/block/floppy.c | 7 +- drivers/gpio/gpiolib.c | 13 +- drivers/hid/hid-core.c | 6 + drivers/hid/hid-input.c | 16 +- drivers/hid/hidraw.c | 7 +- drivers/hid/uhid.c | 5 +- drivers/hwmon/adt7475.c | 5 +- drivers/iio/industrialio-buffer.c | 6 +- drivers/infiniband/hw/mlx4/main.c | 16 +- drivers/input/input.c | 26 +- drivers/input/misc/keyspan_remote.c | 9 +- drivers/input/tablet/aiptek.c | 6 +- drivers/input/tablet/gtco.c | 10 +- drivers/input/touchscreen/sur40.c | 2 +- drivers/isdn/gigaset/usb-gigaset.c | 23 +- drivers/md/dm-crypt.c | 4 +- drivers/md/dm-delay.c | 16 +- drivers/md/dm-flakey.c | 40 +- drivers/md/dm-linear.c | 7 +- drivers/md/dm-raid1.c | 8 +- drivers/md/dm-snap-persistent.c | 2 +- drivers/md/dm-stripe.c | 8 +- drivers/md/dm-thin-metadata.c | 29 + drivers/md/dm-thin-metadata.h | 7 + drivers/md/persistent-data/dm-btree-remove.c | 8 +- drivers/md/raid0.c | 2 +- drivers/media/media-device.c | 43 +- drivers/media/media-devnode.c | 171 +++--- drivers/media/usb/gspca/ov519.c | 10 + drivers/media/usb/gspca/stv06xx/stv06xx.c | 19 +- drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c | 4 + drivers/media/usb/gspca/xirlink_cit.c | 18 +- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/misc/enclosure.c | 3 +- drivers/mmc/host/sdhci.c | 10 +- drivers/net/bonding/bond_main.c | 40 +- drivers/net/can/mscan/mscan.c | 21 +- drivers/net/can/slcan.c | 16 +- drivers/net/can/usb/gs_usb.c | 4 +- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 5 - drivers/net/ethernet/natsemi/sonic.c | 113 +++- drivers/net/ethernet/natsemi/sonic.h | 25 +- drivers/net/ethernet/stmicro/stmmac/common.h | 5 +- drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +- drivers/net/hamradio/6pack.c | 4 +- drivers/net/hamradio/mkiss.c | 4 +- drivers/net/macvlan.c | 3 +- drivers/net/slip/slip.c | 12 +- drivers/net/usb/r8152.c | 3 + drivers/net/vxlan.c | 5 +- drivers/net/wireless/libertas/cfg.c | 18 +- drivers/net/wireless/mwifiex/sta_ioctl.c | 1 + drivers/net/wireless/mwifiex/tdls.c | 74 ++- drivers/pinctrl/pinctrl-baytrail.c | 212 ++++--- drivers/platform/x86/asus-wmi.c | 8 +- drivers/platform/x86/hp-wmi.c | 2 +- drivers/ptp/ptp_clock.c | 42 +- drivers/ptp/ptp_private.h | 9 +- drivers/ptp/ptp_sysfs.c | 162 +++--- drivers/scsi/fnic/vnic_dev.c | 20 +- drivers/scsi/qla4xxx/ql4_os.c | 1 - drivers/scsi/sd.c | 4 +- drivers/staging/android/ashmem.c | 28 + drivers/staging/rtl8188eu/os_dep/usb_intf.c | 3 +- drivers/staging/rtl8712/usb_intf.c | 2 +- drivers/staging/usbip/vhci_rx.c | 13 +- drivers/tty/serial/msm_serial.c | 13 +- drivers/tty/serial/serial_core.c | 1 + drivers/tty/vt/selection.c | 34 +- drivers/tty/vt/vt.c | 2 - drivers/usb/atm/ueagle-atm.c | 18 +- drivers/usb/core/config.c | 77 ++- drivers/usb/core/hub.c | 1 + drivers/usb/core/quirks.c | 37 ++ drivers/usb/core/urb.c | 1 + drivers/usb/core/usb.h | 3 + drivers/usb/dwc3/dwc3-pci.c | 30 + drivers/usb/host/ehci-q.c | 13 +- drivers/usb/host/xhci-hub.c | 8 +- drivers/usb/host/xhci-ring.c | 3 +- drivers/usb/misc/adutux.c | 2 +- drivers/usb/misc/idmouse.c | 2 +- drivers/usb/mon/mon_bin.c | 32 +- drivers/usb/musb/musbhsdma.c | 2 +- drivers/usb/serial/ch341.c | 6 +- drivers/usb/serial/io_edgeport.c | 26 +- drivers/usb/serial/keyspan.c | 4 + drivers/usb/serial/opticon.c | 2 +- drivers/usb/serial/quatech2.c | 6 + drivers/usb/serial/usb-serial-simple.c | 2 + drivers/usb/serial/usb-serial.c | 3 + drivers/vhost/net.c | 13 +- drivers/video/console/vgacon.c | 3 + drivers/virtio/virtio_balloon.c | 10 + firmware/Makefile | 2 +- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.c | 19 +- fs/btrfs/ctree.h | 157 +++--- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/disk-io.c | 80 +-- fs/btrfs/extent-tree.c | 110 +++- fs/btrfs/extent_io.c | 98 ++-- fs/btrfs/extent_io.h | 25 +- fs/btrfs/extent_map.c | 2 +- fs/btrfs/extent_map.h | 10 +- fs/btrfs/inode.c | 8 +- fs/btrfs/ioctl.c | 10 +- fs/btrfs/relocation.c | 1 + fs/btrfs/root-tree.c | 10 +- fs/btrfs/scrub.c | 2 +- fs/btrfs/struct-funcs.c | 9 +- fs/btrfs/tree-checker.c | 649 ++++++++++++++++++++++ fs/btrfs/tree-checker.h | 38 ++ fs/btrfs/tree-log.c | 24 +- fs/btrfs/uuid-tree.c | 2 + fs/btrfs/volumes.c | 206 +++++-- fs/btrfs/volumes.h | 2 + fs/char_dev.c | 88 ++- fs/ext4/dir.c | 5 + fs/ext4/ext4.h | 13 + fs/ext4/extents.c | 89 +-- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 117 +++- fs/ext4/super.c | 1 + fs/ext4/truncate.h | 2 + fs/inode.c | 1 + fs/locks.c | 2 +- fs/namei.c | 56 +- include/linux/blkdev.h | 10 +- include/linux/blktrace_api.h | 6 +- include/linux/cdev.h | 5 + include/linux/fs.h | 3 + include/linux/futex.h | 17 +- include/linux/if_ether.h | 8 + include/linux/kobject.h | 2 + include/linux/mod_devicetable.h | 4 +- include/linux/netfilter_arp/arp_tables.h | 2 +- include/linux/posix-clock.h | 19 +- include/linux/quotaops.h | 2 +- include/linux/usb/quirks.h | 3 + include/media/media-device.h | 5 +- include/media/media-devnode.h | 32 +- include/net/addrconf.h | 5 +- include/net/cfg80211.h | 11 + include/net/neighbour.h | 1 - kernel/futex.c | 93 ++-- kernel/sysctl.c | 18 + kernel/taskstats.c | 30 +- kernel/time/posix-clock.c | 31 +- kernel/trace/blktrace.c | 129 +++-- kernel/trace/ftrace.c | 6 +- kernel/trace/trace_sched_wakeup.c | 4 +- kernel/trace/trace_stack.c | 5 + lib/kobject.c | 5 +- mm/mempolicy.c | 6 +- net/8021q/vlan_netlink.c | 10 +- net/batman-adv/distributed-arp-table.c | 4 +- net/bridge/br_netfilter.c | 3 + net/bridge/netfilter/ebtables.c | 58 +- net/core/neighbour.c | 3 - net/ipv4/netfilter/arp_tables.c | 42 +- net/ipv4/netfilter/arptable_filter.c | 2 +- net/ipv4/tcp_input.c | 5 +- net/ipv4/tcp_output.c | 8 + net/ipv6/af_inet6.c | 2 +- net/mac80211/cfg.c | 55 +- net/mac80211/sta_info.c | 4 + net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_core.c | 3 +- net/netfilter/nf_conntrack_netlink.c | 3 + net/netfilter/nft_bitwise.c | 19 +- net/netfilter/nft_cmp.c | 18 +- net/packet/af_packet.c | 3 +- net/sched/ematch.c | 2 +- net/sched/sch_fq.c | 10 +- net/sctp/sm_sideeffect.c | 28 +- net/wireless/util.c | 45 ++ scripts/recordmcount.c | 17 + sound/core/pcm_native.c | 4 + sound/core/seq/seq_timer.c | 14 +- sound/pci/hda/patch_ca0132.c | 5 +- sound/pci/ice1712/ice1724.c | 9 +- sound/soc/codecs/wm8962.c | 4 +- sound/usb/pcm.c | 44 +- 197 files changed, 3378 insertions(+), 1230 deletions(-)
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
PATCH 246/247 futex: Fix inode life-time issue
3.16.83-rc2 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 8019ad13ef7f64be44d4f892af9c840179009254 upstream.
As reported by Jann, ihold() does not in fact guarantee inode persistence. And instead of making it so, replace the usage of inode pointers with a per boot, machine wide, unique inode identifier.
This sequence number is global, but shared (file backed) futexes are rare enough that this should not become a performance issue.
[bwh: Backported to 3.16: Use atomic64_cmpxchg() instead of the
_relaxed() variant which we don't have]
--- fs/inode.c | 1 + include/linux/fs.h | 1 + include/linux/futex.h | 17 +++++---- kernel/futex.c | 89 ++++++++++++++++++++++++++----------------- 4 files changed, 65 insertions(+), 43 deletions(-)
fs/inode.c +1 -0
@@ -131,6 +131,7 @@ int inode_init_always(struct super_block inode->i_sb = sb; inode->i_blkbits = sb->s_blocksize_bits; inode->i_flags =0 ; +atomic64_set (&inode->i_sequence,0 );atomic_set (&inode->i_count,1 ); inode->i_op = &empty_iops; inode->i_fop = &empty_fops;
include/linux/fs.h +1 -0
@@ -570,6 +570,7 @@ struct inode {struct rcu_head i_rcu; };u64 i_version; +atomic64_t i_sequence;/* see futex */ atomic_t i_count;atomic_t i_dio_count;atomic_t i_writecount;
include/linux/futex.h +10 -7
@@ -39,23 +39,26 @@ handle_futex_death(u32 __user *uaddr, stunion futex_key {struct { +u64 i_seq;unsigned long pgoff; -struct inode *inode; -int offset; +unsigned int offset; } shared;struct { +union { +struct mm_struct *mm; +u64 __tmp; + };unsigned long address; -struct mm_struct *mm; -int offset; +unsigned int offset; } private;struct { +u64 ptr;unsigned long word; -void *ptr; -int offset; +unsigned int offset; } both; }; -#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } } +#define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = 0ULL } }#ifdef CONFIG_FUTEX extern void exit_robust_list (struct task_struct *curr);
kernel/futex.c +53 -36
130 lines not on this page · raw message
Re: [PATCH 3.16 246/247] futex: Fix inode life-time issue
Quoted 7 lines · Ben Hutchings
3.16.83-rc2 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit
8019ad13ef7f64be44d4f892af9c840179009254upstream.
Please do not forget:
8d67743653dc ("futex: Unbreak futex hashing")
which fixes this fix.
Re: [PATCH 3.16 246/247] futex: Fix inode life-time issue
Quoted 7 lines · Peter Zijlstra
Quoted 6 lines · Ben Hutchings
3.16.83-rc2 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
Quoted 7 lines
Quoted 1 line
commit
8019ad13ef7f64be44d4f892af9c840179009254upstream.Please do not forget:
8d67743653dc("futex: Unbreak futex hashing")which fixes this fix.
I didn't, Jann reminded me to include both of them.
Ben.
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.
PATCH 247/247 futex: Unbreak futex hashing
In reply to Ben Hutchings3.16.83-rc2 review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
commit 8d67743653dce5a0e7aa500fcccb237cde7ad88e upstream.
The recent futex inode life time fix changed the ordering of the futex key union struct members, but forgot to adjust the hash function accordingly,
As a result the hashing omits the leading 64bit and even hashes beyond the futex key causing a bad hash distribution which led to a ~100% performance regression.
Hand in the futex key pointer instead of a random struct member and make the size calculation based of the struct offset.
--- kernel/futex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/futex.c +2 -2
@@ -309,9 +309,9 @@ static inline int hb_waiters_pending(str*/ static struct futex_hash_bucket *hash_futex (union futex_key *key) { -u32 hash =jhash2 ((u32 *)&key->both.word, - (sizeof (key->both.word)+sizeof (key->both.ptr))/4 , + u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4, key->both.offset); +return &futex_queues[hash & (futex_hashsize -1 )]; }
Re: [PATCH 3.16 000/247] 3.16.83-rc2 review
In reply to Ben HutchingsQuoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 247 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
For v3.16.82-247-gffbdbb4fe113:
Build results:
total: 135 pass: 135 fail: 0 Qemu test results: total: 233 pass: 233 fail: 0
Guenter
Re: [PATCH 3.16 000/247] 3.16.83-rc2 review
Quoted 10 lines · Guenter Roeck
Quoted 8 lines · Ben Hutchings
This is the start of the stable review cycle for the 3.16.83 release. There are 247 patches in this series, which will be posted as responses to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Tue Apr 28 18:00:00 UTC 2020. Anything received after that time might be too late.
Quoted 6 lines
For v3.16.82-247-gffbdbb4fe113:
Build results:
total: 135 pass: 135 fail: 0 Qemu test results: total: 233 pass: 233 fail: 0
Great, thanks for testing again.
Ben.
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.