3.16.60-rc1 review
Subsystems (6)
PATCH 4/366 drm/i915/cmdparser: Do not check past the cmd length.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michal Srb <[email protected]>
commit 3aec7f871c65eb5f76b4125fda432593c834a6f2 upstream.
The command MEDIA_VFE_STATE checks bits at offset +2 dwords. However, it is possible to have MEDIA_VFE_STATE command with length = 0 + LENGTH_BIAS = 2. In that case check_cmd will read bits from the following command, or even past the end of the buffer.
If the offset ends up outside of the command length, reject the command.
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/i915_cmd_parser.c +6 -0
@@ -941,6 +941,12 @@ static bool check_cmd(const struct intelcontinue ; } +if (desc->bits[i].offset >= length) { +DRM_DEBUG_DRIVER ("CMD: Rejected command 0x%08X, too short to check bitmask (ring=%d)\n" , + *cmd, ring->id); +return false; + } + dword = cmd[desc->bits[i].offset] & desc->bits[i].mask;
PATCH 7/366 regmap: Don't use format_val in regmap_bulk_read
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Charles Keepax <[email protected]>
commit 9ae27a8d1f3ebff09191fb8cb1341414547293b2 upstream.
A bulk read can be implemented either through regmap_raw_read, or by reading each register individually using regmap_read. Both regmap_read and regmap_bulk_read should return values in native endian. In the individual case the current implementation calls format_val to put the data into the output array, which can cause endian issues. The regmap_read will have already converted the data into native endian, if the hosts endian differs from the device then format_val will switch the endian back again.
Rather than using format_val simply use the code that is called if there is no format_val function. This code supports all cases except 24-bit but there don't appear to be any users of regmap_bulk_read for 24-bit. Additionally, it would have to be a big endian host for the old code to actually function correctly anyway.
[bwh: Backported to 3.16:
- 64-bit I/O is not supported
- Adjust context]
---
drivers/base/regmap/regmap.c +17 -26
@@ -2240,39 +2240,30 @@ int regmap_bulk_read(struct regmap *map,for (i =0 ; i < val_count * val_bytes; i += val_bytes) map->format.parse_inplace (val + i); }else { +u32 *u32 = val; +u16 *u16 = val; +u8 *u8 = val; +for (i =0 ; i < val_count; i++) {unsigned int ival; + ret =regmap_read (map, reg + (i * map->reg_stride), &ival);if (ret !=0 )return ret; -if (map->format.format_val) { - map->format.format_val (val + (i * val_bytes), ival,0 ); - }else { -/* Devices providing read and write -* operations can use the bulk I/O -* functions if they define a val_bytes, -* we assume that the values are native -* endian. -*/ -u32 *u32 = val; -u16 *u16 = val; -u8 *u8 = val; - -switch (map->format.val_bytes) { -case 4 : - u32[i] = ival; -break ; -case 2 : - u16[i] = ival; -break ; -case 1 : - u8[i] = ival; -break ; -default : -return -EINVAL ; - } +switch (map->format.val_bytes) { +case 4 : + u32[i] = ival; +break ; +case 2 : + u16[i] = ival; +break ; +case 1 : + u8[i] = ival; +break ; +default : +return -EINVAL ; } } }
PATCH 9/366 HID: i2c-hid: fix size check and type usage
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Aaron Ma <[email protected]>
commit ac75a041048b8c1f7418e27621ca5efda8571043 upstream.
When convert char array with signed int, if the inbuf[x] is negative then upper bits will be set to 1. Fix this by using u8 instead of char.
ret_size has to be at least 3, hid_input_report use it after minus 2 bytes.
--- drivers/hid/i2c-hid/i2c-hid.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/hid/i2c-hid/i2c-hid.c +7 -6
@@ -136,10 +136,10 @@ struct i2c_hid {* register of the HID * descriptor. */ unsigned int bufsize;/* i2c buffer size */ -char *inbuf;/* Input buffer */ -char *rawbuf;/* Raw Input buffer */ -char *cmdbuf;/* Command buffer */ -char *argsbuf;/* Command arguments buffer */ +u8 *inbuf;/* Input buffer */ +u8 *rawbuf;/* Raw Input buffer */ +u8 *cmdbuf;/* Command buffer */ +u8 *argsbuf;/* Command arguments buffer */ unsigned long flags;/* device flags */
@@ -373,7 +373,8 @@ static int i2c_hid_hwreset(struct i2c_clstatic void i2c_hid_get_input (struct i2c_hid *ihid) { -int ret, ret_size; +int ret; +u32 ret_size;int size =le16_to_cpu (ihid->hdesc.wMaxInputLength);if (size > ihid->bufsize)
@@ -398,7 +399,7 @@ static void i2c_hid_get_input(struct i2creturn ; } -if (ret_size > size) { +if ((ret_size > size) || (ret_size <=2 )) {dev_err (&ihid->client->dev,"%s: incomplete report (%d/%d)\n" , __func__, size, ret_size);return ;
PATCH 13/366 jbd2: if the journal is aborted then don't allow update of the log tail
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Theodore Ts'o <[email protected]>
commit 85e0c4e89c1b864e763c4e3bb15d0b6d501ad5d9 upstream.
This updates the jbd2 superblock unnecessarily, and on an abort we shouldn't truncate the log.
--- fs/jbd2/journal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/jbd2/journal.c +4 -1
@@ -923,7 +923,7 @@ out: }/* -* This is a variaon of __jbd2_update_log_tail which checks for validity of +* This is a variation of __jbd2_update_log_tail which checks for validity of * provided log tail and locks j_checkpoint_mutex. So it is safe against races * with other threads updating log tail. */
@@ -1399,6 +1399,9 @@ int jbd2_journal_update_sb_log_tail(jourjournal_superblock_t *sb = journal->j_superblock;int ret; +if (is_journal_aborted (journal)) +return -EIO ; +BUG_ON (!mutex_is_locked (&journal->j_checkpoint_mutex));jbd_debug (1 ,"JBD2: updating superblock (start %lu, seq %u)\n" , tail_block, tail_tid);
PATCH 14/366 um: Use POSIX ucontext_t instead of struct ucontext
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Mazur <[email protected]>
commit 4d1a535b8ec5e74b42dfd9dc809142653b2597f6 upstream.
glibc 2.26 removed the 'struct ucontext' to "improve" POSIX compliance and break programs, including User Mode Linux. Fix User Mode Linux by using POSIX ucontext_t.
This fixes:
arch/um/os-Linux/signal.c: In function 'hard_handler':arch/um/os-Linux/signal.c:163:22: error: dereferencing pointer to incomplete type 'struct ucontext'
mcontext_t *mc = &uc->uc_mcontext;arch/x86/um/stub_segv.c: In function 'stub_segv_handler':arch/x86/um/stub_segv.c:16:13: error: dereferencing pointer to incomplete type 'struct ucontext'
&uc->uc_mcontext);
--- arch/um/os-Linux/signal.c | 2 +- arch/x86/um/stub_segv.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/um/os-Linux/signal.c +1 -1
@@ -135,7 +135,7 @@ static void (*handlers[_NSIG])(int sig,static void hard_handler (int sig,siginfo_t *si,void *p) { -struct ucontext *uc = p; +ucontext_t *uc = p;mcontext_t *mc = &uc->uc_mcontext;unsigned long pending =1UL << sig;
arch/x86/um/stub_segv.c +1 -1
@@ -10,7 +10,7 @@void __attribute__ ((__section__ (".__syscall_stub" )))stub_segv_handler (int sig,siginfo_t *info,void *p) { -struct ucontext *uc = p; +ucontext_t *uc = p;GET_FAULTINFO_FROM_MC (*((struct faultinfo *)STUB_DATA ), &uc->uc_mcontext);
PATCH 19/366 serial: fsl_lpuart: Fix out-of-bounds access through DT alias
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
commit ffab87fdecc655cc676f8be8dd1a2c5e22bd6d47 upstream.
The lpuart_ports[] array is indexed using a value derived from the "serialN" alias in DT, which may lead to an out-of-bounds access.
Fix this by adding a range check.
--- drivers/tty/serial/fsl_lpuart.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/serial/fsl_lpuart.c +4 -0
@@ -1170,6 +1170,10 @@ static int lpuart_probe(struct platform_dev_err (&pdev->dev,"failed to get alias id, errno %d\n" , ret);return ret; } +if (ret >=ARRAY_SIZE (lpuart_ports)) { +dev_err (&pdev->dev,"serial%d out of range\n" , ret); +return -EINVAL ; + } sport->port.line = ret; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
PATCH 29/366 net: core: dst: Add kernel-doc for 'net' parameter
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jonathan Neuschäfer <[email protected]>
commit 8eb1a8590f5ca114fabf16ebb26a4bce0255ace9 upstream.
This fixes the following kernel-doc warning:
./include/net/dst.h:366: warning: Function parameter or member 'net' not described in 'skb_tunnel_rx'
--- include/net/dst.h | 1 + 1 file changed, 1 insertion(+)
include/net/dst.h +1 -0
@@ -350,6 +350,7 @@ static inline void __skb_tunnel_rx(struc* skb_tunnel_rx - prepare skb for rx reinsert * @skb: buffer * @dev: tunnel device +* @net: netns for packet i/o * * After decapsulation, packet is going to re-enter (netif_rx()) our stack, * so make some cleanups, and perform accounting.
PATCH 36/366 thermal: imx: register irq handler later in probe
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bai Ping <[email protected]>
commit 84866ee5818e95f6e97194656777c10ac24cb9d3 upstream.
The irq handler should be registered after the tempmon module has been initialized in a known state and the thermal_zone and cpu_cooling device have been registered successfully. Otherwise, if the irq is triggled earlier before thermal probe has been finished, it may lead to 'NULL' pointer kernel panic.
--- drivers/thermal/imx_thermal.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/thermal/imx_thermal.c +11 -8
@@ -422,14 +422,6 @@ static int imx_thermal_probe(struct platif (data->irq <0 )return data->irq; - ret =devm_request_threaded_irq (&pdev->dev, data->irq, - imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, -0 ,"imx_thermal" , data); -if (ret <0 ) { -dev_err (&pdev->dev,"failed to request alarm irq: %d\n" , ret); -return ret; - } -platform_set_drvdata (pdev, data); ret =imx_get_sensor_data (pdev);
@@ -492,6 +484,17 @@ static int imx_thermal_probe(struct platregmap_write (map,TEMPSENSE0 +REG_CLR ,TEMPSENSE0_POWER_DOWN );regmap_write (map,TEMPSENSE0 +REG_SET ,TEMPSENSE0_MEASURE_TEMP ); + ret =devm_request_threaded_irq (&pdev->dev, data->irq, + imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, +0 ,"imx_thermal" , data); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to request alarm irq: %d\n" , ret); +clk_disable_unprepare (data->thermal_clk); +thermal_zone_device_unregister (data->tz); +cpufreq_cooling_unregister (data->cdev); +return ret; + } + data->irq_enabled = true; data->mode =THERMAL_DEVICE_ENABLED ;
PATCH 38/366 parport_pc: Add support for WCH CH382L PCI-E single parallel port card.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Gerasiov <[email protected]>
commit 823f7923833c6cc2b16e601546d607dcfb368004 upstream.
WCH CH382L is a PCI-E adapter with 1 parallel port. It is similair to CH382 but serial ports are not soldered on board. Detected as
Serial controller: Device 1c00:3050 (rev 10) (prog-if 05 [16850])
--- drivers/parport/parport_pc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/parport/parport_pc.c +4 -0
@@ -2616,6 +2616,7 @@ enum parport_pc_pci_cards { netmos_9901, netmos_9865, quatech_sppxp100, + wch_ch382l, };
@@ -2678,6 +2679,7 @@ static struct parport_pc_pci { /* netmos_9901 */ { 1, { { 0, -1 }, } }, /* netmos_9865 */ { 1, { { 0, -1 }, } }, /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, + /* wch_ch382l */ { 1, { { 2, -1 }, } }, }; static const struct pci_device_id parport_pc_pci_tbl[] = {
@@ -2767,6 +2769,8 @@ static const struct pci_device_id parpor/* Quatech SPPXP-100 Parallel port PCI ExpressCard */ {PCI_VENDOR_ID_QUATECH ,PCI_DEVICE_ID_QUATECH_SPPXP_100 , PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, +/* WCH CH382L PCI-E single parallel port card */ + { 0x1c00, 0x3050, 0x1c00, 0x3050, 0, 0, wch_ch382l }, { 0, } /* terminate list */ };MODULE_DEVICE_TABLE (pci, parport_pc_pci_tbl);
PATCH 46/366 USB: serial: ftdi_sio: add RT Systems VX-8 cable
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Major Hayden <[email protected]>
commit 9608e5c0f079390473b484ef92334dfd3431bb89 upstream.
This patch adds a device ID for the RT Systems cable used to program Yaesu VX-8R/VX-8DR handheld radios. It uses the main FTDI VID instead of the common RT Systems VID.
--- drivers/usb/serial/ftdi_sio.c | 1 + drivers/usb/serial/ftdi_sio_ids.h | 3 +++ 2 files changed, 4 insertions(+)
drivers/usb/serial/ftdi_sio.c +1 -0
@@ -786,6 +786,7 @@ static const struct usb_device_id id_tab .driver_info = (kernel_ulong_t)&ftdi_NDI_device_quirk }, { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, { USB_DEVICE(NOVITUS_VID, NOVITUS_BONO_E_PID) }, + { USB_DEVICE(FTDI_VID, RTSYSTEMS_USB_VX8_PID) }, { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_USB_S03_PID) }, { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_USB_59_PID) }, { USB_DEVICE(RTSYSTEMS_VID, RTSYSTEMS_USB_57A_PID) },
drivers/usb/serial/ftdi_sio_ids.h +3 -0
@@ -922,6 +922,9 @@/* * RT Systems programming cables for various ham radios */ +/* This device uses the VID of FTDI */ +#define RTSYSTEMS_USB_VX8_PID 0x9e50/* USB-VX8 USB to 7 pin modular plug for Yaesu VX-8 radio */ +#define RTSYSTEMS_VID 0x2100/* Vendor ID */ #define RTSYSTEMS_USB_S03_PID 0x9001/* RTS-03 USB to Serial Adapter */ #define RTSYSTEMS_USB_59_PID 0x9e50/* USB-59 USB to 8 pin plug */
PATCH 47/366 USB: serial: cp210x: add ELDAT Easywave RX09 id
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 1f1e82f74c0947e40144688c9e36abe4b3999f49 upstream.
Add device id for ELDAT Easywave RX09 tranceiver.
--- drivers/usb/serial/cp210x.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/serial/cp210x.c +1 -0
@@ -151,6 +151,7 @@ static const struct usb_device_id id_tab { USB_DEVICE(0x12B8, 0xEC62) }, /* Link G4+ ECU */ { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */ + { USB_DEVICE(0x155A, 0x1006) }, /* ELDAT Easywave RX09 */ { USB_DEVICE(0x166A, 0x0201) }, /* Clipsal 5500PACA C-Bus Pascal Automation Controller */ { USB_DEVICE(0x166A, 0x0301) }, /* Clipsal 5800PC C-Bus Wireless PC Interface */ { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
PATCH 63/366 ipc,shm: move BUG_ON check into shm_lock
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Davidlohr Bueso <[email protected]>
commit c5c8975b2eb4eb7604e8ce4f762987f56d2a96a2 upstream.
Upon every shm_lock call, we BUG_ON if an error was returned, indicating racing either in idr or in shm_destroy. Move this logic into the locking.
--- ipc/shm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
ipc/shm.c +5 -5
@@ -155,8 +155,11 @@ static inline struct shmid_kernel *shm_l {struct kern_ipc_perm *ipcp =ipc_lock (&shm_ids (ns), id); -if (IS_ERR (ipcp)) -return (struct shmid_kernel *)ipcp; +/* +* We raced in the idr lookup or with shm_destroy(). Either way, the +* ID is busted. +*/ +BUG_ON (IS_ERR (ipcp)); return container_of(ipcp, struct shmid_kernel, shm_perm); }
@@ -190,7 +193,6 @@ static void shm_open(struct vm_area_strustruct shmid_kernel *shp; shp =shm_lock (sfd->ns, sfd->id); -BUG_ON (IS_ERR (shp)); shp->shm_atim =get_seconds (); shp->shm_lprid =task_tgid_vnr (current); shp->shm_nattch++;
@@ -256,7 +258,6 @@ static void shm_close(struct vm_area_strdown_write (&shm_ids (ns).rwsem);/* remove from the list of attaches of the shm segment */ shp =shm_lock (ns, sfd->id); -BUG_ON (IS_ERR (shp)); shp->shm_lprid =task_tgid_vnr (current); shp->shm_dtim =get_seconds (); shp->shm_nattch--;
@@ -1199,7 +1200,6 @@ out_fput: out_nattch:down_write (&shm_ids (ns).rwsem); shp =shm_lock (ns, shmid); -BUG_ON (IS_ERR (shp)); shp->shm_nattch--;if (shm_may_destroy (ns, shp))shm_destroy (ns, shp);
PATCH 67/366 ipc/shm: Fix shmctl(..., IPC_STAT, ...) between pid namespaces.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <[email protected]>
commit 98f929b1bd4d0b7c7a77d0d9776d1b924db2e454 upstream.
Today shm_cpid and shm_lpid are remembered in the pid namespace of the creator and the processes that last touched a sysvipc shared memory
segment. If you have processes in multiple pid namespaces that
is just wrong, and I don't know how this has been over-looked for so long.
As only creation and shared memory attach and shared memory detach update the pids I do not expect there to be a repeat of the issues when struct pid was attached to each af_unix skb, which in some notable cases cut the performance in half. The problem was threads of the same process updating same struct pid from different cpus causing the cache line to be highly contended and bounce between cpus.
As creation, attach, and detach are expected to be rare operations for sysvipc shared memory segments I do not expect that kind of cache line ping pong to cause probems. In addition because the pid is at a fixed location in the structure instead of being dynamic on a skb, the reference count of the pid does not need to be updated on each operation if the pid is the same. This ability to simply skip the pid reference count changes if the pid is unchanging further reduces the likelihood of the a cache line holding a pid reference count ping-ponging between cpus.
---
include/linux/shm.h +2 -2
@@ -14,8 +14,8 @@ struct shmid_kernel /* private to the ketime_t shm_atim;time_t shm_dtim;time_t shm_ctim; -pid_t shm_cprid; -pid_t shm_lprid; +struct pid *shm_cprid; +struct pid *shm_lprid;struct user_struct *mlock_user;/* The task created the shm object. NULL if the task is dead. */
ipc/shm.c +13 -8
@@ -198,7 +198,7 @@ static int __shm_open(struct vm_area_strreturn PTR_ERR (shp); shp->shm_atim =get_seconds (); - shp->shm_lprid =task_tgid_vnr (current); +ipc_update_pid (&shp->shm_lprid,task_tgid (current)); shp->shm_nattch++;shm_unlock (shp);return 0 ;
@@ -238,6 +238,8 @@ static void shm_destroy(struct ipc_nameselse if (shp->mlock_user)user_shm_unlock (file_inode (shm_file)->i_size, shp->mlock_user);fput (shm_file); +ipc_update_pid (&shp->shm_cprid,NULL ); +ipc_update_pid (&shp->shm_lprid,NULL );ipc_rcu_putref (shp, shm_rcu_free); }
@@ -282,7 +284,7 @@ static void shm_close(struct vm_area_strif (WARN_ON_ONCE (IS_ERR (shp))) goto done;/* no-op */ - shp->shm_lprid =task_tgid_vnr (current); +ipc_update_pid (&shp->shm_lprid,task_tgid (current)); shp->shm_dtim =get_seconds (); shp->shm_nattch--;if (shm_may_destroy (ns, shp))
@@ -581,8 +583,8 @@ static int newseg(struct ipc_namespace *if (IS_ERR (file)) goto no_file; - shp->shm_cprid =task_tgid_vnr (current); - shp->shm_lprid =0 ; + shp->shm_cprid =get_pid (task_tgid (current)); + shp->shm_lprid =NULL ; shp->shm_atim = shp->shm_dtim =0 ; shp->shm_ctim =get_seconds (); shp->shm_segsz = size;
@@ -614,6 +616,8 @@ no_id:user_shm_unlock (size, shp->mlock_user);fput (file); no_file: +ipc_update_pid (&shp->shm_cprid,NULL ); +ipc_update_pid (&shp->shm_lprid,NULL );ipc_rcu_putref (shp, shm_rcu_free);return error; }
@@ -952,8 +956,8 @@ static int shmctl_nolock(struct ipc_name tbuf.shm_atime = shp->shm_atim; tbuf.shm_dtime = shp->shm_dtim; tbuf.shm_ctime = shp->shm_ctim; - tbuf.shm_cpid = shp->shm_cprid; - tbuf.shm_lpid = shp->shm_lprid; + tbuf.shm_cpid =pid_vnr (shp->shm_cprid); + tbuf.shm_lpid =pid_vnr (shp->shm_lprid); tbuf.shm_nattch = shp->shm_nattch;rcu_read_unlock ();
@@ -1363,6 +1367,7 @@ SYSCALL_DEFINE1(shmdt, char __user *, sh#ifdef CONFIG_PROC_FS static int sysvipc_shm_proc_show (struct seq_file *s,void *it) { +struct pid_namespace *pid_ns =ipc_seq_pid_ns (s);struct user_namespace *user_ns =seq_user_ns (s);struct shmid_kernel *shp = it;unsigned long rss =0 , swp =0 ;
@@ -1383,8 +1388,8 @@ static int sysvipc_shm_proc_show(struct shp->shm_perm.id, shp->shm_perm.mode, shp->shm_segsz, - shp->shm_cprid, - shp->shm_lprid, +pid_nr_ns (shp->shm_cprid, pid_ns), +pid_nr_ns (shp->shm_lprid, pid_ns), shp->shm_nattch,from_kuid_munged (user_ns, shp->shm_perm.uid), from_kgid_munged(user_ns, shp->shm_perm.gid),
PATCH 68/366 ipc/shm: fix use-after-free of shm file via remap_file_pages()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 3f05317d9889ab75c7190dcd39491d2a97921984 upstream.
syzbot reported a use-after-free of shm_file_data(file)->file->f_op in shm_get_unmapped_area(), called via sys_remap_file_pages().
Unfortunately it couldn't generate a reproducer, but I found a bug which I think caused it. When remap_file_pages() is passed a full System V shared memory segment, the memory is first unmapped, then a new map is created using the ->vm_file. Between these steps, the shm ID can be removed and reused for a new shm segment. But, shm_mmap() only checks whether the ID is currently valid before calling the underlying file's ->mmap(); it doesn't check whether it was reused. Thus it can use the wrong underlying file, one that was already freed.
Fix this by making the "outer" shm file (the one that gets put in ->vm_file) hold a reference to the real shm file, and by making __shm_open() require that the file associated with the shm ID matches the one associated with the "outer" file.
Taking the reference to the real shm file is needed to fully solve the problem, since otherwise sfd->file could point to a freed file, which then could be reallocated for the reused shm ID, causing the wrong shm segment to be mapped (and without the required permission checks).
Commit 1ac0b6dec656 ("ipc/shm: handle removed segments gracefully in shm_mmap()") almost fixed this bug, but it didn't go far enough because it didn't consider the case where the shm ID is reused.
The following program usually reproduces this bug:
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int is_parent = (fork() != 0);
srand(getpid());
for (;;) {
int id = shmget(0xF00F, 4096, IPC_CREAT|0700);
if (is_parent) {
void *addr = shmat(id, NULL, 0);
usleep(rand() % 50);
while (!syscall(__NR_remap_file_pages, addr, 4096, 0, 0, 0));
} else {
usleep(rand() % 50);
shmctl(id, IPC_RMID, NULL);
}
}
}It causes the following NULL pointer dereference due to a 'struct file' being used while it's being freed. (I couldn't actually get a KASAN use-after-free splat like in the syzbot report. But I think it's possible with this bug; it would just take a more extraordinary race...)
BUG: unable to handle kernel NULL pointer dereference at 0000000000000058 PGD 0 P4D 0 Oops: 0000 [#1] SMP NOPTI CPU: 9 PID: 258 Comm: syz_ipc Not tainted 4.16.0-05140-gf8cf2f16a7c95 #189 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014 RIP: 0010:d_inode include/linux/dcache.h:519 [inline] RIP: 0010:touch_atime+0x25/0xd0 fs/inode.c:1724 [...] Call Trace: file_accessed include/linux/fs.h:2063 [inline] shmem_mmap+0x25/0x40 mm/shmem.c:2149 call_mmap include/linux/fs.h:1789 [inline] shm_mmap+0x34/0x80 ipc/shm.c:465 call_mmap include/linux/fs.h:1789 [inline] mmap_region+0x309/0x5b0 mm/mmap.c:1712 do_mmap+0x294/0x4a0 mm/mmap.c:1483 do_mmap_pgoff include/linux/mm.h:2235 [inline] SYSC_remap_file_pages mm/mmap.c:2853 [inline] SyS_remap_file_pages+0x232/0x310 mm/mmap.c:2769 do_syscall_64+0x64/0x1a0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7
--- ipc/shm.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
ipc/shm.c +20 -3
@@ -197,6 +197,12 @@ static int __shm_open(struct vm_area_strif (IS_ERR (shp))return PTR_ERR (shp); +if (shp->shm_file != sfd->file) { +/* ID was reused */ +shm_unlock (shp); +return -EINVAL ; + } + shp->shm_atim =get_seconds ();ipc_update_pid (&shp->shm_lprid,task_tgid (current)); shp->shm_nattch++;
@@ -413,8 +419,9 @@ static int shm_mmap(struct file *file, sint ret;/* -* In case of remap_file_pages() emulation, the file can represent -* removed IPC ID: propogate shm_lock() error to caller. +* In case of remap_file_pages() emulation, the file can represent an +* IPC ID that was removed, and possibly even reused by another shm +* segment already. Propagate this case as an error to caller. */ ret =__shm_open (vma);if (ret)
@@ -438,6 +445,7 @@ static int shm_release(struct inode *inostruct shm_file_data *sfd =shm_file_data (file);put_ipc_ns (sfd->ns); +fput (sfd->file);shm_file_data (file) =NULL ;kfree (sfd);return 0 ;
@@ -1197,7 +1205,16 @@ long do_shmat(int shmid, char __user *sh file->f_mapping = shp->shm_file->f_mapping; sfd->id = shp->shm_perm.id; sfd->ns =get_ipc_ns (ns); - sfd->file = shp->shm_file; +/* +* We need to take a reference to the real shm file to prevent the +* pointer from becoming stale in cases where the lifetime of the outer +* file extends beyond that of the shm segment. It's not usually +* possible, but it can happen during remap_file_pages() emulation as +* that unmaps the memory, then does ->mmap() via file reference only. +* We'll deny the ->mmap() if the shm segment was since removed, but to +* detect shm ID reuse we need to compare the file pointers. +*/ + sfd->file =get_file (shp->shm_file); sfd->vm_ops =NULL ; err =security_mmap_file (file, prot, flags);
PATCH 74/366 iio:buffer: make length types match kfifo types
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Martin Kelly <[email protected]>
commit c043ec1ca5baae63726aae32abbe003192bc6eec upstream.
Currently, we use int for buffer length and bytes_per_datum. However, kfifo uses unsigned int for length and size_t for element size. We need to make sure these matches or we will have bugs related to overflow (in the range between INT_MAX and UINT_MAX for length, for example).
In addition, set_bytes_per_datum uses size_t while bytes_per_datum is an int, which would cause bugs for large values of bytes_per_datum.
Change buffer length to use unsigned int and bytes_per_datum to use size_t.
[bwh: Backported to 3.16:
- Drop change in iio_dma_buffer_set_length()
- Adjust filenames, context]
---
drivers/iio/kfifo_buf.c +2 -2
@@ -19,7 +19,7 @@ struct iio_kfifo {#define iio_to_kfifo (r) container_of(r, struct iio_kfifo, buffer)static inline int __iio_allocate_kfifo (struct iio_kfifo *buf, -int bytes_per_datum,int length) +size_t bytes_per_datum,unsigned int length) {if ((length ==0 ) || (bytes_per_datum ==0 ))return -EINVAL ;
@@ -87,7 +87,7 @@ static int iio_set_bytes_per_datum_kfiforeturn 0 ; } -static int iio_set_length_kfifo (struct iio_buffer *r,int length) +static int iio_set_length_kfifo (struct iio_buffer *r,unsigned int length) {/* Avoid an invalid state */ if (length <2 )
include/linux/iio/buffer.h +3 -3
@@ -52,7 +52,7 @@ struct iio_buffer_access_funcs {int (*get_bytes_per_datum)(struct iio_buffer *buffer);int (*set_bytes_per_datum)(struct iio_buffer *buffer,size_t bpd);int (*get_length)(struct iio_buffer *buffer); -int (*set_length)(struct iio_buffer *buffer,int length); +int (*set_length)(struct iio_buffer *buffer,unsigned int length);void (*release)(struct iio_buffer *buffer); };
@@ -78,8 +78,8 @@ struct iio_buffer_access_funcs {* @ref: [INTERN] reference count of the buffer. */ struct iio_buffer { -int length; -int bytes_per_datum; +unsigned int length; +size_t bytes_per_datum;struct attribute_group *scan_el_attrs;long *scan_mask;bool scan_timestamp;
PATCH 79/366 crypto: ahash - Fix early termination in hash walk
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
commit 900a081f6912a8985dc15380ec912752cb66025a upstream.
When we have an unaligned SG list entry where there is no leftover aligned data, the hash walk code will incorrectly return zero as if the entire SG list has been processed.
This patch fixes it by moving onto the next page instead.
--- crypto/ahash.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
crypto/ahash.c +4 -3
@@ -90,13 +90,14 @@ int crypto_hash_walk_done(struct crypto_if (nbytes && walk->offset & alignmask && !err) { walk->offset =ALIGN (walk->offset, alignmask +1 ); - walk->data += walk->offset; - nbytes =min (nbytes, ((unsigned int )(PAGE_SIZE )) - walk->offset); walk->entrylen -= nbytes; -return nbytes; +if (nbytes) { + walk->data += walk->offset; +return nbytes; + } }if (walk->flags &CRYPTO_ALG_ASYNC )
PATCH 84/366 btrfs: tests/qgroup: Fix wrong tree backref level
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 3c0efdf03b2d127f0e40e30db4e7aa0429b1b79a upstream.
The extent tree of the test fs is like the following:
BTRFS info (device (null)): leaf 16327509003777336587 total ptrs 1 free space 3919
item 0 key (4096 168 4096) itemoff 3944 itemsize 51
extent refs 1 gen 1 flags 2
tree block key (68719476736 0 0) level 1
^^^^^^^
ref#0: tree block backref root 5
And it's using an empty tree for fs tree, so there is no way that its level can be 1.
For REAL (created by mkfs) fs tree backref with no skinny metadata, the result should look like:
item 3 key (30408704 EXTENT_ITEM 4096) itemoff 3845 itemsize 51
refs 1 gen 4 flags TREE_BLOCK
tree block key (256 INODE_ITEM 0) level 0
^^^^^^^
tree block backref root 5
Fix the level to 0, so it won't break later tree level checker.
--- fs/btrfs/tests/qgroup-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tests/qgroup-tests.c +1 -1
@@ -69,7 +69,7 @@ static int insert_normal_tree_ref(structbtrfs_set_extent_generation (leaf, item,1 );btrfs_set_extent_flags (leaf, item,BTRFS_EXTENT_FLAG_TREE_BLOCK ); block_info = (struct btrfs_tree_block_info *)(item +1 ); -btrfs_set_tree_block_level (leaf, block_info,1 ); +btrfs_set_tree_block_level (leaf, block_info,0 ); iref = (struct btrfs_extent_inline_ref *)(block_info +1 );if (parent >0 ) { btrfs_set_extent_inline_ref_type(leaf, iref,
PATCH 85/366 ext4: correctly detect when an xattr value has an invalid size
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit d7614cc16146e3f0b4c33e71875c19607602aed5 upstream.
It was possible for an xattr value to have a very large size, which would then pass validation on 32-bit architectures due to a pointer wraparound. Fix this by validating the size in a way which avoids pointer wraparound.
It was also possible that a value's size would fit in the available space but its padded size would not. This would cause an out-of-bounds memory write in ext4_xattr_set_entry when replacing the xattr value. For example, if an xattr value of unpadded size 253 bytes went until the very end of the inode or block, then using setxattr(2) to replace this xattr's value with 256 bytes would cause a write to the 3 bytes past the end of the inode or buffer, and the new xattr value would be incorrectly truncated. Fix this by requiring that the padded size fit in the available space rather than the unpadded size.
This patch shouldn't have any noticeable effect on non-corrupted/non-malicious filesystems.
[bwh: Backported to 3.16:
- s/EFSCORRUPTED/EIO/
- Adjust context]
--- fs/ext4/xattr.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
fs/ext4/xattr.c +21 -6
@@ -188,6 +188,7 @@ ext4_xattr_check_names(struct ext4_xattr {struct ext4_xattr_entry *e = entry; +/* Find the end of the names list */ while (!IS_LAST_ENTRY (e)) {struct ext4_xattr_entry *next =EXT4_XATTR_NEXT (e);if ((void *)next >= end)
@@ -195,13 +196,27 @@ ext4_xattr_check_names(struct ext4_xattr e = next; } +/* Check the values */ while (!IS_LAST_ENTRY (entry)) { -if (entry->e_value_size !=0 && - (value_start +le16_to_cpu (entry->e_value_offs) < - (void *)e +sizeof (__u32) || - value_start +le16_to_cpu (entry->e_value_offs) + -le32_to_cpu (entry->e_value_size) > end)) -return -EIO ; +if (entry->e_value_size !=0 ) { +u16 offs =le16_to_cpu (entry->e_value_offs); +u32 size =le32_to_cpu (entry->e_value_size); +void *value; + +/* +* The value cannot overlap the names, and the value +* with padding cannot extend beyond 'end'. Check both +* the padded and unpadded sizes, since the size may +* overflow to 0 when adding padding. +*/ +if (offs > end - value_start) +return -EIO ; + value = value_start + offs; +if (value < (void *)e +sizeof (u32) || + size > end - value || +EXT4_XATTR_SIZE (size) > end - value) +return -EIO ; + } entry =EXT4_XATTR_NEXT (entry); }
PATCH 88/366 sky2: Increase D3 delay to sky2 stops working after suspend
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit afb133637071be6deeb8b3d0e55593ffbf63c527 upstream.
The sky2 ethernet stops working after system resume from suspend:
[ 582.852065] sky2 0000:04:00.0: Refused to change power state, currently in D3
The current 150ms delay is not enough, change it to 200ms can solve the issue.
--- drivers/net/ethernet/marvell/sky2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/sky2.c +1 -1
@@ -5070,7 +5070,7 @@ static int sky2_probe(struct pci_dev *pdINIT_WORK (&hw->restart_work, sky2_restart);pci_set_drvdata (pdev, hw); - pdev->d3_delay =150 ; + pdev->d3_delay =200 ;return 0 ;
PATCH 90/366 ext4: force revalidation of directory pointer after seekdir(2)
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Theodore Ts'o <[email protected]>
commit e40ff213898502d299351cc2fe1e350cd186f0d3 upstream.
A malicious user could force the directory pointer to be in an invalid spot by using seekdir(2). Use the mechanism we already have to notice if the directory has changed since the last time we called ext4_readdir() to force a revalidation of the pointer.
--- fs/ext4/dir.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ext4/dir.c +5 -3
@@ -322,13 +322,15 @@ static loff_t ext4_dir_llseek(struct fil {struct inode *inode = file->f_mapping->host;int dx_dir =is_dx_dir (inode); -loff_t htree_max =ext4_get_htree_eof (file); +loff_t ret, htree_max =ext4_get_htree_eof (file);if (likely (dx_dir)) -return generic_file_llseek_size (file, offset, whence, + ret =generic_file_llseek_size (file, offset, whence, htree_max, htree_max);else -return ext4_llseek (file, offset, whence); + ret =ext4_llseek (file, offset, whence); + file->f_version = inode->i_version -1 ; +return ret; }/*
PATCH 91/366 ALSA: pcm: Fix UAF at PCM release via PCM timer access
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit a820ccbe21e8ce8e86c39cd1d3bc8c7d1cbb949b upstream.
The PCM runtime object is created and freed dynamically at PCM stream open / close time. This is tracked via substream->runtime, and it's cleared at snd_pcm_detach_substream().
The runtime object assignment is protected by PCM open_mutex, so for all PCM operations, it's safely handled. However, each PCM substream provides also an ALSA timer interface, and user-space can access to this while closing a PCM substream. This may eventually lead to a UAF, as snd_pcm_timer_resolution() tries to access the runtime while clearing it in other side.
Fortunately, it's the only concurrent access from the PCM timer, and it merely reads runtime->timer_resolution field. So, we can avoid the race by reordering kfree() and wrapping the substream->runtime clearance with the corresponding timer lock.
--- sound/core/pcm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/core/pcm.c +7 -1
@@ -28,6 +28,7 @@#include <sound/core.h> #include <sound/minors.h> #include <sound/pcm.h> +#include <sound/timer.h> #include <sound/control.h> #include <sound/info.h>
@@ -1002,8 +1003,13 @@ void snd_pcm_detach_substream(struct snd#ifdef CONFIG_SND_PCM_XRUN_DEBUG kfree (runtime->hwptr_log);#endif -kfree (runtime); +/* Avoid concurrent access to runtime via PCM timer interface */ +if (substream->timer) +spin_lock_irq (&substream->timer->lock); substream->runtime =NULL ; +if (substream->timer) +spin_unlock_irq (&substream->timer->lock); +kfree (runtime);put_pid (substream->pid); substream->pid =NULL ; substream->pstr->substream_opened--;
PATCH 109/366 ipv6: sit: better validate user provided tunnel names
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit b95211e066fc3494b7c115060b2297b4ba21f025 upstream.
Use dev_valid_name() to make sure user does not provide illegal device name.
syzbot caught the following bug :
BUG: KASAN: stack-out-of-bounds in strlcpy include/linux/string.h:300 [inline] BUG: KASAN: stack-out-of-bounds in ipip6_tunnel_locate+0x63b/0xaa0 net/ipv6/sit.c:254 Write of size 33 at addr ffff8801b64076d8 by task syzkaller932654/4453 CPU: 0 PID: 4453 Comm: syzkaller932654 Not tainted 4.16.0+ #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x1b9/0x29f lib/dump_stack.c:53 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0xac/0x2f5 mm/kasan/report.c:412 check_memory_region_inline mm/kasan/kasan.c:260 [inline] check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 memcpy+0x37/0x50 mm/kasan/kasan.c:303 strlcpy include/linux/string.h:300 [inline] ipip6_tunnel_locate+0x63b/0xaa0 net/ipv6/sit.c:254 ipip6_tunnel_ioctl+0xe71/0x241b net/ipv6/sit.c:1221 dev_ifsioc+0x43e/0xb90 net/core/dev_ioctl.c:334 dev_ioctl+0x69a/0xcc0 net/core/dev_ioctl.c:525 sock_ioctl+0x47e/0x680 net/socket.c:1015 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0x1cf/0x1650 fs/ioctl.c:684 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:701 SYSC_ioctl fs/ioctl.c:708 [inline] SyS_ioctl+0x24/0x30 fs/ioctl.c:706 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7
--- net/ipv6/sit.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv6/sit.c +5 -3
@@ -244,11 +244,13 @@ static struct ip_tunnel *ipip6_tunnel_loif (!create) goto failed; -if (parms->name[0 ]) +if (parms->name[0 ]) { +if (!dev_valid_name (parms->name)) + goto failed;strlcpy (name, parms->name,IFNAMSIZ ); -else + }else {strcpy (name,"sit%d" ); - + } dev =alloc_netdev (sizeof (*t), name, ipip6_tunnel_setup);if (dev ==NULL )return NULL ;
PATCH 122/366 net: fix uninit-value in __hw_addr_add_ex()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 77d36398d99f2565c0a8d43a86fd520a82e64bb8 upstream.
syzbot complained :
BUG: KMSAN: uninit-value in memcmp+0x119/0x180 lib/string.c:861 CPU: 0 PID: 3 Comm: kworker/0:0 Not tainted 4.16.0+ #82 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: ipv6_addrconf addrconf_dad_work Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 memcmp+0x119/0x180 lib/string.c:861 __hw_addr_add_ex net/core/dev_addr_lists.c:60 [inline] __dev_mc_add+0x1c2/0x8e0 net/core/dev_addr_lists.c:670 dev_mc_add+0x6d/0x80 net/core/dev_addr_lists.c:687 igmp6_group_added+0x2db/0xa00 net/ipv6/mcast.c:662 ipv6_dev_mc_inc+0xe9e/0x1130 net/ipv6/mcast.c:914 addrconf_join_solict net/ipv6/addrconf.c:2078 [inline] addrconf_dad_begin net/ipv6/addrconf.c:3828 [inline] addrconf_dad_work+0x427/0x2150 net/ipv6/addrconf.c:3954 process_one_work+0x12c6/0x1f60 kernel/workqueue.c:2113 worker_thread+0x113c/0x24f0 kernel/workqueue.c:2247 kthread+0x539/0x720 kernel/kthread.c:239
--- net/core/dev_addr_lists.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/dev_addr_lists.c +2 -2
@@ -57,8 +57,8 @@ static int __hw_addr_add_ex(struct netdereturn -EINVAL ;list_for_each_entry (ha, &list->list, list) { -if (!memcmp (ha->addr, addr, addr_len) && - ha->type == addr_type) { +if (ha->type == addr_type && + !memcmp (ha->addr, addr, addr_len)) {if (global) {/* check if addr is already used as global */ if (ha->global_use)
PATCH 126/366 fanotify: fix logic of events on child
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
commit 54a307ba8d3cd00a3902337ffaae28f436eeb1a4 upstream.
When event on child inodes are sent to the parent inode mark and parent inode mark was not marked with FAN_EVENT_ON_CHILD, the event will not be delivered to the listener process. However, if the same process also has a mount mark, the event to the parent inode will be delivered regadless of the mount mark mask.
This behavior is incorrect in the case where the mount mark mask does not contain the specific event type. For example, the process adds a mark on a directory with mask FAN_MODIFY (without FAN_EVENT_ON_CHILD) and a mount mark with mask FAN_CLOSE_NOWRITE (without FAN_ONDIR).
A modify event on a file inside that directory (and inside that mount) should not create a FAN_MODIFY event, because neither of the marks requested to get that event on the file.
--- fs/notify/fanotify/fanotify.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
fs/notify/fanotify/fanotify.c +15 -19
@@ -92,7 +92,7 @@ static bool fanotify_should_send_event(su32 event_mask, void *data, int data_type) { - __u32 marks_mask, marks_ignored_mask; + __u32 marks_mask = 0, marks_ignored_mask = 0;struct path *path = data; pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p"
@@ -108,24 +108,20 @@ static bool fanotify_should_send_event(s !S_ISDIR(path->dentry->d_inode->i_mode))return false; -if (inode_mark && vfsmnt_mark) { - marks_mask = (vfsmnt_mark->mask | inode_mark->mask); - marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask); - }else if (inode_mark) { -/* -* if the event is for a child and this inode doesn't care about -* events on the child, don't send it! -*/ -if ((event_mask &FS_EVENT_ON_CHILD ) && - !(inode_mark->mask &FS_EVENT_ON_CHILD )) -return false; - marks_mask = inode_mark->mask; - marks_ignored_mask = inode_mark->ignored_mask; - }else if (vfsmnt_mark) { - marks_mask = vfsmnt_mark->mask; - marks_ignored_mask = vfsmnt_mark->ignored_mask; - }else { -BUG (); +/* +* if the event is for a child and this inode doesn't care about +* events on the child, don't send it! +*/ +if (inode_mark && + (!(event_mask &FS_EVENT_ON_CHILD ) || + (inode_mark->mask &FS_EVENT_ON_CHILD ))) { + marks_mask |= inode_mark->mask; + marks_ignored_mask |= inode_mark->ignored_mask; + } + +if (vfsmnt_mark) { + marks_mask |= vfsmnt_mark->mask; + marks_ignored_mask |= vfsmnt_mark->ignored_mask; } if (S_ISDIR(path->dentry->d_inode->i_mode) &&
PATCH 128/366 scsi: qla2xxx: Avoid double completion of abort command
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
commit 3a9910d7b686546dcc9986e790af17e148f1c888 upstream.
qla2x00_tmf_sp_done() now deletes the timer that will run qla2x00_tmf_iocb_timeout(), but doesn't check whether the timer already expired. Check the return value from del_timer() to avoid calling complete() a second time.
--- drivers/scsi/qla2xxx/qla_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_init.c +2 -2
@@ -363,8 +363,8 @@ qla24xx_abort_sp_done(void *data, void *srb_t *sp = (srb_t *)ptr;struct srb_iocb *abt = &sp->u.iocb_cmd; -del_timer (&sp->u.iocb_cmd.timer); -complete (&abt->u.abt.comp); +if (del_timer (&sp->u.iocb_cmd.timer)) +complete (&abt->u.abt.comp); } static int
PATCH 139/366 l2tp: fix race in duplicate tunnel detection
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit f6cd651b056ffd3b4e8496afd44d4ed44bf69136 upstream.
We can't use l2tp_tunnel_find() to prevent l2tp_nl_cmd_tunnel_create() from creating a duplicate tunnel. A tunnel can be concurrently registered after l2tp_tunnel_find() returns. Therefore, searching for duplicates must be done at registration time.
Finally, remove l2tp_tunnel_find() entirely as it isn't use anywhere anymore.
--- net/l2tp/l2tp_core.c | 35 ++++++++++++++--------------------- net/l2tp/l2tp_core.h | 1 - net/l2tp/l2tp_netlink.c | 6 ------ 3 files changed, 14 insertions(+), 28 deletions(-)
net/l2tp/l2tp_core.c +14 -21
@@ -395,26 +395,6 @@ err_tlock: }EXPORT_SYMBOL_GPL (l2tp_session_register); -/* Lookup a tunnel by id -*/ -struct l2tp_tunnel *l2tp_tunnel_find (struct net *net,u32 tunnel_id) -{ -struct l2tp_tunnel *tunnel; -struct l2tp_net *pn =l2tp_pernet (net); - -rcu_read_lock_bh (); -list_for_each_entry_rcu (tunnel, &pn->l2tp_tunnel_list, list) { -if (tunnel->tunnel_id == tunnel_id) { -rcu_read_unlock_bh (); -return tunnel; - } - } -rcu_read_unlock_bh (); - -return NULL ; -} -EXPORT_SYMBOL_GPL (l2tp_tunnel_find); -struct l2tp_tunnel *l2tp_tunnel_find_nth (struct net *net,int nth) {struct l2tp_net *pn =l2tp_pernet (net);
@@ -1625,6 +1605,7 @@ static int l2tp_validate_socket(const stint l2tp_tunnel_register (struct l2tp_tunnel *tunnel,struct net *net,struct l2tp_tunnel_cfg *cfg) { +struct l2tp_tunnel *tunnel_walk;struct l2tp_net *pn;struct socket *sock;struct sock *sk;
@@ -1653,7 +1634,16 @@ int l2tp_tunnel_register(struct l2tp_tun tunnel->l2tp_net = net; pn =l2tp_pernet (net); +spin_lock_bh (&pn->l2tp_tunnel_list_lock); +list_for_each_entry (tunnel_walk, &pn->l2tp_tunnel_list, list) { +if (tunnel_walk->tunnel_id == tunnel->tunnel_id) { +spin_unlock_bh (&pn->l2tp_tunnel_list_lock); + + ret = -EEXIST ; + goto err_sock; + } + }list_add_rcu (&tunnel->list, &pn->l2tp_tunnel_list);spin_unlock_bh (&pn->l2tp_tunnel_list_lock);
@@ -1683,7 +1673,10 @@ int l2tp_tunnel_register(struct l2tp_tunreturn 0 ; err_sock: -sockfd_put (sock); +if (tunnel->fd <0 ) +sock_release (sock); +else +sockfd_put (sock); err:return ret; }
net/l2tp/l2tp_core.h +0 -1
@@ -240,7 +240,6 @@ struct l2tp_session *l2tp_session_get_ntstruct l2tp_session *l2tp_session_get_by_ifname (const struct net *net,const char *ifname,bool do_ref); -struct l2tp_tunnel *l2tp_tunnel_find (struct net *net,u32 tunnel_id);struct l2tp_tunnel *l2tp_tunnel_find_nth (struct net *net,int nth); int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id,
net/l2tp/l2tp_netlink.c +0 -6
@@ -177,12 +177,6 @@ static int l2tp_nl_cmd_tunnel_create(strif (info->attrs[L2TP_ATTR_DEBUG ]) cfg.debug =nla_get_u32 (info->attrs[L2TP_ATTR_DEBUG ]); - tunnel =l2tp_tunnel_find (net, tunnel_id); -if (tunnel !=NULL ) { - ret = -EEXIST ; - goto out; - } - ret = -EINVAL ;switch (cfg.encap) {case L2TP_ENCAPTYPE_UDP :
PATCH 141/366 ASoC: fsl_esai: Fix divisor calculation failure at lower ratio
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
commit c656941df9bc80f7ec65b92ca73c42f8b0b62628 upstream.
When the desired ratio is less than 256, the savesub (tolerance) in the calculation would become 0. This will then fail the loop- search immediately without reporting any errors.
But if the ratio is smaller enough, there is no need to calculate the tolerance because PM divisor alone is enough to get the ratio.
So a simple fix could be just to set PM directly instead of going into the loop-search.
--- sound/soc/fsl/fsl_esai.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/fsl/fsl_esai.c +7 -0
@@ -142,6 +142,13 @@ static int fsl_esai_divisor_cal(struct s psr = ratio <=256 * maxfp ? ESAI_xCCR_xPSR_BYPASS : ESAI_xCCR_xPSR_DIV8; +/* Do not loop-search if PM (1 ~ 256) alone can serve the ratio */ +if (ratio <=256 ) { + pm = ratio; + fp =1 ; + goto out; + } +/* Set the max fluctuation -- 0.1% of the max devisor */ savesub = (psr ?1 :8 ) *256 * maxfp /1000 ;
PATCH 142/366 tcp: md5: reject TCP_MD5SIG or TCP_MD5SIG_EXT on established sockets
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 7212303268918b9a203aebeacfdbd83b5e87b20d upstream.
syzbot/KMSAN reported an uninit-value in tcp_parse_options() [1]
I believe this was caused by a TCP_MD5SIG being set on live flow.
This is highly unexpected, since TCP option space is limited.
For instance, presence of TCP MD5 option automatically disables TCP TimeStamp option at SYN/SYNACK time, which we can not do once flow has been established.
Really, adding/deleting an MD5 key only makes sense on sockets in CLOSE or LISTEN state.
[1]
BUG: KMSAN: uninit-value in tcp_parse_options+0xd74/0x1a30 net/ipv4/tcp_input.c:3720 CPU: 1 PID: 6177 Comm: syzkaller192004 Not tainted 4.16.0+ #83 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 tcp_parse_options+0xd74/0x1a30 net/ipv4/tcp_input.c:3720 tcp_fast_parse_options net/ipv4/tcp_input.c:3858 [inline] tcp_validate_incoming+0x4f1/0x2790 net/ipv4/tcp_input.c:5184 tcp_rcv_established+0xf60/0x2bb0 net/ipv4/tcp_input.c:5453 tcp_v4_do_rcv+0x6cd/0xd90 net/ipv4/tcp_ipv4.c:1469 sk_backlog_rcv include/net/sock.h:908 [inline] __release_sock+0x2d6/0x680 net/core/sock.c:2271 release_sock+0x97/0x2a0 net/core/sock.c:2786 tcp_sendmsg+0xd6/0x100 net/ipv4/tcp.c:1464 inet_sendmsg+0x48d/0x740 net/ipv4/af_inet.c:764 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] SYSC_sendto+0x6c3/0x7e0 net/socket.c:1747 SyS_sendto+0x8a/0xb0 net/socket.c:1715 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 RIP: 0033:0x448fe9 RSP: 002b:00007fd472c64d38 EFLAGS: 00000216 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00000000006e5a30 RCX: 0000000000448fe9 RDX: 000000000000029f RSI: 0000000020a88f88 RDI: 0000000000000004 RBP: 00000000006e5a34 R08: 0000000020e68000 R09: 0000000000000010 R10: 00000000200007fd R11: 0000000000000216 R12: 0000000000000000 R13: 00007fff074899ef R14: 00007fd472c659c0 R15: 0000000000000009
Uninit was created at:
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:278 [inline] kmsan_internal_poison_shadow+0xb8/0x1b0 mm/kmsan/kmsan.c:188 kmsan_kmalloc+0x94/0x100 mm/kmsan/kmsan.c:314 kmsan_slab_alloc+0x11/0x20 mm/kmsan/kmsan.c:321 slab_post_alloc_hook mm/slab.h:445 [inline] slab_alloc_node mm/slub.c:2737 [inline] __kmalloc_node_track_caller+0xaed/0x11c0 mm/slub.c:4369 __kmalloc_reserve net/core/skbuff.c:138 [inline] __alloc_skb+0x2cf/0x9f0 net/core/skbuff.c:206 alloc_skb include/linux/skbuff.h:984 [inline] tcp_send_ack+0x18c/0x910 net/ipv4/tcp_output.c:3624 __tcp_ack_snd_check net/ipv4/tcp_input.c:5040 [inline] tcp_ack_snd_check net/ipv4/tcp_input.c:5053 [inline] tcp_rcv_established+0x2103/0x2bb0 net/ipv4/tcp_input.c:5469 tcp_v4_do_rcv+0x6cd/0xd90 net/ipv4/tcp_ipv4.c:1469 sk_backlog_rcv include/net/sock.h:908 [inline] __release_sock+0x2d6/0x680 net/core/sock.c:2271 release_sock+0x97/0x2a0 net/core/sock.c:2786 tcp_sendmsg+0xd6/0x100 net/ipv4/tcp.c:1464 inet_sendmsg+0x48d/0x740 net/ipv4/af_inet.c:764 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] SYSC_sendto+0x6c3/0x7e0 net/socket.c:1747 SyS_sendto+0x8a/0xb0 net/socket.c:1715 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2
--- net/ipv4/tcp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +4 -2
@@ -2683,8 +2683,10 @@ static int do_tcp_setsockopt(struct sock#ifdef CONFIG_TCP_MD5SIG case TCP_MD5SIG : -/* Read the IP->Key mappings from userspace */ - err = tp->af_specific->md5_parse (sk, optval, optlen); +if ((1 << sk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN )) + err = tp->af_specific->md5_parse (sk, optval, optlen); +else + err = -EINVAL ;break ;#endif case TCP_USER_TIMEOUT :
PATCH 145/366 l2tp: hold reference on tunnels in netlink dumps
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit 5846c131c39b6d0add36ec19dc8650700690f930 upstream.
l2tp_tunnel_find_nth() is unsafe: no reference is held on the returned tunnel, therefore it can be freed whenever the caller uses it. This patch defines l2tp_tunnel_get_nth() which works similarly, but also takes a reference on the returned tunnel. The caller then has to drop it after it stops using the tunnel.
Convert netlink dumps to make them safe against concurrent tunnel deletion.
--- net/l2tp/l2tp_core.c | 20 ++++++++++++++++++++ net/l2tp/l2tp_core.h | 2 ++ net/l2tp/l2tp_netlink.c | 11 ++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-)
net/l2tp/l2tp_core.c +20 -0
@@ -231,6 +231,26 @@ struct l2tp_tunnel *l2tp_tunnel_get(cons }EXPORT_SYMBOL_GPL (l2tp_tunnel_get); +struct l2tp_tunnel *l2tp_tunnel_get_nth (const struct net *net,int nth) +{ +const struct l2tp_net *pn =l2tp_pernet (net); +struct l2tp_tunnel *tunnel; +int count =0 ; + +rcu_read_lock_bh (); +list_for_each_entry_rcu (tunnel, &pn->l2tp_tunnel_list, list) { +if (++count > nth) { +l2tp_tunnel_inc_refcount (tunnel); +rcu_read_unlock_bh (); +return tunnel; + } + } +rcu_read_unlock_bh (); + +return NULL ; +} +EXPORT_SYMBOL_GPL (l2tp_tunnel_get_nth); +/* Like l2tp_session_find() but takes a reference on the returned session. * Optionally calls session->ref() too if do_ref is true. */
net/l2tp/l2tp_core.h +2 -0
@@ -227,6 +227,8 @@ static inline void *l2tp_session_priv(st }struct l2tp_tunnel *l2tp_tunnel_get (const struct net *net,u32 tunnel_id); +struct l2tp_tunnel *l2tp_tunnel_get_nth (const struct net *net,int nth); +void l2tp_tunnel_free (struct l2tp_tunnel *tunnel); struct l2tp_session *l2tp_session_get(const struct net *net,
net/l2tp/l2tp_netlink.c +8 -3
@@ -395,14 +395,17 @@ static int l2tp_nl_cmd_tunnel_dump(strucstruct net *net =sock_net (skb->sk);for (;;) { - tunnel =l2tp_tunnel_find_nth (net, ti); + tunnel =l2tp_tunnel_get_nth (net, ti);if (tunnel ==NULL ) goto out;if (l2tp_nl_tunnel_send (skb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,NLM_F_MULTI , - tunnel) <=0 ) + tunnel) <=0 ) { +l2tp_tunnel_dec_refcount (tunnel); goto out; + } +l2tp_tunnel_dec_refcount (tunnel); ti++; }
@@ -746,7 +749,7 @@ static int l2tp_nl_cmd_session_dump(strufor (;;) {if (tunnel ==NULL ) { - tunnel =l2tp_tunnel_find_nth (net, ti); + tunnel =l2tp_tunnel_get_nth (net, ti);if (tunnel ==NULL ) goto out; }
@@ -754,6 +757,7 @@ static int l2tp_nl_cmd_session_dump(stru session =l2tp_session_get_nth (tunnel, si, false);if (session ==NULL ) { ti++; +l2tp_tunnel_dec_refcount (tunnel); tunnel =NULL ; si =0 ;continue ;
@@ -763,6 +767,7 @@ static int l2tp_nl_cmd_session_dump(stru cb->nlh->nlmsg_seq, NLM_F_MULTI, session) <= 0) {l2tp_session_dec_refcount (session); +l2tp_tunnel_dec_refcount (tunnel);break ; }l2tp_session_dec_refcount (session);
PATCH 147/366 l2tp: hold reference on tunnels printed in l2tp/tunnels debugfs file
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit f726214d9b23e5fce8c11937577a289a3202498f upstream.
Use l2tp_tunnel_get_nth() instead of l2tp_tunnel_find_nth(), to be safe against concurrent tunnel deletion.
Use the same mechanism as in l2tp_ppp.c for dropping the reference taken by l2tp_tunnel_get_nth(). That is, drop the reference just before looking up the next tunnel. In case of error, drop the last accessed tunnel in l2tp_dfs_seq_stop().
That was the last use of l2tp_tunnel_find_nth().
--- net/l2tp/l2tp_core.c | 20 -------------------- net/l2tp/l2tp_core.h | 1 - net/l2tp/l2tp_debugfs.c | 15 +++++++++++++-- 3 files changed, 13 insertions(+), 23 deletions(-)
net/l2tp/l2tp_core.c +0 -20
@@ -415,26 +415,6 @@ err_tlock: }EXPORT_SYMBOL_GPL (l2tp_session_register); -struct l2tp_tunnel *l2tp_tunnel_find_nth (struct net *net,int nth) -{ -struct l2tp_net *pn =l2tp_pernet (net); -struct l2tp_tunnel *tunnel; -int count =0 ; - -rcu_read_lock_bh (); -list_for_each_entry_rcu (tunnel, &pn->l2tp_tunnel_list, list) { -if (++count > nth) { -rcu_read_unlock_bh (); -return tunnel; - } - } - -rcu_read_unlock_bh (); - -return NULL ; -} -EXPORT_SYMBOL_GPL (l2tp_tunnel_find_nth); -/***************************************************************************** * Receive data handling *****************************************************************************/
net/l2tp/l2tp_core.h +0 -1
@@ -242,7 +242,6 @@ struct l2tp_session *l2tp_session_get_ntstruct l2tp_session *l2tp_session_get_by_ifname (const struct net *net,const char *ifname,bool do_ref); -struct l2tp_tunnel *l2tp_tunnel_find_nth (struct net *net,int nth); int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg,
net/l2tp/l2tp_debugfs.c +13 -2
@@ -47,7 +47,11 @@ struct l2tp_dfs_seq_data {static void l2tp_dfs_next_tunnel (struct l2tp_dfs_seq_data *pd) { - pd->tunnel =l2tp_tunnel_find_nth (pd->net, pd->tunnel_idx); +/* Drop reference taken during previous invocation */ +if (pd->tunnel) +l2tp_tunnel_dec_refcount (pd->tunnel); + + pd->tunnel =l2tp_tunnel_get_nth (pd->net, pd->tunnel_idx); pd->tunnel_idx++; }
@@ -96,7 +100,14 @@ static void *l2tp_dfs_seq_next(struct sestatic void l2tp_dfs_seq_stop (struct seq_file *p,void *v) { -/* nothing to do */ +struct l2tp_dfs_seq_data *pd = v; + +if (!pd || pd ==SEQ_START_TOKEN ) +return ; + +/* Drop reference taken by last invocation of l2tp_dfs_next_tunnel() */ +if (pd->tunnel) +l2tp_tunnel_dec_refcount (pd->tunnel); }static void l2tp_dfs_seq_tunnel_show (struct seq_file *m,void *v)
PATCH 156/366 powerpc/lib: Fix off-by-one in alternate feature patching
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michael Ellerman <[email protected]>
commit b8858581febb050688e276b956796bc4a78299ed upstream.
When we patch an alternate feature section, we have to adjust any relative branches that branch out of the alternate section.
But currently we have a bug if we have a branch that points to past the last instruction of the alternate section, eg:
FTR_SECTION_ELSE
1: b 2f
or 6,6,6
2:
ALT_FTR_SECTION_END(...)
nop
This will result in a relative branch at 1 with a target that equals the end of the alternate section.
That branch does not need adjusting when it's moved to the non-else location. Currently we do adjust it, resulting in a branch that goes off into the link-time location of the else section, which is junk.
The fix is to not patch branches that have a target == end of the alternate section.
--- arch/powerpc/lib/feature-fixups.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/lib/feature-fixups.c +1 -1
@@ -52,7 +52,7 @@ static int patch_alt_instruction(unsigneunsigned int *target = (unsigned int *)branch_target (src);/* Branch within the section doesn't need translating */ -if (target < alt_start || target >= alt_end) { +if (target < alt_start || target > alt_end) { instr =translate_branch (dest, src);if (!instr)return 1 ;
PATCH 158/366 net: af_packet: fix race in PACKET_{R|T}X_RING
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 5171b37d959641bbc619781caf62e61f7b940871 upstream.
In order to remove the race caught by syzbot [1], we need to lock the socket before using po->tp_version as this could change under us otherwise.
This means lock_sock() and release_sock() must be done by packet_set_ring() callers.
[1] :
BUG: KMSAN: uninit-value in packet_set_ring+0x1254/0x3870 net/packet/af_packet.c:4249 CPU: 0 PID: 20195 Comm: syzkaller707632 Not tainted 4.16.0+ #83 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 packet_set_ring+0x1254/0x3870 net/packet/af_packet.c:4249 packet_setsockopt+0x12c6/0x5a90 net/packet/af_packet.c:3662 SYSC_setsockopt+0x4b8/0x570 net/socket.c:1849 SyS_setsockopt+0x76/0xa0 net/socket.c:1828 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 RIP: 0033:0x449099 RSP: 002b:00007f42b5307ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000036 RAX: ffffffffffffffda RBX: 000000000070003c RCX: 0000000000449099 RDX: 0000000000000005 RSI: 0000000000000107 RDI: 0000000000000003 RBP: 0000000000700038 R08: 000000000000001c R09: 0000000000000000 R10: 00000000200000c0 R11: 0000000000000246 R12: 0000000000000000 R13: 000000000080eecf R14: 00007f42b53089c0 R15: 0000000000000001
Local variable description: ----req_u@packet_setsockopt Variable was created at:
packet_setsockopt+0x13f/0x5a90 net/packet/af_packet.c:3612 SYSC_setsockopt+0x4b8/0x570 net/socket.c:1849
[bwh: Backported to 3.16: PACKET_VNET_HDR is incompatible with
PACKET_{TX,RX}_RING; fix up the check for that as well]
---
net/packet/af_packet.c +16 -10
@@ -2651,6 +2651,7 @@ static int packet_release(struct socketpacket_flush_mclist (sk); +lock_sock (sk);if (po->rx_ring.pg_vec) {memset (&req_u,0 ,sizeof (req_u));packet_set_ring (sk, &req_u,1 ,0 );
@@ -2660,6 +2661,7 @@ static int packet_release(struct socketmemset (&req_u,0 ,sizeof (req_u));packet_set_ring (sk, &req_u,1 ,1 ); } +release_sock (sk); f =fanout_release (sk);
@@ -3295,6 +3297,7 @@ packet_setsockopt(struct socket *sock, iunion tpacket_req_u req_u;int len; +lock_sock (sk);switch (po->tp_version) {case TPACKET_V1 :case TPACKET_V2 :
@@ -3305,14 +3308,19 @@ packet_setsockopt(struct socket *sock, i len =sizeof (req_u.req3);break ; } -if (optlen < len) -return -EINVAL ; -if (pkt_sk (sk)->has_vnet_hdr) -return -EINVAL ; -if (copy_from_user (&req_u.req, optval, len)) -return -EFAULT ; -return packet_set_ring (sk, &req_u,0 , - optname ==PACKET_TX_RING ); +if (optlen < len) { + ret = -EINVAL ; + }else if (pkt_sk (sk)->has_vnet_hdr) { + ret = -EINVAL ; + }else { +if (copy_from_user (&req_u.req, optval, len)) + ret = -EFAULT ; +else + ret =packet_set_ring (sk, &req_u,0 , + optname ==PACKET_TX_RING ); + } +release_sock (sk); +return ret; }case PACKET_COPY_THRESH : {
@@ -3820,7 +3828,6 @@ static int packet_set_ring(struct sock */* Added to avoid minimal code churn */ struct tpacket_req *req = &req_u->req; -lock_sock (sk);/* Opening a Tx-ring is NOT supported in TPACKET_V3 */ if (!closing && tx_ring && (po->tp_version >TPACKET_V2 )) {WARN (1 ,"Tx-ring is not supported.\n" );
@@ -3956,7 +3963,6 @@ static int packet_set_ring(struct sock *if (pg_vec)free_pg_vec (pg_vec, order, req->tp_block_nr); out: -release_sock (sk);return err; }
PATCH 167/366 vlan: Fix reading memory beyond skb->tail in skb_vlan_tagged_multi
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Toshiaki Makita <[email protected]>
commit 7ce2367254e84753bceb07327aaf5c953cfce117 upstream.
Syzkaller spotted an old bug which leads to reading skb beyond tail by 4 bytes on vlan tagged packets.
This is caused because skb_vlan_tagged_multi() did not check skb_headlen.
BUG: KMSAN: uninit-value in eth_type_vlan include/linux/if_vlan.h:283 [inline] BUG: KMSAN: uninit-value in skb_vlan_tagged_multi include/linux/if_vlan.h:656 [inline] BUG: KMSAN: uninit-value in vlan_features_check include/linux/if_vlan.h:672 [inline] BUG: KMSAN: uninit-value in dflt_features_check net/core/dev.c:2949 [inline] BUG: KMSAN: uninit-value in netif_skb_features+0xd1b/0xdc0 net/core/dev.c:3009 CPU: 1 PID: 3582 Comm: syzkaller435149 Not tainted 4.16.0+ #82 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 eth_type_vlan include/linux/if_vlan.h:283 [inline] skb_vlan_tagged_multi include/linux/if_vlan.h:656 [inline] vlan_features_check include/linux/if_vlan.h:672 [inline] dflt_features_check net/core/dev.c:2949 [inline] netif_skb_features+0xd1b/0xdc0 net/core/dev.c:3009 validate_xmit_skb+0x89/0x1320 net/core/dev.c:3084 __dev_queue_xmit+0x1cb2/0x2b60 net/core/dev.c:3549 dev_queue_xmit+0x4b/0x60 net/core/dev.c:3590 packet_snd net/packet/af_packet.c:2944 [inline] packet_sendmsg+0x7c57/0x8a10 net/packet/af_packet.c:2969 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] sock_write_iter+0x3b9/0x470 net/socket.c:909 do_iter_readv_writev+0x7bb/0x970 include/linux/fs.h:1776 do_iter_write+0x30d/0xd40 fs/read_write.c:932 vfs_writev fs/read_write.c:977 [inline] do_writev+0x3c9/0x830 fs/read_write.c:1012 SYSC_writev+0x9b/0xb0 fs/read_write.c:1085 SyS_writev+0x56/0x80 fs/read_write.c:1082 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 RIP: 0033:0x43ffa9 RSP: 002b:00007fff2cff3948 EFLAGS: 00000217 ORIG_RAX: 0000000000000014 RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 000000000043ffa9 RDX: 0000000000000001 RSI: 0000000020000080 RDI: 0000000000000003 RBP: 00000000006cb018 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000217 R12: 00000000004018d0 R13: 0000000000401960 R14: 0000000000000000 R15: 0000000000000000
Uninit was created at:
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:278 [inline] kmsan_internal_poison_shadow+0xb8/0x1b0 mm/kmsan/kmsan.c:188 kmsan_kmalloc+0x94/0x100 mm/kmsan/kmsan.c:314 kmsan_slab_alloc+0x11/0x20 mm/kmsan/kmsan.c:321 slab_post_alloc_hook mm/slab.h:445 [inline] slab_alloc_node mm/slub.c:2737 [inline] __kmalloc_node_track_caller+0xaed/0x11c0 mm/slub.c:4369 __kmalloc_reserve net/core/skbuff.c:138 [inline] __alloc_skb+0x2cf/0x9f0 net/core/skbuff.c:206 alloc_skb include/linux/skbuff.h:984 [inline] alloc_skb_with_frags+0x1d4/0xb20 net/core/skbuff.c:5234 sock_alloc_send_pskb+0xb56/0x1190 net/core/sock.c:2085 packet_alloc_skb net/packet/af_packet.c:2803 [inline] packet_snd net/packet/af_packet.c:2894 [inline] packet_sendmsg+0x6444/0x8a10 net/packet/af_packet.c:2969 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] sock_write_iter+0x3b9/0x470 net/socket.c:909 do_iter_readv_writev+0x7bb/0x970 include/linux/fs.h:1776 do_iter_write+0x30d/0xd40 fs/read_write.c:932 vfs_writev fs/read_write.c:977 [inline] do_writev+0x3c9/0x830 fs/read_write.c:1012 SYSC_writev+0x9b/0xb0 fs/read_write.c:1085 SyS_writev+0x56/0x80 fs/read_write.c:1082 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2
---
net/core/dev.c +2 -1
@@ -2608,7 +2608,8 @@ netdev_features_t netif_skb_features(strif (!vlan_tx_tag_present (skb)) {if (unlikely (protocol ==htons (ETH_P_8021Q ) || - protocol ==htons (ETH_P_8021AD ))) { + protocol ==htons (ETH_P_8021AD )) && +likely (pskb_may_pull (skb,VLAN_ETH_HLEN ))) {struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; protocol = veh->h_vlan_encapsulated_proto; }else {
PATCH 169/366 ext4: set h_journal if there is a failure starting a reserved handle
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Theodore Ts'o <[email protected]>
commit b2569260d55228b617bd82aba6d0db2faeeb4116 upstream.
If ext4 tries to start a reserved handle via jbd2_journal_start_reserved(), and the journal has been aborted, this can result in a NULL pointer dereference. This is because the fields h_journal and h_transaction in the handle structure share the same memory, via a union, so jbd2_journal_start_reserved() will clear h_journal before calling start_this_handle(). If this function fails due to an aborted handle, h_journal will still be NULL, and the call to jbd2_journal_free_reserved() will pass a NULL journal to sub_reserve_credits().
This can be reproduced by running "kvm-xfstests -c dioread_nolock generic/475".
--- fs/jbd2/transaction.c | 1 + 1 file changed, 1 insertion(+)
fs/jbd2/transaction.c +1 -0
@@ -515,6 +515,7 @@ int jbd2_journal_start_reserved(handle_t*/ ret =start_this_handle (journal, handle,GFP_NOFS );if (ret <0 ) { + handle->h_journal = journal;jbd2_journal_free_reserved (handle);return ret; }
PATCH 170/366 MIPS: memset.S: Fix clobber of v1 in last_fixup
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit c96eebf07692e53bf4dd5987510d8b550e793598 upstream.
The label .Llast_fixup\@ is jumped to on page fault within the final byte set loop of memset (on < MIPSR6 architectures). For some reason, in this fault handler, the v1 register is randomly set to a2 & STORMASK. This clobbers v1 for the calling function. This can be observed with the following test code:
static int __init __attribute__((optimize("O0"))) test_clear_user(void) {
register int t asm("v1");
char *test;
int j, k;
pr_info("\n\n\nTesting clear_user\n");
test = vmalloc(PAGE_SIZE);
for (j = 256; j < 512; j++) {
t = 0xa5a5a5a5;
if ((k = clear_user(test + PAGE_SIZE - 256, j)) != j - 256) {
pr_err("clear_user (%px %d) returned %d\n", test + PAGE_SIZE - 256, j, k);
}
if (t != 0xa5a5a5a5) {
pr_err("v1 was clobbered to 0x%x!\n", t);
}
} return 0;
}late_initcall(test_clear_user);
Which demonstrates that v1 is indeed clobbered (MIPS64):
Testing clear_user
v1 was clobbered to 0x1!
v1 was clobbered to 0x2!
v1 was clobbered to 0x3!
v1 was clobbered to 0x4!
v1 was clobbered to 0x5!
v1 was clobbered to 0x6!
v1 was clobbered to 0x7!
Since the number of bytes that could not be set is already contained in a2, the andi placing a value in v1 is not necessary and actively harmful in clobbering v1.
Patchwork: https://patchwork.linux-mips.org/patch/19109/
--- arch/mips/lib/memset.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/memset.S +1 -1
@@ -210,7 +210,7 @@ .Llast_fixup\@: jr ra - andi v1, a2, STORMASK + nop .Lsmall_fixup\@: PTR_SUBU a2, t1, a0
PATCH 179/366 xhci: Fix USB ports for Dell Inspiron 5775
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit 621faf4f6a181b6e012c1d1865213f36f4159b7f upstream.
The Dell Inspiron 5775 is a Raven Ridge. The Enable Slot command timed out when a USB device gets plugged:
[ 212.156326] xhci_hcd 0000:03:00.3: Error while assigning device slot ID [ 212.156340] xhci_hcd 0000:03:00.3: Max number of devices this xHCI host supports is 64. [ 212.156348] usb usb2-port3: couldn't allocate usb_device
AMD suggests that a delay before xHC suspends can fix the issue.
I can confirm it fixes the issue, so use the suspend delay quirk for Raven Ridge's xHC.
--- drivers/usb/host/xhci-pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-pci.c +4 -1
@@ -124,7 +124,10 @@ static void xhci_pci_quirks(struct devicif (pdev->vendor ==PCI_VENDOR_ID_AMD &&usb_amd_find_chipset_info ()) xhci->quirks |=XHCI_AMD_PLL_FIX ; -if (pdev->vendor ==PCI_VENDOR_ID_AMD && pdev->device ==0x43bb ) +if (pdev->vendor ==PCI_VENDOR_ID_AMD && + (pdev->device ==0x15e0 || + pdev->device ==0x15e1 || + pdev->device ==0x43bb )) xhci->quirks |=XHCI_SUSPEND_DELAY ;if (pdev->vendor ==PCI_VENDOR_ID_AMD )
PATCH 184/366 usbip: vhci_hcd: check rhport before using in vhci_hub_control()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 5b22f676118ff25049382041da0db8012e57c9e8 upstream.
Validate !rhport < 0 before using it to access port_status array.
[bwh: Backported to 3.16:
- Drop changes to the SetPortFeature USB_PORT_FEAT_{SUSPEND,POWER,BH_PORT_RESET} cases
- Add the "error" label
- Adjust filename, context]
---
drivers/staging/usbip/vhci_hcd.c +7 -1
@@ -266,6 +266,8 @@ static int vhci_hub_control(struct usb_husbip_dbg_vhci_rh (" ClearHubFeature\n" );break ;case ClearPortFeature: +if (rhport <0 ) + goto error;switch (wValue) {case USB_PORT_FEAT_SUSPEND :if (dum->port_status[rhport] &USB_PORT_STAT_SUSPEND ) {
@@ -370,6 +372,8 @@ static int vhci_hub_control(struct usb_hcase USB_PORT_FEAT_RESET :usbip_dbg_vhci_rh (" SetPortFeature: USB_PORT_FEAT_RESET\n" ); +if (rhport <0 ) + goto error;/* if it's already running, disconnect first */ if (dum->port_status[rhport] &USB_PORT_STAT_ENABLE ) { dum->port_status[rhport] &=
@@ -385,6 +389,8 @@ static int vhci_hub_control(struct usb_hdefault :usbip_dbg_vhci_rh (" SetPortFeature: default %d\n" , wValue); +if (rhport <0 ) + goto error; dum->port_status[rhport] |= (1 << wValue);break ; }
@@ -392,7 +398,7 @@ static int vhci_hub_control(struct usb_hdefault :pr_err ("default: no such request\n" ); - +error:/* "protocol stall" on error */ retval = -EPIPE ; }
PATCH 189/366 llc: hold llc_sap before release_sock()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit f7e43672683b097bb074a8fe7af9bc600a23f231 upstream.
syzbot reported we still access llc->sap in llc_backlog_rcv() after it is freed in llc_sap_remove_socket():
Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1b9/0x294 lib/dump_stack.c:113 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412 __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430 llc_conn_ac_send_sabme_cmd_p_set_x+0x3a8/0x460 net/llc/llc_c_ac.c:785 llc_exec_conn_trans_actions net/llc/llc_conn.c:475 [inline] llc_conn_service net/llc/llc_conn.c:400 [inline] llc_conn_state_process+0x4e1/0x13a0 net/llc/llc_conn.c:75 llc_backlog_rcv+0x195/0x1e0 net/llc/llc_conn.c:891 sk_backlog_rcv include/net/sock.h:909 [inline] __release_sock+0x12f/0x3a0 net/core/sock.c:2335 release_sock+0xa4/0x2b0 net/core/sock.c:2850 llc_ui_release+0xc8/0x220 net/llc/af_llc.c:204
llc->sap is refcount'ed and llc_sap_remove_socket() is paired with llc_sap_add_socket(). This can be amended by holding its refcount before llc_sap_remove_socket() and releasing it after release_sock().
--- net/llc/af_llc.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/llc/af_llc.c +7 -0
@@ -187,6 +187,7 @@ static int llc_ui_release(struct socket {struct sock *sk = sock->sk;struct llc_sock *llc; +struct llc_sap *sap;if (unlikely (sk ==NULL )) goto out;
@@ -197,9 +198,15 @@ static int llc_ui_release(struct socket llc->laddr.lsap, llc->daddr.lsap);if (!llc_send_disc (sk))llc_ui_wait_for_disc (sk, sk->sk_rcvtimeo); + sap = llc->sap; +/* Hold this for release_sock(), so that llc_backlog_rcv() could still +* use it. +*/ +llc_sap_hold (sap);if (!sock_flag (sk,SOCK_ZAPPED ))llc_sap_remove_socket (llc->sap, sk);release_sock (sk); +llc_sap_put (sap);if (llc->dev)dev_put (llc->dev);sock_put (sk);
PATCH 192/366 s390/dasd: fix IO error for newly defined devices
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Haberland <[email protected]>
commit 5d27a2bf6e14f5c7d1033ad1e993fcd0eba43e83 upstream.
When a new CKD storage volume is defined at the storage server, Linux may be relying on outdated information about that volume, which leads to the following errors:
1. Command Reject Errors for minidisk on z/VM:
dasd-eckd.b3193d: 0.0.XXXX: An error occurred in the DASD device driver,
reason=09 dasd(eckd): I/O status report for device 0.0.XXXX: dasd(eckd): in req: 00000000XXXXXXXX CC:00 FC:04 AC:00 SC:17 DS:02 CS:00 RC:0
dasd(eckd): device 0.0.2046: Failing CCW: 00000000XXXXXXXX dasd(eckd): Sense(hex) 0- 7: 80 00 00 00 00 00 00 00 dasd(eckd): Sense(hex) 8-15: 00 00 00 00 00 00 00 00 dasd(eckd): Sense(hex) 16-23: 00 00 00 00 e1 00 0f 00 dasd(eckd): Sense(hex) 24-31: 00 00 40 e2 00 00 00 00 dasd(eckd): 24 Byte: 0 MSG 0, no MSGb to SYSOP
2. Equipment Check errors on LPAR or for dedicated devices on z/VM:
dasd(eckd): I/O status report for device 0.0.XXXX:
dasd(eckd): in req: 00000000XXXXXXXX CC:00 FC:04 AC:00 SC:17 DS:0E CS:40
fcxs:01 schxs:00 RC:0
dasd(eckd): device 0.0.9713: Failing TCW: 00000000XXXXXXXX dasd(eckd): Sense(hex) 0- 7: 10 00 00 00 13 58 4d 0f dasd(eckd): Sense(hex) 8-15: 67 00 00 00 00 00 00 04 dasd(eckd): Sense(hex) 16-23: e5 18 05 33 97 01 0f 0f dasd(eckd): Sense(hex) 24-31: 00 00 40 e2 00 04 58 0d dasd(eckd): 24 Byte: 0 MSG f, no MSGb to SYSOP
Fix this problem by using the up-to-date information provided during online processing via the device specific SNEQ to detect the case of outdated LCU data. If there is a difference, perform a re-read of that data.
[bwh: Backported to 3.16:
- Move up assignment of "private"
- Adjust context]
---
drivers/s390/block/dasd_alias.c +12 -4
@@ -608,18 +608,26 @@ static int _schedule_lcu_update(struct aint dasd_alias_add_device (struct dasd_device *device) { -struct dasd_eckd_private *private; -struct alias_lcu *lcu; +struct dasd_eckd_private *private = device->private; +__u8 uaddr = private->uid.real_unit_addr; +struct alias_lcu *lcu = private->lcu;unsigned long flags;int rc; - private = (struct dasd_eckd_private *) device->private; - lcu = private->lcu; rc =0 ;/* need to take cdev lock before lcu lock */ spin_lock_irqsave (get_ccwdev_lock (device->cdev), flags);spin_lock (&lcu->lock); +/* +* Check if device and lcu type differ. If so, the uac data may be +* outdated and needs to be updated. +*/ +if (private->uid.type != lcu->uac->unit[uaddr].ua_type) { + lcu->flags |=UPDATE_PENDING ; +DBF_DEV_EVENT (DBF_WARNING , device,"%s" , +"uid type mismatch - trigger rescan" ); + }if (!(lcu->flags &UPDATE_PENDING )) { rc =_add_device_to_lcu (lcu, device, device);if (rc)
PATCH 196/366 tty: Avoid possible error pointer dereference at tty_ldisc_restore().
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit 598c2d41ff44889dd8eced4f117403e472158d85 upstream.
syzbot is reporting crashes [1] triggered by memory allocation failure at tty_ldisc_get() from tty_ldisc_restore(). While syzbot stops at WARN_ON() due to panic_on_warn == true, panic_on_warn == false will after all trigger an OOPS by dereferencing old->ops->num if IS_ERR(old) == true.
We can simplify tty_ldisc_restore() as three calls (old->ops->num, N_TTY, N_NULL) to tty_ldisc_failto() in addition to avoiding possible error pointer dereference.
If someone reports kernel panic triggered by forcing all memory allocations for tty_ldisc_restore() to fail, we can consider adding __GFP_NOFAIL for tty_ldisc_restore() case.
[1] https://syzkaller.appspot.com/bug?id=6ac359c61e71d22e06db7f8f88243feb11d927e7
--- drivers/tty/tty_ldisc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/tty/tty_ldisc.c +5 -8
@@ -510,19 +510,16 @@ static void tty_ldisc_restore(struct ttychar buf[64 ];/* There is an outstanding reference here so this is safe */ - old =tty_ldisc_get (tty, old->ops->num); -WARN_ON (IS_ERR (old)); - tty->ldisc = old; -tty_set_termios_ldisc (tty, old->ops->num); -if (tty_ldisc_open (tty, old) <0 ) { -tty_ldisc_put (old); +if (tty_ldisc_failto (tty, old->ops->num) <0 ) { +const char *name =tty_name (tty, buf); + +pr_warn ("Falling back ldisc for %s.\n" , name);/* The traditional behaviour is to fall back to N_TTY, we want to avoid falling back to N_NULL unless we have no choice to avoid the risk of breaking anything */ if (tty_ldisc_failto (tty,N_TTY ) <0 &&tty_ldisc_failto (tty,N_NULL ) <0 ) -panic ("Couldn't open N_NULL ldisc for %s." , -tty_name (tty, buf)); +panic ("Couldn't open N_NULL ldisc for %s." , name); } }
PATCH 197/366 tty: Don't call panic() at tty_ldisc_init()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit 903f9db10f18f735e62ba447147b6c434b6af003 upstream.
syzbot is reporting kernel panic [1] triggered by memory allocation failure at tty_ldisc_get() from tty_ldisc_init(). But since both tty_ldisc_get() and caller of tty_ldisc_init() can cleanly handle errors, tty_ldisc_init() does not need to call panic() when tty_ldisc_get() failed.
[1] https://syzkaller.appspot.com/bug?id=883431818e036ae6a9981156a64b821110f39187
--- drivers/tty/tty_io.c | 5 ++++- drivers/tty/tty_ldisc.c | 5 +++-- include/linux/tty.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/tty/tty_io.c +4 -1
@@ -3036,7 +3036,10 @@ struct tty_struct *alloc_tty_struct(strukref_init (&tty->kref); tty->magic =TTY_MAGIC ; -tty_ldisc_init (tty); +if (tty_ldisc_init (tty)) { +kfree (tty); +return NULL ; + } tty->session =NULL ; tty->pgrp =NULL ;mutex_init (&tty->legacy_mutex);
drivers/tty/tty_ldisc.c +3 -2
@@ -820,12 +820,13 @@ void tty_ldisc_release(struct tty_struct* the tty structure is not completely set up when this call is made. */ -void tty_ldisc_init (struct tty_struct *tty) +int tty_ldisc_init (struct tty_struct *tty) {struct tty_ldisc *ld =tty_ldisc_get (tty,N_TTY );if (IS_ERR (ld)) -panic ("n_tty: init_tty" ); +return PTR_ERR (ld); tty->ldisc = ld; +return 0 ; }/**
include/linux/tty.h +1 -1
@@ -556,7 +556,7 @@ extern int tty_unregister_ldisc(int discextern int tty_set_ldisc (struct tty_struct *tty,int ldisc);extern int tty_ldisc_setup (struct tty_struct *tty,struct tty_struct *o_tty);extern void tty_ldisc_release (struct tty_struct *tty,struct tty_struct *o_tty); -extern void tty_ldisc_init (struct tty_struct *tty); +extern int __must_check tty_ldisc_init (struct tty_struct *tty);extern void tty_ldisc_deinit (struct tty_struct *tty);extern void tty_ldisc_begin (void );
PATCH 202/366 bonding: do not set slave_dev npinfo before slave_enable_netpoll in bond_enslave
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit ddea788c63094f7c483783265563dd5b50052e28 upstream.
After Commit 8a8efa22f51b ("bonding: sync netpoll code with bridge"), it would set slave_dev npinfo in slave_enable_netpoll when enslaving a dev if bond->dev->npinfo was set.
However now slave_dev npinfo is set with bond->dev->npinfo before calling slave_enable_netpoll. With slave_dev npinfo set, __netpoll_setup called in slave_enable_netpoll will not call slave dev's .ndo_netpoll_setup(). It causes that the lower dev of this slave dev can't set its npinfo.
One way to reproduce it:
# modprobe bonding # brctl addbr br0 # brctl addif br0 eth1 # ifconfig bond0 192.168.122.1/24 up # ifenslave bond0 eth2 # systemctl restart netconsole # ifenslave bond0 br0 # ifconfig eth2 down # systemctl restart netconsole
The netpoll won't really work.
This patch is to remove that slave_dev npinfo setting in bond_enslave().
--- drivers/net/bonding/bond_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +1 -2
@@ -1535,8 +1535,7 @@ int bond_enslave(struct net_device *bond }/* switch(bond_mode) */ #ifdef CONFIG_NET_POLL_CONTROLLER - slave_dev->npinfo = bond->dev->npinfo; -if (slave_dev->npinfo) { +if (bond->dev->npinfo) {if (slave_enable_netpoll (new_slave)) {pr_info ("Error, %s: master_dev is using netpoll, but new slave device does not support netpoll\n" , bond_dev->name);
PATCH 210/366 mtd: cfi: cmdset_0002: Do not allow read/write to suspend erase block.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joakim Tjernlund <[email protected]>
commit 7b70eb14392a7cf505f9b358d06c33b5af73d1e7 upstream.
Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine.
Taken from cfi_cmdset_0001 driver.
--- drivers/mtd/chips/cfi_cmdset_0002.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mtd/chips/cfi_cmdset_0002.c +6 -3
@@ -780,9 +780,10 @@ static int get_chip(struct map_info *map (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)))) goto sleep; -/* We could check to see if we're trying to access the sector -* that is currently being erased. However, no user will try -* anything like that so we just wait for the timeout. */ +/* Do not allow suspend iff read/write to EB address */ +if ((adr & chip->in_progress_block_mask) == + chip->in_progress_block_addr) + goto sleep;/* Erase suspend */ /* It's harmless to issue the Erase-Suspend and Erase-Resume
@@ -1926,6 +1927,7 @@ static int __xipram do_erase_chip(struct chip->state =FL_ERASING ; chip->erase_suspended =0 ; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(map->size -1 ); INVALIDATE_CACHE_UDELAY(map, chip, adr, map->size,
@@ -2015,6 +2017,7 @@ static int __xipram do_erase_oneblock(st chip->state =FL_ERASING ; chip->erase_suspended =0 ; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len -1 ); INVALIDATE_CACHE_UDELAY(map, chip, adr, len,
PATCH 212/366 ALSA: seq: oss: Fix unbalanced use lock for synth MIDI device
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f5e94b4c6ebdabe0f602d796e0430180927521a0 upstream.
When get_synthdev() is called for a MIDI device, it returns the fixed midi_synth_dev without the use refcounting. OTOH, the caller is supposed to unreference unconditionally after the usage, so this would lead to unbalanced refcount.
This patch corrects the behavior and keep up the refcount balance also for the MIDI synth device.
--- sound/core/seq/oss/seq_oss_synth.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/core/seq/oss/seq_oss_synth.c +8 -4
@@ -363,10 +363,14 @@ get_synthdev(struct seq_oss_devinfo *dp,return NULL ;if (! dp->synths[dev].opened)return NULL ; -if (dp->synths[dev].is_midi) -return &midi_synth_dev; -if ((rec =get_sdev (dev)) ==NULL ) -return NULL ; +if (dp->synths[dev].is_midi) { + rec = &midi_synth_dev; +snd_use_lock_use (&rec->use_lock); + }else { + rec =get_sdev (dev); +if (!rec) +return NULL ; + }if (! rec->opened) {snd_use_lock_free (&rec->use_lock);return NULL ;
PATCH 213/366 ALSA: seq: oss: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 8d218dd8116695ecda7164f97631c069938aa22e upstream.
As Smatch recently suggested, a few places in OSS sequencer codes may expand the array directly from the user-space value with speculation, namely there are a significant amount of references to either info->ch[] or dp->synths[] array:
sound/core/seq/oss/seq_oss_event.c:315 note_on_event() warn: potential spectre issue 'info->ch' (local cap) sound/core/seq/oss/seq_oss_event.c:362 note_off_event() warn: potential spectre issue 'info->ch' (local cap) sound/core/seq/oss/seq_oss_synth.c:470 snd_seq_oss_synth_load_patch() warn: potential spectre issue 'dp->synths' (local cap) sound/core/seq/oss/seq_oss_event.c:293 note_on_event() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_event.c:353 note_off_event() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_synth.c:506 snd_seq_oss_synth_sysex() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_synth.c:580 snd_seq_oss_synth_ioctl() warn: potential spectre issue 'dp->synths'
Although all these seem doing only the first load without further reference, we may want to stay in a safer side, so hardening with array_index_nospec() would still make sense.
We may put array_index_nospec() at each place, but here we take a different approach:
- For dp->synths[], change the helpers to retrieve seq_oss_synthinfo pointer directly instead of the array expansion at each place
- For info->ch[], harden in a normal way, as there are only a couple of places
As a result, the existing helper, snd_seq_oss_synth_is_valid() is replaced with snd_seq_oss_synth_info(). Also, we cover MIDI device where a similar array expansion is done, too, although it wasn't reported by Smatch.
--- sound/core/seq/oss/seq_oss_event.c | 15 +++--- sound/core/seq/oss/seq_oss_midi.c | 2 + sound/core/seq/oss/seq_oss_synth.c | 75 +++++++++++++++++------------- sound/core/seq/oss/seq_oss_synth.h | 3 +- 4 files changed, 55 insertions(+), 40 deletions(-)
sound/core/seq/oss/seq_oss_event.c +9 -6
@@ -26,6 +26,7 @@#include <sound/seq_oss_legacy.h> #include "seq_oss_readq.h" #include "seq_oss_writeq.h" +#include <linux/nospec.h> /*
@@ -287,10 +288,10 @@ note_on_event(struct seq_oss_devinfo *dp {struct seq_oss_synthinfo *info; -if (!snd_seq_oss_synth_is_valid (dp, dev)) + info =snd_seq_oss_synth_info (dp, dev); +if (!info)return -ENXIO ; - info = &dp->synths[dev];switch (info->arg.event_passing) {case SNDRV_SEQ_OSS_PROCESS_EVENTS :if (! info->ch || ch <0 || ch >= info->nr_voices) {
@@ -298,6 +299,7 @@ note_on_event(struct seq_oss_devinfo *dpreturn set_note_event (dp, dev,SNDRV_SEQ_EVENT_NOTEON , ch, note, vel, ev); } + ch =array_index_nospec (ch, info->nr_voices);if (note ==255 && info->ch[ch].note >=0 ) {/* volume control */ int type;
@@ -347,10 +349,10 @@ note_off_event(struct seq_oss_devinfo *d {struct seq_oss_synthinfo *info; -if (!snd_seq_oss_synth_is_valid (dp, dev)) + info =snd_seq_oss_synth_info (dp, dev); +if (!info)return -ENXIO ; - info = &dp->synths[dev];switch (info->arg.event_passing) {case SNDRV_SEQ_OSS_PROCESS_EVENTS :if (! info->ch || ch <0 || ch >= info->nr_voices) {
@@ -358,6 +360,7 @@ note_off_event(struct seq_oss_devinfo *dreturn set_note_event (dp, dev,SNDRV_SEQ_EVENT_NOTEON , ch, note, vel, ev); } + ch =array_index_nospec (ch, info->nr_voices);if (info->ch[ch].note >=0 ) { note = info->ch[ch].note; info->ch[ch].vel =0 ;
@@ -381,7 +384,7 @@ note_off_event(struct seq_oss_devinfo *dstatic int set_note_event (struct seq_oss_devinfo *dp,int dev,int type,int ch,int note,int vel,struct snd_seq_event *ev) { -if (!snd_seq_oss_synth_is_valid (dp, dev)) +if (!snd_seq_oss_synth_info (dp, dev))return -ENXIO ; ev->type = type;
@@ -399,7 +402,7 @@ set_note_event(struct seq_oss_devinfo *dstatic int set_control_event (struct seq_oss_devinfo *dp,int dev,int type,int ch,int param,int val,struct snd_seq_event *ev) { -if (!snd_seq_oss_synth_is_valid (dp, dev)) +if (!snd_seq_oss_synth_info (dp, dev))return -ENXIO ; ev->type = type;
sound/core/seq/oss/seq_oss_midi.c +2 -0
@@ -29,6 +29,7 @@#include "../seq_lock.h" #include <linux/init.h> #include <linux/slab.h> +#include <linux/nospec.h> /*
@@ -318,6 +319,7 @@ get_mididev(struct seq_oss_devinfo *dp, {if (dev <0 || dev >= dp->max_mididev)return NULL ; + dev =array_index_nospec (dev, dp->max_mididev);return get_mdev (dev); }
sound/core/seq/oss/seq_oss_synth.c +42 -33
171 lines not on this page · raw message
sound/core/seq/oss/seq_oss_synth.h +2 -1
@@ -37,7 +37,8 @@ void snd_seq_oss_synth_cleanup(struct sevoid snd_seq_oss_synth_reset (struct seq_oss_devinfo *dp,int dev);int snd_seq_oss_synth_load_patch (struct seq_oss_devinfo *dp,int dev,int fmt,const char __user *buf,int p,int c); -int snd_seq_oss_synth_is_valid (struct seq_oss_devinfo *dp,int dev); +struct seq_oss_synthinfo *snd_seq_oss_synth_info (struct seq_oss_devinfo *dp, +int dev);int snd_seq_oss_synth_sysex (struct seq_oss_devinfo *dp,int dev,unsigned char *buf,struct snd_seq_event *ev);int snd_seq_oss_synth_addr (struct seq_oss_devinfo *dp,int dev,struct snd_seq_event *ev);
PATCH 215/366 ALSA: hda: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 69fa6f19b95597618ab30438a27b67ad93daa7c7 upstream.
As recently Smatch suggested, one place in HD-audio hwdep ioctl codes
may expand the array directly from the user-space value with
speculation:
sound/pci/hda/hda_local.h:467 get_wcaps() warn: potential spectre issue 'codec->wcaps'
As get_wcaps() itself is a fairly frequently called inline function, and there is only one single call with a user-space value, we replace only the latter one to open-code locally with array_index_nospec() hardening in this patch.
--- sound/pci/hda/hda_hwdep.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
sound/pci/hda/hda_hwdep.c +11 -1
@@ -21,6 +21,7 @@#include <linux/init.h> #include <linux/slab.h> #include <linux/compat.h> +#include <linux/nospec.h> #include <sound/core.h> #include "hda_codec.h" #include "hda_local.h"
@@ -51,7 +52,16 @@ static int get_wcap_ioctl(struct hda_codif (get_user (verb, &arg->verb))return -EFAULT ; - res =get_wcaps (codec, verb >>24 ); +/* open-code get_wcaps(verb>>24) with nospec */ + verb >>=24 ; +if (verb < codec->start_nid || + verb >= codec->start_nid + codec->num_nodes) { + res =0 ; + }else { + verb -= codec->start_nid; + verb =array_index_nospec (verb, codec->num_nodes); + res = codec->wcaps[verb]; + }if (put_user (res, &arg->res))return -EFAULT ;return 0 ;
PATCH 217/366 ALSA: asihpi: used parts of message/response are zeroed before use
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eliot Blennerhassett <[email protected]>
commit 51e6f47dd2e3463dac6f37128fd7b7cb40c500de upstream.
--- sound/pci/asihpi/hpimsginit.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
sound/pci/asihpi/hpimsginit.c +20 -10
@@ -1,7 +1,7 @@/****************************************************************************** AudioScience HPI driver -Copyright (C) 1997-2011 AudioScience Inc. <[email protected]> +Copyright (C) 1997-2014 AudioScience Inc. <[email protected]> This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as
@@ -37,11 +37,15 @@ static u16 gwSSX2_bypass;static void hpi_init_message (struct hpi_message *phm,u16 object,u16 function) { -memset (phm,0 ,sizeof (*phm)); +u16 size; +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) - phm->size = msg_size[object]; + size = msg_size[object];else - phm->size =sizeof (*phm); + size =sizeof (*phm); + +memset (phm,0 , size); + phm->size = size;if (gwSSX2_bypass) phm->type =HPI_TYPE_SSX2BYPASS_MESSAGE ;
@@ -60,12 +64,16 @@ static void hpi_init_message(struct hpi_void hpi_init_response (struct hpi_response *phr,u16 object,u16 function,u16 error) { -memset (phr,0 ,sizeof (*phr)); - phr->type =HPI_TYPE_RESPONSE ; +u16 size; +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) - phr->size = res_size[object]; + size = res_size[object];else - phr->size =sizeof (*phr); + size =sizeof (*phr); + +memset (phr,0 ,sizeof (*phr)); + phr->size = size; + phr->type =HPI_TYPE_RESPONSE ; phr->object = object; phr->function = function; phr->error = error;
@@ -86,7 +94,7 @@ void hpi_init_message_response(struct hpstatic void hpi_init_messageV1 (struct hpi_message_header *phm,u16 size,u16 object,u16 function) { -memset (phm,0 ,sizeof (*phm)); +memset (phm,0 , size);if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { phm->size = size; phm->type =HPI_TYPE_REQUEST ;
@@ -100,7 +108,9 @@ static void hpi_init_messageV1(struct hpvoid hpi_init_responseV1 (struct hpi_response_header *phr,u16 size,u16 object,u16 function) { -memset (phr,0 ,sizeof (*phr)); + (void )object; + (void )function; +memset (phr,0 , size); phr->size = size; phr->version =1 ; phr->type =HPI_TYPE_RESPONSE ;
PATCH 218/366 ALSA: asihpi: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f9d94b57e30fd1575b4935045b32d738668aa74b upstream.
As recently Smatch suggested, a couple of places in ASIHPI driver may
expand the array directly from the user-space value with speculation:
sound/pci/asihpi/hpimsginit.c:70 hpi_init_response() warn: potential spectre issue 'res_size' (local cap) sound/pci/asihpi/hpioctl.c:189 asihpi_hpi_ioctl() warn: potential spectre issue 'adapters'
This patch puts array_index_nospec() for hardening against them.
--- sound/pci/asihpi/hpimsginit.c | 13 +++++++++---- sound/pci/asihpi/hpioctl.c | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-)
sound/pci/asihpi/hpimsginit.c +9 -4
@@ -23,6 +23,7 @@#include "hpi_internal.h" #include "hpimsginit.h" +#include <linux/nospec.h> /* The actual message size for each object type */ static u16 msg_size[HPI_OBJ_MAXINDEX +1 ] =HPI_MESSAGE_SIZE_BY_OBJECT ;
@@ -39,10 +40,12 @@ static void hpi_init_message(struct hpi_ {u16 size; -if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { + object =array_index_nospec (object,HPI_OBJ_MAXINDEX +1 ); size = msg_size[object]; -else + }else { size =sizeof (*phm); + }memset (phm,0 , size); phm->size = size;
@@ -66,10 +69,12 @@ void hpi_init_response(struct hpi_respon {u16 size; -if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { + object =array_index_nospec (object,HPI_OBJ_MAXINDEX +1 ); size = res_size[object]; -else + }else { size =sizeof (*phr); + }memset (phr,0 ,sizeof (*phr)); phr->size = size;
sound/pci/asihpi/hpioctl.c +3 -1
@@ -35,6 +35,7 @@ Common Linux HPI ioctl and module probe/#include <linux/pci.h> #include <linux/stringify.h> #include <linux/module.h> +#include <linux/nospec.h> #ifdef MODULE_FIRMWARE MODULE_FIRMWARE ("asihpi/dsp5000.bin" );
@@ -182,7 +183,8 @@ long asihpi_hpi_ioctl(struct file *file,struct hpi_adapter *pa =NULL ;if (hm->h.adapter_index <ARRAY_SIZE (adapters)) - pa = &adapters[hm->h.adapter_index]; + pa = &adapters[array_index_nospec (hm->h.adapter_index, +ARRAY_SIZE (adapters))];if (!pa || !pa->adapter || !pa->adapter->type) { hpi_init_response(&hr->r0, hm->h.object,
PATCH 222/366 virtio_console: don't tie bufs to a vq
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit 2855b33514d290c51d52d94e25d3ef942cd4d578 upstream.
an allocated buffer doesn't need to be tied to a vq - only vq->vdev is ever used. Pass the function the just what it needs - the vdev.
--- drivers/char/virtio_console.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +7 -7
@@ -417,7 +417,7 @@ static void reclaim_dma_bufs(void) } } -static struct port_buffer *alloc_buf (struct virtqueue *vq,size_t buf_size, +static struct port_buffer *alloc_buf (struct virtio_device *vdev,size_t buf_size,int pages) {struct port_buffer *buf;
@@ -440,7 +440,7 @@ static struct port_buffer *alloc_buf(strreturn buf; } -if (is_rproc_serial (vq->vdev)) { +if (is_rproc_serial (vdev)) {/* * Allocate DMA memory from ancestor. When a virtio * device is created by remoteproc, the DMA memory is
@@ -450,9 +450,9 @@ static struct port_buffer *alloc_buf(str* DMA_MEMORY_INCLUDES_CHILDREN had been supported * in dma-coherent.c */ -if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent) +if (!vdev->dev.parent || !vdev->dev.parent->parent) goto free_buf; - buf->dev = vq->vdev->dev.parent->parent; + buf->dev = vdev->dev.parent->parent;/* Increase device refcnt to avoid freeing it */ get_device (buf->dev);
@@ -834,7 +834,7 @@ static ssize_t port_fops_write(struct fi count =min ((size_t )(32 *1024 ), count); - buf =alloc_buf (port->out_vq, count,0 ); + buf =alloc_buf (port->portdev->vdev, count,0 );if (!buf)return -ENOMEM ;
@@ -953,7 +953,7 @@ static ssize_t port_fops_splice_write(stif (ret <0 ) goto error_out; - buf =alloc_buf (port->out_vq,0 , pipe->nrbufs); + buf =alloc_buf (port->portdev->vdev,0 , pipe->nrbufs);if (!buf) { ret = -ENOMEM ; goto error_out;
@@ -1370,7 +1370,7 @@ static unsigned int fill_queue(struct vi nr_added_bufs =0 ; do { - buf = alloc_buf(vq, PAGE_SIZE, 0); + buf = alloc_buf(vq->vdev, PAGE_SIZE, 0); if (!buf) break;
PATCH 229/366 libceph: validate con->state at the top of try_write()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit 9c55ad1c214d9f8c4594ac2c3fa392c1c32431a7 upstream.
ceph_con_workfn() validates con->state before calling try_read() and then try_write(). However, try_read() temporarily releases con->mutex, notably in process_message() and ceph_con_in_msg_alloc(), opening the window for ceph_con_close() to sneak in, close the connection and release con->sock. When try_write() is called on the assumption that con->state is still valid (i.e. not STANDBY or CLOSED), a NULL sock gets passed to the networking stack:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 IP: selinux_socket_sendmsg+0x5/0x20
Make sure con->state is valid at the top of try_write() and add an explicit BUG_ON for this, similar to try_read().
--- net/ceph/messenger.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/ceph/messenger.c +7 -0
@@ -2453,6 +2453,11 @@ static int try_write(struct ceph_connectint ret =1 ;dout ("try_write start %p state %lu\n" , con, con->state); +if (con->state !=CON_STATE_PREOPEN && + con->state !=CON_STATE_CONNECTING && + con->state !=CON_STATE_NEGOTIATING && + con->state !=CON_STATE_OPEN ) +return 0 ; more:dout ("try_write out_kvec_bytes %d\n" , con->out_kvec_bytes);
@@ -2478,6 +2483,8 @@ more: } more_kvec: +BUG_ON (!con->sock); +/* kvec data queued? */ if (con->out_skip) { ret =write_partial_skip (con);
PATCH 242/366 iw_cxgb4: Atomically flush per QP HW CQEs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bharat Potnuri <[email protected]>
commit 2df19e19ae90d94fd8724083f161f368a2797537 upstream.
When a CQ is shared by multiple QPs, c4iw_flush_hw_cq() needs to acquire corresponding QP lock before moving the CQEs into its corresponding SW queue and accessing the SQ contents for completing a WR. Ignore CQEs if corresponding QP is already flushed.
--- drivers/infiniband/hw/cxgb4/cq.c | 11 ++++++++++- drivers/infiniband/hw/cxgb4/iw_cxgb4.h | 2 +- drivers/infiniband/hw/cxgb4/qp.c | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-)
drivers/infiniband/hw/cxgb4/cq.c +10 -1
@@ -331,7 +331,7 @@ static void advance_oldest_read(struct t* Deal with out-of-order and/or completions that complete * prior unsignalled WRs. */ -void c4iw_flush_hw_cq (struct c4iw_cq *chp) +void c4iw_flush_hw_cq (struct c4iw_cq *chp,struct c4iw_qp *flush_qhp) {struct t4_cqe *hw_cqe, *swcqe, read_cqe;struct c4iw_qp *qhp;
@@ -355,6 +355,13 @@ void c4iw_flush_hw_cq(struct c4iw_cq *chif (qhp ==NULL ) goto next_cqe; +if (flush_qhp != qhp) { +spin_lock (&qhp->lock); + +if (qhp->wq.flushed ==1 ) + goto next_cqe; + } +if (CQE_OPCODE (hw_cqe) ==FW_RI_TERMINATE ) goto next_cqe;
@@ -406,6 +413,8 @@ void c4iw_flush_hw_cq(struct c4iw_cq *ch next_cqe:t4_hwcq_consume (&chp->cq); ret =t4_next_hw_cqe (&chp->cq, &hw_cqe); +if (qhp && flush_qhp != qhp) +spin_unlock (&qhp->lock); } }
drivers/infiniband/hw/cxgb4/iw_cxgb4.h +1 -1
@@ -977,7 +977,7 @@ void c4iw_pblpool_free(struct c4iw_rdevu32 c4iw_ocqp_pool_alloc (struct c4iw_rdev *rdev,int size);void c4iw_ocqp_pool_free (struct c4iw_rdev *rdev,u32 addr,int size);int c4iw_ofld_send (struct c4iw_rdev *rdev,struct sk_buff *skb); -void c4iw_flush_hw_cq (struct c4iw_cq *chp); +void c4iw_flush_hw_cq (struct c4iw_cq *chp,struct c4iw_qp *flush_qhp);void c4iw_count_rcqes (struct t4_cq *cq,struct t4_wq *wq,int *count);int c4iw_ep_disconnect (struct c4iw_ep *ep,int abrupt,gfp_t gfp);int c4iw_flush_rq (struct t4_wq *wq,struct t4_cq *cq,int count);
drivers/infiniband/hw/cxgb4/qp.c +2 -2
@@ -1082,7 +1082,7 @@ static void __flush_qp(struct c4iw_qp *q } qhp->wq.flushed =1 ; -c4iw_flush_hw_cq (rchp); +c4iw_flush_hw_cq (rchp, qhp);c4iw_count_rcqes (&rchp->cq, &qhp->wq, &count); flushed =c4iw_flush_rq (&qhp->wq, &rchp->cq, count);spin_unlock (&qhp->lock);
@@ -1097,7 +1097,7 @@ static void __flush_qp(struct c4iw_qp *qspin_lock_irqsave (&schp->lock, flag);spin_lock (&qhp->lock);if (schp != rchp) -c4iw_flush_hw_cq (schp); +c4iw_flush_hw_cq (schp, qhp); flushed =c4iw_flush_sq (qhp);spin_unlock (&qhp->lock);spin_unlock_irqrestore (&schp->lock, flag);
PATCH 243/366 net: support compat 64-bit time in {s,g}etsockopt
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lance Richardson <[email protected]>
commit 988bf7243e03ef69238381594e0334a79cef74a6 upstream.
For the x32 ABI, struct timeval has two 64-bit fields. However the kernel currently interprets the user-space values used for the SO_RCVTIMEO and SO_SNDTIMEO socket options as having a pair of 32-bit fields.
When the seconds portion of the requested timeout is less than 2**32, the seconds portion of the effective timeout is correct but the microseconds portion is zero. When the seconds portion of the requested timeout is zero and the microseconds portion is non-zero, the kernel interprets the timeout as zero (never timeout).
Fix by using 64-bit time for SO_RCVTIMEO/SO_SNDTIMEO as required for the ABI.
The code included below demonstrates the problem.
Results before patch:
$ gcc -m64 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.008181 seconds
send time: 2.015985 seconds $ gcc -m32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.016763 seconds
send time: 2.016062 seconds $ gcc -mx32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 1.007239 seconds
send time: 1.023890 secondsResults after patch:
$ gcc -m64 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.010062 seconds
send time: 2.015836 seconds $ gcc -m32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.013974 seconds
send time: 2.015981 seconds $ gcc -mx32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.030257 seconds
send time: 2.013383 seconds #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
void checkrc(char *str, int rc)
{
if (rc >= 0)
return;
perror(str);
exit(1);}
static char buf[1024];
int main(int argc, char **argv)
{
int rc;
int socks[2];
struct timeval tv;
struct timeval start, end, delta;
rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socks);
checkrc("socketpair", rc);
/* set timeout to 1.999999 seconds */
tv.tv_sec = 1;
tv.tv_usec = 999999;
rc = setsockopt(socks[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
rc = setsockopt(socks[0], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
checkrc("setsockopt", rc);
/* measure actual receive timeout */
gettimeofday(&start, NULL);
rc = recv(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("recv time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
/* fill send buffer */
do {
rc = send(socks[0], buf, sizeof buf, 0);
} while (rc > 0);
/* measure actual send timeout */
gettimeofday(&start, NULL);
rc = send(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("send time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
exit(0);}
--- net/compat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/compat.c +4 -2
@@ -386,7 +386,8 @@ static int compat_sock_setsockopt(structif (optname ==SO_ATTACH_FILTER )return do_set_attach_filter (sock, level, optname, optval, optlen); -if (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ) +if (!COMPAT_USE_64BIT_TIME && + (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ))return do_set_sock_timeout (sock, level, optname, optval, optlen);return sock_setsockopt (sock, level, optname, optval, optlen);
@@ -451,7 +452,8 @@ static int do_get_sock_timeout(struct sostatic int compat_sock_getsockopt (struct socket *sock,int level,int optname,char __user *optval,int __user *optlen) { -if (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ) +if (!COMPAT_USE_64BIT_TIME && + (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ))return do_get_sock_timeout (sock, level, optname, optval, optlen);return sock_getsockopt (sock, level, optname, optval, optlen); }
PATCH 255/366 qmi_wwan: do not steal interfaces from class drivers
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bjørn Mork <[email protected]>
commit 5697db4a696c41601a1d15c1922150b4dbf5726c upstream.
The USB_DEVICE_INTERFACE_NUMBER matching macro assumes that the { vendorid, productid, interfacenumber } set uniquely identifies one specific function. This has proven to fail for some configurable devices. One example is the Quectel EM06/EP06 where the same interface number can be either QMI or MBIM, without the device ID changing either.
Fix by requiring the vendor-specific class for interface number based matching. Functions of other classes can and should use class based matching instead.
--- drivers/net/usb/qmi_wwan.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/usb/qmi_wwan.c +12 -0
@@ -899,6 +899,18 @@ static int qmi_wwan_probe(struct usb_int id->driver_info = (unsigned long )&qmi_wwan_info; } +/* There are devices where the same interface number can be +* configured as different functions. We should only bind to +* vendor specific functions when matching on interface number +*/ +if (id->match_flags &USB_DEVICE_ID_MATCH_INT_NUMBER && + desc->bInterfaceClass !=USB_CLASS_VENDOR_SPEC ) { +dev_dbg (&intf->dev, +"Rejecting interface number match for class %02x\n" , + desc->bInterfaceClass); +return -ENODEV ; + } +/* Quectel EC20 quirk where we've QMI on interface 4 instead of 0 */ if (quectel_ec20_detected (intf) && desc->bInterfaceNumber ==0 ) {dev_dbg (&intf->dev,"Quectel EC20 quirk, skipping interface 0\n" );
PATCH 257/366 dccp: fix tasklet usage
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit a8d7aa17bbc970971ccdf71988ea19230ab368b1 upstream.
syzbot reported a crash in tasklet_action_common() caused by dccp.
dccp needs to make sure socket wont disappear before tasklet handler has completed.
This patch takes a reference on the socket when arming the tasklet, and moves the sock_put() from dccp_write_xmit_timer() to dccp_write_xmitlet()
kernel BUG at kernel/softirq.c:514!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 1 PID: 17 Comm: ksoftirqd/1 Not tainted 4.17.0-rc3+ #30 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:tasklet_action_common.isra.19+0x6db/0x700 kernel/softirq.c:515 RSP: 0018:ffff8801d9b3faf8 EFLAGS: 00010246 dccp_close: ABORT with 65423 bytes unread RAX: 1ffff1003b367f6b RBX: ffff8801daf1f3f0 RCX: 0000000000000000 RDX: ffff8801cf895498 RSI: 0000000000000004 RDI: 0000000000000000 RBP: ffff8801d9b3fc40 R08: ffffed0039f12a95 R09: ffffed0039f12a94 dccp_close: ABORT with 65423 bytes unread R10: ffffed0039f12a94 R11: ffff8801cf8954a3 R12: 0000000000000000 R13: ffff8801d9b3fc18 R14: dffffc0000000000 R15: ffff8801cf895490 FS: 0000000000000000(0000) GS:ffff8801daf00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2bc28000 CR3: 00000001a08a9000 CR4: 00000000001406e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: tasklet_action+0x1d/0x20 kernel/softirq.c:533 __do_softirq+0x2e0/0xaf5 kernel/softirq.c:285 dccp_close: ABORT with 65423 bytes unread run_ksoftirqd+0x86/0x100 kernel/softirq.c:646 smpboot_thread_fn+0x417/0x870 kernel/smpboot.c:164 kthread+0x345/0x410 kernel/kthread.c:238 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412 Code: 48 8b 85 e8 fe ff ff 48 8b 95 f0 fe ff ff e9 94 fb ff ff 48 89 95 f0 fe ff ff e8 81 53 6e 00 48 8b 95 f0 fe ff ff e9 62 fb ff ff <0f> 0b 48 89 cf 48 89 8d e8 fe ff ff e8 64 53 6e 00 48 8b 8d e8 RIP: tasklet_action_common.isra.19+0x6db/0x700 kernel/softirq.c:515 RSP: ffff8801d9b3faf8
--- net/dccp/ccids/ccid2.c | 14 ++++++++++++-- net/dccp/timer.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
net/dccp/ccids/ccid2.c +12 -2
@@ -126,6 +126,16 @@ static void ccid2_change_l_seq_window(st DCCPF_SEQ_WMAX)); } +static void dccp_tasklet_schedule (struct sock *sk) +{ +struct tasklet_struct *t = &dccp_sk (sk)->dccps_xmitlet; + +if (!test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) { +sock_hold (sk); +__tasklet_schedule (t); + } +} +static void ccid2_hc_tx_rto_expire (unsigned long data) {struct sock *sk = (struct sock *)data;
@@ -166,7 +176,7 @@ static void ccid2_hc_tx_rto_expire(unsig/* if we were blocked before, we may now send cwnd=1 packet */ if (sender_was_blocked) -tasklet_schedule (&dccp_sk (sk)->dccps_xmitlet); +dccp_tasklet_schedule (sk);/* restart backed-off timer */ sk_reset_timer (sk, &hc->tx_rtotimer, jiffies + hc->tx_rto); out:
@@ -706,7 +716,7 @@ static void ccid2_hc_tx_packet_recv(stru done:/* check if incoming Acks allow pending packets to be sent */ if (sender_was_blocked && !ccid2_cwnd_network_limited (hc)) -tasklet_schedule (&dccp_sk (sk)->dccps_xmitlet); +dccp_tasklet_schedule (sk);dccp_ackvec_parsed_cleanup (&hc->tx_av_chunks); }
net/dccp/timer.c +1 -1
@@ -252,12 +252,12 @@ static void dccp_write_xmitlet(unsignedelse dccp_write_xmit (sk);bh_unlock_sock (sk); +sock_put (sk); }static void dccp_write_xmit_timer (unsigned long data) {dccp_write_xmitlet (data); -sock_put ((struct sock *)data); }void dccp_init_xmit_timers (struct sock *sk)
PATCH 262/366 sched/autogroup: Fix 64-bit kernel nice level adjustment
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mike Galbraith <[email protected]>
commit 83929cce95251cc77e5659bf493bd424ae0e7a67 upstream.
Michael Kerrisk reported:
Quoted 3 lines
Regarding the previous paragraph... My tests indicate that writing *any* value to the autogroup [nice priority level] file causes the task group to get a lower priority.
Because autogroup didn't call the then meaningless scale_load()...
Autogroup nice level adjustment has been broken ever since load resolution was increased for 64-bit kernels. Use scale_load() to scale group weight.
Michael Kerrisk tested this patch to fix the problem:
Quoted 7 lines
Applied and tested against 4.9-rc6 on an Intel u7 (4 cores). Test setup:
Terminal window 1: running 40 CPU burner jobs
Terminal window 2: running 40 CPU burner jobs
Terminal window 1: running 1 CPU burner job
Quoted 8 lines
Demonstrated that:
* Writing "0" to the autogroup file for TW1 now causes no change to the rate at which the process on the terminal consume CPU.
* Writing -20 to the autogroup file for TW1 caused those processes to get the lion's share of CPU while TW2 TW3 get a tiny amount.
* Writing -20 to the autogroup files for TW1 and TW3 allowed the process on TW3 to get as much CPU as it was getting as when the autogroup nice values for both terminals were 0.
--- kernel/sched/auto_group.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/auto_group.c +3 -1
@@ -197,6 +197,7 @@ int proc_sched_autogroup_set_nice(struct {static unsigned long next =INITIAL_JIFFIES ;struct autogroup *ag; +unsigned long shares;int err;if (nice <MIN_NICE || nice >MAX_NICE )
@@ -215,9 +216,10 @@ int proc_sched_autogroup_set_nice(struct next =HZ /10 + jiffies; ag =autogroup_task_get (p); + shares =scale_load (prio_to_weight[nice +20 ]);down_write (&ag->lock); - err =sched_group_set_shares (ag->tg, prio_to_weight[nice +20 ]); + err =sched_group_set_shares (ag->tg, shares);if (!err) ag->nice = nice;up_write (&ag->lock);
PATCH 272/366 s390/cpum_sf: ensure sample frequency of perf event attributes is non-zero
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hendrik Brueckner <[email protected]>
commit 4bbaf2584b86b0772413edeac22ff448f36351b1 upstream.
Correct a trinity finding for the perf_event_open() system call with a perf event attribute structure that uses a frequency but has the sampling frequency set to zero. This causes a FP divide exception during the sample rate initialization for the hardware sampling facility.
--- arch/s390/kernel/perf_cpum_sf.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/s390/kernel/perf_cpum_sf.c +4 -0
@@ -744,6 +744,10 @@ static int __hw_perf_event_init(struct p*/ rate =0 ;if (attr->freq) { +if (!attr->sample_freq) { + err = -EINVAL ; + goto out; + } rate =freq_to_sample_rate (&si, attr->sample_freq); rate =hw_limit_rate (&si, rate); attr->freq =0 ;
PATCH 274/366 RDMA/mlx5: Don't assume that medium blueFlame register exists
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Yishai Hadas <[email protected]>
commit 18b0362e87dfa09e355093b897b9db854e360d28 upstream.
User can leave system without medium BlueFlames registers, however the code assumed that at least one such register exists.
This patch fixes that assumption.
[bwh: Backported to 3.16:
- s/bfreg/uuar/g
- Neither alloc_med_class_uuar() nor num_med_uuar() takes a mlx5_ib_dev pointer, so first_med_uuar() doesn't need to take one
- Adjust context]
--- drivers/infiniband/hw/mlx5/qp.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +10 -7
@@ -356,11 +356,6 @@ static int qp_has_rq(struct ib_qp_init_areturn 1 ; } -static int first_med_uuar (void ) -{ -return 1 ; -} -static int next_uuar (int n) { n++;
@@ -395,6 +390,11 @@ static int max_uuari(struct mlx5_uuar_inreturn uuari->num_uars *4 ; } +static int first_med_uuar (struct mlx5_uuar_info *uuari) +{ +return num_med_uuar (uuari) ?1 : -ENOMEM ; +} +static int first_hi_uuar (struct mlx5_uuar_info *uuari) {int med;
@@ -420,10 +420,13 @@ static int alloc_high_class_uuar(structstatic int alloc_med_class_uuar (struct mlx5_uuar_info *uuari) { -int minidx =first_med_uuar (); +int minidx =first_med_uuar (uuari);int i; -for (i =first_med_uuar (); i <first_hi_uuar (uuari); i =next_uuar (i)) { +if (minidx <0 ) +return minidx; + +for (i = minidx; i <first_hi_uuar (uuari); i =next_uuar (i)) {if (uuari->count[i] < uuari->count[minidx]) minidx = i;if (!uuari->count[minidx])
PATCH 276/366 batman-adv: Avoid race in TT TVLV allocator helper
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 8ba0f9bd3bdea1058c2b2676bec7905724418e40 upstream.
The functions batadv_tt_prepare_tvlv_local_data and batadv_tt_prepare_tvlv_global_data are responsible for preparing a buffer which can be used to store the TVLV container for TT and add the VLAN information to it.
This will be done in three phases:
1. count the number of VLANs and their entries
2. allocate the buffer using the counters from the previous step and limits from the caller (parameter tt_len)
3. insert the VLAN information to the buffer
The step 1 and 3 operate on a list which contains the VLANs. The access to these lists must be protected with an appropriate lock or otherwise they might operate on on different entries. This could for example happen when another context is adding VLAN entries to this list.
This could lead to a buffer overflow in these functions when enough entries were added between step 1 and 3 to the VLAN lists that the buffer room for the entries (*tt_change) is smaller then the now required extra buffer for new VLAN entries.
--- net/batman-adv/translation-table.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +4 -4
@@ -718,7 +718,7 @@ batadv_tt_prepare_tvlv_global_data(strucstruct batadv_orig_node_vlan *vlan;uint8_t *tt_change_ptr; -rcu_read_lock (); +spin_lock_bh (&orig_node->vlan_list_lock);list_for_each_entry_rcu (vlan, &orig_node->vlan_list, list) { num_vlan++; num_entries +=atomic_read (&vlan->tt.num_entries);
@@ -756,7 +756,7 @@ batadv_tt_prepare_tvlv_global_data(struc *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: -rcu_read_unlock (); +spin_unlock_bh (&orig_node->vlan_list_lock);return tvlv_len; }
@@ -790,7 +790,7 @@ batadv_tt_prepare_tvlv_local_data(structuint8_t *tt_change_ptr;int change_offset; -rcu_read_lock (); +spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry_rcu (vlan, &bat_priv->softif_vlan_list, list) { num_vlan++; num_entries +=atomic_read (&vlan->tt.num_entries);
@@ -828,7 +828,7 @@ batadv_tt_prepare_tvlv_local_data(struct *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: -rcu_read_unlock (); +spin_unlock_bh (&bat_priv->softif_vlan_list_lock);return tvlv_len; }
PATCH 277/366 net/mlx4_en: Verify coalescing parameters are in range
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Moshe Shemesh <[email protected]>
commit 6ad4e91c6d796b38a7f0e724db1de28eeb122bad upstream.
Add check of coalescing parameters received through ethtool are within range of values supported by the HW.
Driver gets the coalescing rx/tx-usecs and rx/tx-frames as set by the users through ethtool. The ethtool support up to 32 bit value for each. However, mlx4 modify cq limits the coalescing time parameter and coalescing frames parameters to 16 bits.
Return out of range error if user tries to set these parameters to higher values.
Change type of sample-interval and adaptive_rx_coal parameters in mlx4 driver to u32 as the ethtool holds them as u32 and these parameters are not limited due to mlx4 HW.
--- drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 16 ++++++++++++++++ drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +16 -0
@@ -441,6 +441,22 @@ static int mlx4_en_set_coalesce(struct nif (!coal->tx_max_coalesced_frames_irq)return -EINVAL ; +if (coal->tx_coalesce_usecs >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs_low >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs_high >MLX4_EN_MAX_COAL_TIME ) { +netdev_info (dev,"%s: maximum coalesce time supported is %d usecs\n" , + __func__,MLX4_EN_MAX_COAL_TIME ); +return -ERANGE ; + } + +if (coal->tx_max_coalesced_frames >MLX4_EN_MAX_COAL_PKTS || + coal->rx_max_coalesced_frames >MLX4_EN_MAX_COAL_PKTS ) { +netdev_info (dev,"%s: maximum coalesced frames supported is %d\n" , + __func__,MLX4_EN_MAX_COAL_PKTS ); +return -ERANGE ; + } + priv->rx_frames = (coal->rx_max_coalesced_frames ==MLX4_EN_AUTO_CONF ) ? MLX4_EN_RX_COAL_TARGET :
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +5 -2
@@ -136,6 +136,9 @@ enum {#define MLX4_EN_TX_COAL_PKTS 16#define MLX4_EN_TX_COAL_TIME 0x10 +#define MLX4_EN_MAX_COAL_PKTS U16_MAX +#define MLX4_EN_MAX_COAL_TIME U16_MAX +#define MLX4_EN_RX_RATE_LOW 400000#define MLX4_EN_RX_COAL_TIME_LOW 0#define MLX4_EN_RX_RATE_HIGH 450000
@@ -522,8 +525,8 @@ struct mlx4_en_priv {u16 rx_usecs_low;u32 pkt_rate_high;u16 rx_usecs_high; -u16 sample_interval; -u16 adaptive_rx_coal; +u32 sample_interval; +u32 adaptive_rx_coal;u32 msg_enable;u32 loopback_ok;u32 validate_loopback;
PATCH 278/366 smb3: directory sync should not return an error
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Steve French <[email protected]>
commit 6e70c267e68d77679534dcf4aaf84e66f2cf1425 upstream.
As with NFS, which ignores sync on directory handles, fsync on a directory handle is a noop for CIFS/SMB3. Do not return an error on it. It breaks some database apps otherwise.
--- fs/cifs/cifsfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/cifs/cifsfs.c +13 -0
@@ -899,6 +899,18 @@ const struct inode_operations cifs_symli#endif }; +/* +* Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync() +* is a dummy operation. +*/ +static int cifs_dir_fsync (struct file *file,loff_t start,loff_t end,int datasync) +{ +cifs_dbg (FYI ,"Sync directory - name: %pD datasync: 0x%x\n" , + file, datasync); + +return 0 ; +} +const struct file_operations cifs_file_ops = { .read = new_sync_read, .write = new_sync_write,
@@ -1018,6 +1030,7 @@ const struct file_operations cifs_dir_op .read = generic_read_dir, .unlocked_ioctl = cifs_ioctl, .llseek = generic_file_llseek, + .fsync = cifs_dir_fsync, }; static void
PATCH 280/366 ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Ignatov <[email protected]>
commit 1b97013bfb11d66f041de691de6f0fec748ce016 upstream.
Fix more memory leaks in ip_cmsg_send() callers. Part of them were fixed earlier in 919483096bfe.
* udp_sendmsg one was there since the beginning when linux sources were first added to git;
* ping_v4_sendmsg one was copy/pasted in c319b4d76b9e.
Whenever return happens in udp_sendmsg() or ping_v4_sendmsg() IP options have to be freed if they were allocated previously.
Add label so that future callers (if any) can use it instead of kfree() before return that is easy to forget.
--- net/ipv4/ping.c | 7 +++++-- net/ipv4/udp.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-)
net/ipv4/ping.c +5 -2
@@ -779,8 +779,10 @@ static int ping_v4_sendmsg(struct kiocb ipc.addr = faddr = daddr;if (ipc.opt && ipc.opt->opt.srr) { -if (!daddr) -return -EINVAL ; +if (!daddr) { + err = -EINVAL ; + goto out_free; + } faddr = ipc.opt->opt.faddr; } tos =get_rttos (&ipc, inet);
@@ -845,6 +847,7 @@ back_from_confirm: out:ip_rt_put (rt); +out_free:if (free)kfree (ipc.opt);if (!err) {
net/ipv4/udp.c +5 -2
@@ -997,8 +997,10 @@ int udp_sendmsg(struct kiocb *iocb, stru ipc.addr = faddr = daddr;if (ipc.opt && ipc.opt->opt.srr) { -if (!daddr) -return -EINVAL ; +if (!daddr) { + err = -EINVAL ; + goto out_free; + } faddr = ipc.opt->opt.faddr; connected =0 ; }
@@ -1103,6 +1105,7 @@ do_append_data: out:ip_rt_put (rt); +out_free:if (free)kfree (ipc.opt);if (!err)
PATCH 281/366 Btrfs: ensure tmpfile inode is always persisted with link count of 0
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 5762b5c958abbecb7fb9f4596a6476d1ce91ecf6 upstream.
If we open a file with O_TMPFILE, don't do any further operation on it (so that the inode item isn't updated) and then force a transaction commit, we get a persisted inode item with a link count of 1, and not 0 as it should be.
Steps to reproduce it (requires a modern xfs_io with -T support):
$ mkfs.btrfs -f /dev/sdd
$ mount -o /dev/sdd /mnt
$ xfs_io -T /mnt &
$ syncThen btrfs-debug-tree shows the inode item with a link count of 1:
$ btrfs-debug-tree /dev/sdd
(...)
fs tree key (FS_TREE ROOT_ITEM 0)
leaf 29556736 items 4 free space 15851 generation 6 owner 5
fs uuid f164d01b-1b92-481d-a4e4-435fb0f843d0
chunk uuid 0e3d0e56-bcca-4a1c-aa5f-cec2c6f4f7a6
item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
inode generation 3 transid 6 size 0 block group 0 mode 40755 links 1
item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
inode ref index 0 namelen 2 name: ..
item 2 key (257 INODE_ITEM 0) itemoff 15951 itemsize 160
inode generation 6 transid 6 size 0 block group 0 mode 100600 links 1
item 3 key (ORPHAN ORPHAN_ITEM 257) itemoff 15951 itemsize 0
orphan item
checksum tree key (CSUM_TREE ROOT_ITEM 0)
(...)--- fs/btrfs/inode.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/btrfs/inode.c +15 -0
@@ -5731,6 +5731,13 @@ static struct inode *btrfs_new_inode(str }/* +* O_TMPFILE, set link count to 0, so that after this point, +* we fill in an inode item with the correct link count. +*/ +if (!name) +set_nlink (inode,0 ); + +/* * we have to initialize this early, so we can reclaim the inode * number if we fail afterwards in this function. */
@@ -9096,6 +9103,14 @@ static int btrfs_tmpfile(struct inode *dif (ret) goto out; +/* +* We set number of links to 0 in btrfs_new_inode(), and here we set +* it to 1 because d_tmpfile() will issue a warning if the count is 0, +* through: +* +* d_tmpfile() -> inode_dec_link_count() -> drop_nlink() +*/ +set_nlink (inode,1 );d_tmpfile (dentry, inode);mark_inode_dirty (inode);
PATCH 283/366 Btrfs: don't leave dangling dentry if symlink creation failed
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit d50866d00fb39fcf72307001763ee9cc92625a43 upstream.
When we are creating a symlink we might fail with an error after we created its inode and added the corresponding directory indexes to its parent inode. In this case we end up never removing the directory indexes because the inode eviction handler, called for our symlink inode on the final iput(), only removes items associated with the symlink inode and not with the parent inode.
Example:
$ mkfs.btrfs -f /dev/sdi $ mount /dev/sdi /mnt $ touch /mnt/foo $ ln -s /mnt/foo /mnt/bar ln: failed to create symbolic link ‘bar’: Cannot allocate memory $ umount /mnt $ btrfsck /dev/sdi Checking filesystem on /dev/sdi UUID: d5acb5ba-31bd-42da-b456-89dca2e716e1 checking extents checking free space cache checking fs roots root 5 inode 258 errors 2001, no inode item, link count wrong unresolved ref dir 256 index 3 namelen 3 name bar filetype 7 errors 4, no inode ref found 131073 bytes used err is 1 total csum bytes: 0 total tree bytes: 131072 total fs tree bytes: 32768 total extent tree bytes: 16384 btree space waste bytes: 124305 file data blocks allocated: 262144 referenced 262144 btrfs-progs v4.2.3
So fix this by adding the directory index entries as the very last step of symlink creation.
--- fs/btrfs/inode.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +7 -4
@@ -8877,10 +8877,6 @@ static int btrfs_symlink(struct inode *dif (err) goto out_unlock_inode; - err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index); -if (err) - goto out_unlock_inode; - path =btrfs_alloc_path ();if (!path) { err = -ENOMEM ;
@@ -8918,6 +8914,13 @@ static int btrfs_symlink(struct inode *dinode_set_bytes (inode, name_len);btrfs_i_size_write (inode, name_len); err =btrfs_update_inode (trans, root, inode); +/* +* Last step, add directory indexes for our symlink inode. This is the +* last step to avoid extra cleanup of these indexes if an error happens +* elsewhere above. +*/ +if (!err) + err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index);if (err) { drop_inode =1 ; goto out_unlock_inode;
PATCH 286/366 f2fs: go out for insert_inode_locked failure
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jaegeuk Kim <[email protected]>
commit a21c20f0c812925085204fced932ac95f2a76bf0 upstream.
We should not call unlock_new_inode when insert_inode_locked failed.
--- fs/f2fs/namei.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/f2fs/namei.c +1 -4
@@ -52,15 +52,12 @@ static struct inode *f2fs_new_inode(struif (err) { err = -EINVAL ; nid_free = true; - goto out; + goto fail; }trace_f2fs_new_inode (inode,0 );mark_inode_dirty (inode);return inode; -out: -clear_nlink (inode); -unlock_new_inode (inode); fail:trace_f2fs_new_inode (inode, err);make_bad_inode (inode);
PATCH 289/366 udf: fix the udf_iget() vs. udf_new_inode() races
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit b231509616feb911c2a7a8814d58c0014ef5b17f upstream.
Currently udf_iget() (triggered by NFS) can race with udf_new_inode() leading to two inode structures with the same inode number:
nfsd: iget_locked() creates inode
nfsd: try to read from disk, block on that. udf_new_inode(): allocate inode with that inumber udf_new_inode(): insert it into icache, set it up and dirty udf_write_inode(): write inode into buffer cache
nfsd: get CPU again, look into buffer cache, see nice and sane on-disk
inode, set the in-core inode from it
Fix the problem by putting inode into icache in locked state (I_NEW set) and unlocking it only after it's fully set up.
--- fs/udf/ialloc.c | 7 ++++++- fs/udf/namei.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/udf/ialloc.c +6 -1
@@ -123,7 +123,12 @@ struct inode *udf_new_inode(struct inode iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; inode->i_mtime = inode->i_atime = inode->i_ctime = iinfo->i_crtime =current_fs_time (inode->i_sb); -insert_inode_hash (inode); +if (unlikely (insert_inode_locked (inode) <0 )) { +make_bad_inode (inode); +iput (inode); + *err = -EIO ; +return NULL ; + }mark_inode_dirty (inode); *err =0 ;
fs/udf/namei.c +7 -0
@@ -562,6 +562,7 @@ static int udf_add_nondir(struct dentry fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err);if (unlikely (!fi)) {inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode);return err; }
@@ -575,6 +576,7 @@ static int udf_add_nondir(struct dentryif (fibh.sbh != fibh.ebh)brelse (fibh.ebh);brelse (fibh.sbh); +unlock_new_inode (inode);d_instantiate (dentry, inode);return 0 ;
@@ -622,6 +624,7 @@ static int udf_tmpfile(struct inode *dirmark_inode_dirty (inode);d_tmpfile (dentry, inode); +unlock_new_inode (inode);return 0 ; }
@@ -663,6 +666,7 @@ static int udf_mkdir(struct inode *dir, fi =udf_add_entry (inode,NULL , &fibh, &cfi, &err);if (!fi) {inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); goto out; }
@@ -681,6 +685,7 @@ static int udf_mkdir(struct inode *dir,if (!fi) {clear_nlink (inode);mark_inode_dirty (inode); +unlock_new_inode (inode);iput (inode); goto out; }
@@ -692,6 +697,7 @@ static int udf_mkdir(struct inode *dir,udf_write_fi (dir, &cfi, fi, &fibh,NULL ,NULL );inc_nlink (dir);mark_inode_dirty (dir); +unlock_new_inode (inode);d_instantiate (dentry, inode);if (fibh.sbh != fibh.ebh)brelse (fibh.ebh);
@@ -999,6 +1005,7 @@ out: out_no_entry:up_write (&iinfo->i_data_sem);inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); goto out; }
PATCH 294/366 batman-adv: Fix TT sync flags for intermediate TT responses
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Linus Lüssing <[email protected]>
commit 7072337e52b3e9d5460500d8dc9cbc1ba2db084c upstream.
The previous TT sync fix so far only fixed TT responses issued by the target node directly. So far, TT responses issued by intermediate nodes still lead to the wrong flags being added, leading to CRC mismatches.
This behaviour was observed at Freifunk Hannover in a 800 nodes setup where a considerable amount of nodes were still infected with 'WI' TT flags even with (most) nodes having the previous TT sync fix applied.
I was able to reproduce the issue with intermediate TT responses in a four node test setup and this patch fixes this issue by ensuring to use the per originator instead of the summarized, OR'd ones.
[bwh: Backported to 3.16:
- Drop inapplicable comment changes
- Change return types of batadv_tt_{local,global}_valid() to bool, done as part of a larger conversion upstream
- Adjust context]
---
net/batman-adv/translation-table.c +54 -14
@@ -1219,7 +1219,8 @@ batadv_tt_global_orig_entry_find(const s*/ static bool batadv_tt_global_entry_has_orig (const struct batadv_tt_global_entry *entry, -const struct batadv_orig_node *orig_node) +const struct batadv_orig_node *orig_node, +u8 *flags) {struct batadv_tt_orig_list_entry *orig_entry;bool found = false;
@@ -1227,6 +1228,10 @@ batadv_tt_global_entry_has_orig(const st orig_entry =batadv_tt_global_orig_entry_find (entry, orig_node);if (orig_entry) { found = true; + +if (flags) + *flags = orig_entry->flags; +batadv_tt_orig_list_entry_free_ref (orig_entry); }
@@ -1403,7 +1408,7 @@ static bool batadv_tt_global_add(structif (!(common->flags &BATADV_TT_CLIENT_TEMP )) goto out;if (batadv_tt_global_entry_has_orig (tt_global_entry, - orig_node)) + orig_node,NULL )) goto out_remove;batadv_tt_global_del_orig_list (tt_global_entry); goto add_orig_entry;
@@ -2311,23 +2316,46 @@ unlock: }/** -* batadv_tt_local_valid - verify that given tt entry is a valid one +* batadv_tt_local_valid() - verify local tt entry and get flags * @entry_ptr: to be checked local tt entry * @data_ptr: not used but definition required to satisfy the callback prototype +* @flags: a pointer to store TT flags for this client to * -* Returns 1 if the entry is a valid, 0 otherwise. +* Checks the validity of the given local TT entry. If it is, then the provided +* flags pointer is updated. +* +* Return: true if the entry is a valid, false otherwise. */ -static int batadv_tt_local_valid (const void *entry_ptr,const void *data_ptr) +static bool batadv_tt_local_valid (const void *entry_ptr, +const void *data_ptr, +u8 *flags) {const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;if (tt_common_entry->flags &BATADV_TT_CLIENT_NEW ) -return 0 ; -return 1 ; +return false; + +if (flags) + *flags = tt_common_entry->flags; + +return true; } -static int batadv_tt_global_valid (const void *entry_ptr, -const void *data_ptr) +/** +* batadv_tt_global_valid() - verify global tt entry and get flags +* @entry_ptr: to be checked global tt entry +* @data_ptr: an orig_node object (may be NULL) +* @flags: a pointer to store TT flags for this client to +* +* Checks the validity of the given global TT entry. If it is, then the provided +* flags pointer is updated either with the common (summed) TT flags if data_ptr +* is NULL or the specific, per originator TT flags otherwise. +* +* Return: true if the entry is a valid, false otherwise. +*/ +static bool batadv_tt_global_valid (const void *entry_ptr, +const void *data_ptr, +u8 *flags) {const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;const struct batadv_tt_global_entry *tt_global_entry;
@@ -2341,7 +2369,8 @@ static int batadv_tt_global_valid(const struct batadv_tt_global_entry, common); -return batadv_tt_global_entry_has_orig (tt_global_entry, orig_node); +return batadv_tt_global_entry_has_orig (tt_global_entry, orig_node, + flags); }/**
@@ -2351,24 +2380,34 @@ static int batadv_tt_global_valid(const* @hash: hash table containing the tt entries * @tt_len: expected tvlv tt data buffer length in number of bytes * @tvlv_buff: pointer to the buffer to fill with the TT data -* @valid_cb: function to filter tt change entries +* @valid_cb: function to filter tt change entries and to return TT flags * @cb_data: data passed to the filter function as argument +* +* Fills the tvlv buff with the tt entries from the specified hash. If valid_cb +* is not provided then this becomes a no-op. */ static void batadv_tt_tvlv_generate (struct batadv_priv *bat_priv,struct batadv_hashtable *hash,void *tvlv_buff,uint16_t tt_len, -int (*valid_cb)(const void *,const void *), +bool (*valid_cb)(const void *, +const void *, +u8 *flags),void *cb_data) {struct batadv_tt_common_entry *tt_common_entry;struct batadv_tvlv_tt_change *tt_change;struct hlist_head *head;uint16_t tt_tot, tt_num_entries =0 ; +u8 flags; +bool ret;uint32_t i; tt_tot =batadv_tt_entries (tt_len); tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff; +if (!valid_cb) +return ; +rcu_read_lock ();for (i =0 ; i < hash->size; i++) { head = &hash->table[i];
@@ -2378,11 +2417,12 @@ static void batadv_tt_tvlv_generate(struif (tt_tot == tt_num_entries)break ; -if ((valid_cb) && (!valid_cb (tt_common_entry, cb_data))) + ret =valid_cb (tt_common_entry, cb_data, &flags); +if (!ret)continue ;ether_addr_copy (tt_change->addr, tt_common_entry->addr); - tt_change->flags = tt_common_entry->flags; + tt_change->flags = flags; tt_change->vid =htons (tt_common_entry->vid);memset (tt_change->reserved,0 ,sizeof (tt_change->reserved));
PATCH 296/366 ALSA: control: fix a redundant-copy issue
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wenwen Wang <[email protected]>
commit 3f12888dfae2a48741c4caa9214885b3aaf350f9 upstream.
In snd_ctl_elem_add_compat(), the fields of the struct 'data' need to be copied from the corresponding fields of the struct 'data32' in userspace. This is achieved by invoking copy_from_user() and get_user() functions. The problem here is that the 'type' field is copied twice. One is by copy_from_user() and one is by get_user(). Given that the 'type' field is not used between the two copies, the second copy is *completely* redundant and should be removed for better performance and cleanup. Also, these two copies can cause inconsistent data: as the struct 'data32' resides in userspace and a malicious userspace process can race to change the 'type' field between the two copies to cause inconsistent data. Depending on how the data is used in the future, such an inconsistency may cause potential security risks.
For above reasons, we should take out the second copy.
--- sound/core/control_compat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/core/control_compat.c +1 -2
@@ -400,8 +400,7 @@ static int snd_ctl_elem_add_compat(strucif (copy_from_user (&data->id, &data32->id,sizeof (data->id)) ||copy_from_user (&data->type, &data32->type,3 *sizeof (u32))) goto error; -if (get_user (data->owner, &data32->owner) || -get_user (data->type, &data32->type)) +if (get_user (data->owner, &data32->owner)) goto error;switch (data->type) {case SNDRV_CTL_ELEM_TYPE_BOOLEAN :
PATCH 297/366 ALSA: usb: mixer: volume quirk for CM102-A+/102S+
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Federico Cuello <[email protected]>
commit 21493316a3c4598f308d5a9fa31cc74639c4caff upstream.
Currently it's not possible to set volume lower than 26% (it just mutes).
Also fixes this warning:
Warning! Unlikely big volume range (=9472), cval->res is probably wrong.
[13] FU [PCM Playback Volume] ch = 2, val = -9473/-1/1
, and volume works fine for full range.
--- sound/usb/mixer.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/usb/mixer.c +8 -0
@@ -885,6 +885,14 @@ static void volume_control_quirks(struct }break ; +case USB_ID (0x0d8c ,0x0103 ): +if (!strcmp (kctl->id.name,"PCM Playback Volume" )) { +usb_audio_info (chip, +"set volume quirk for CM102-A+/102S+\n" ); + cval->min =-256 ; + } +break ; +case USB_ID (0x0471 ,0x0101 ):case USB_ID (0x0471 ,0x0104 ):case USB_ID (0x0471 ,0x0105 ):
PATCH 299/366 efi: Avoid potential crashes, fix the 'struct efi_pci_io_protocol_32' definition for mixed mode
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
commit 0b3225ab9407f557a8e20f23f37aa7236c10a9b1 upstream.
Mixed mode allows a kernel built for x86_64 to interact with 32-bit EFI firmware, but requires us to define all struct definitions carefully when it comes to pointer sizes.
'struct efi_pci_io_protocol_32' currently uses a 'void *' for the 'romimage' field, which will be interpreted as a 64-bit field on such kernels, potentially resulting in bogus memory references and subsequent crashes.
--- arch/x86/boot/compressed/eboot.c | 6 ++++-- include/linux/efi.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/boot/compressed/eboot.c +4 -2
@@ -358,7 +358,8 @@ __setup_efi_pci32(efi_pci_io_protocol_32if (status !=EFI_SUCCESS ) goto free_struct; -memcpy (rom->romdata, pci->romimage, pci->romsize); +memcpy (rom->romdata, (void *)(unsigned long )pci->romimage, + pci->romsize);return status; free_struct:
@@ -460,7 +461,8 @@ __setup_efi_pci64(efi_pci_io_protocol_64if (status !=EFI_SUCCESS ) goto free_struct; -memcpy (rom->romdata, pci->romimage, pci->romsize); +memcpy (rom->romdata, (void *)(unsigned long )pci->romimage, + pci->romsize);return status; free_struct:
include/linux/efi.h +4 -4
@@ -368,8 +368,8 @@ typedef struct {u32 attributes;u32 get_bar_attributes;u32 set_bar_attributes; -uint64_t romsize; -void *romimage; +u64 romsize; +u32 romimage; } efi_pci_io_protocol_32; typedef struct {
@@ -388,8 +388,8 @@ typedef struct {u64 attributes;u64 get_bar_attributes;u64 set_bar_attributes; -uint64_t romsize; -void *romimage; +u64 romsize; +u64 romimage; } efi_pci_io_protocol_64; typedef struct {
PATCH 304/366 net/mlx4_core: Fix error handling in mlx4_init_port_info.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tarick Bedeir <[email protected]>
commit 57f6f99fdad9984801cde05c1db68fe39b474a10 upstream.
Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice.
In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup.
--- drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/main.c +3 -1
@@ -2048,6 +2048,7 @@ static int mlx4_init_port_info(struct mlif (err) {mlx4_err (dev,"Failed to create file for port %d\n" , port); info->port =-1 ; +return err; }sprintf (info->dev_mtu_name,"mlx4_port%d_mtu" , port);
@@ -2066,9 +2067,10 @@ static int mlx4_init_port_info(struct mlmlx4_err (dev,"Failed to create mtu file for port %d\n" , port);device_remove_file (&info->dev->pdev->dev, &info->port_attr); info->port =-1 ; +return err; } -return err; +return 0 ; }static void mlx4_cleanup_port_info (struct mlx4_port_info *info)
PATCH 307/366 KVM: Fix spelling mistake: "cop_unsuable" -> "cop_unusable"
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
commit ba3696e94d9d590d9a7e55f68e81c25dba515191 upstream.
Trivial fix to spelling mistake in debugfs_entries text.
--- arch/mips/kvm/kvm_mips.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kvm/kvm_mips.c +1 -1
@@ -38,7 +38,7 @@ struct kvm_stats_debugfs_item debugfs_en { "cache", VCPU_STAT(cache_exits) }, { "signal", VCPU_STAT(signal_exits) }, { "interrupt", VCPU_STAT(int_exits) }, - { "cop_unsuable", VCPU_STAT(cop_unusable_exits) }, + { "cop_unusable", VCPU_STAT(cop_unusable_exits) }, { "tlbmod", VCPU_STAT(tlbmod_exits) }, { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits) }, { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits) },
PATCH 312/366 vmxnet3: set the DMA mask before the first DMA map operation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "[email protected]" <[email protected]>
commit 61aeecea40afb2b89933e27cd4adb10fc2e75cfd upstream.
The DMA mask must be set before, not after, the first DMA map operation, or the first DMA map operation could in theory fail on some systems.
[bwh: Backported to 3.16: Bump version from 1.2.1.0-k to 1.2.2.0-k, which
wasn't used in mainline]
--- drivers/net/vmxnet3/vmxnet3_drv.c | 50 +++++++++++++++---------------- drivers/net/vmxnet3/vmxnet3_int.h | 8 +++-- 2 files changed, 30 insertions(+), 28 deletions(-)
drivers/net/vmxnet3/vmxnet3_drv.c +25 -25
@@ -2445,7 +2445,7 @@ vmxnet3_set_mac_addr(struct net_device */* ==================== initialization and cleanup routines ============ */ static int -vmxnet3_alloc_pci_resources (struct vmxnet3_adapter *adapter,bool *dma64) +vmxnet3_alloc_pci_resources (struct vmxnet3_adapter *adapter) {int err;unsigned long mmio_start, mmio_len;
@@ -2457,30 +2457,12 @@ vmxnet3_alloc_pci_resources(struct vmxnereturn err; } -if (pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) ==0 ) { -if (pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 ) { -dev_err (&pdev->dev, -"pci_set_consistent_dma_mask failed\n" ); - err = -EIO ; - goto err_set_mask; - } - *dma64 = true; - }else { -if (pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 ) { -dev_err (&pdev->dev, -"pci_set_dma_mask failed\n" ); - err = -EIO ; - goto err_set_mask; - } - *dma64 = false; - } - err =pci_request_selected_regions (pdev, (1 <<2 ) -1 , vmxnet3_driver_name);if (err) {dev_err (&pdev->dev,"Failed to request region for adapter: error %d\n" , err); - goto err_set_mask; + goto err_enable_device; }pci_set_master (pdev);
@@ -2508,7 +2490,7 @@ err_bar1:iounmap (adapter->hw_addr0); err_ioremap:pci_release_selected_regions (pdev, (1 <<2 ) -1 ); -err_set_mask: +err_enable_device:pci_disable_device (pdev);return err; }
@@ -2973,7 +2955,7 @@ vmxnet3_probe_device(struct pci_dev *pde#endif };int err; -bool dma64 = false;/* stupid gcc */ +bool dma64;u32 ver;struct net_device *netdev;struct vmxnet3_adapter *adapter;
@@ -3018,6 +3000,24 @@ vmxnet3_probe_device(struct pci_dev *pde adapter->tx_ring_size =VMXNET3_DEF_TX_RING_SIZE ; adapter->rx_ring_size =VMXNET3_DEF_RX_RING_SIZE ; +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) ==0 ) { +if (pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )) !=0 ) { +dev_err (&pdev->dev, +"pci_set_consistent_dma_mask failed\n" ); + err = -EIO ; + goto err_set_mask; + } + dma64 = true; + }else { +if (pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )) !=0 ) { +dev_err (&pdev->dev, +"pci_set_dma_mask failed\n" ); + err = -EIO ; + goto err_set_mask; + } + dma64 = false; + } +spin_lock_init (&adapter->cmd_lock); adapter->adapter_pa = dma_map_single(&adapter->pdev->dev, adapter, sizeof(struct vmxnet3_adapter),
@@ -3025,7 +3025,7 @@ vmxnet3_probe_device(struct pci_dev *pdeif (dma_mapping_error (&adapter->pdev->dev, adapter->adapter_pa)) {dev_err (&pdev->dev,"Failed to map dma\n" ); err = -EFAULT ; - goto err_dma_map; + goto err_set_mask; } adapter->shared = dma_alloc_coherent( &adapter->pdev->dev,
@@ -3076,7 +3076,7 @@ vmxnet3_probe_device(struct pci_dev *pde }#endif /* VMXNET3_RSS */ - err =vmxnet3_alloc_pci_resources (adapter, &dma64); + err =vmxnet3_alloc_pci_resources (adapter);if (err <0 ) goto err_alloc_pci;
@@ -3180,7 +3180,7 @@ err_alloc_queue_desc: err_alloc_shared:dma_unmap_single (&adapter->pdev->dev, adapter->adapter_pa,sizeof (struct vmxnet3_adapter ),PCI_DMA_TODEVICE ); -err_dma_map: +err_set_mask:free_netdev (netdev);return err; }
drivers/net/vmxnet3/vmxnet3_int.h +5 -3
@@ -69,10 +69,12 @@/* * Version numbers */ -#define VMXNET3_DRIVER_VERSION_STRING "1.2.1.0-k" +#define VMXNET3_DRIVER_VERSION_STRING "1.2.2.0-k" -/* a 32-bit int, each byte encode a verion number in VMXNET3_DRIVER_VERSION */ -#define VMXNET3_DRIVER_VERSION_NUM 0x01020100 +/* Each byte of this 32-bit integer encodes a version number in +* VMXNET3_DRIVER_VERSION_STRING. +*/ +#define VMXNET3_DRIVER_VERSION_NUM 0x01020200#if defined(CONFIG_PCI_MSI )/* RSS only makes sense if MSI-X is supported. */
PATCH 314/366 drm: set FMODE_UNSIGNED_OFFSET for drm files
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dave Airlie <[email protected]>
commit 76ef6b28ea4f81c3d511866a9b31392caa833126 upstream.
Since we have the ttm and gem vma managers using a subset of the file address space for objects, and these start at 0x100000000 they will overflow the new mmap checks.
I've checked all the mmap routines I could see for any bad behaviour but overall most people use GEM/TTM VMA managers even the legacy drivers have a hashtable.
--- drivers/gpu/drm/drm_fops.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_fops.c +1 -0
@@ -251,6 +251,7 @@ static int drm_open_helper(struct file *return -ENOMEM ; filp->private_data = priv; + filp->f_mode |=FMODE_UNSIGNED_OFFSET ; priv->filp = filp; priv->uid =current_euid (); priv->pid =get_pid (task_pid (current));
PATCH 321/366 ARM: davinci: board-dm646x-evm: set VPIF capture card name
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sekhar Nori <[email protected]>
commit bb7298a7e87cf3430eb62be8746e5d7a07ca9d7c upstream.
VPIF capture driver expects card name to be set since it uses it without checking for NULL. The commit which introduced VPIF display and capture support added card name only for display, not for capture.
Set it in platform data to probe driver successfully.
While at it, also fix the display card name to something more appropriate.
--- arch/arm/mach-davinci/board-dm646x-evm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-davinci/board-dm646x-evm.c +2 -1
@@ -541,7 +541,7 @@ static struct vpif_display_config dm646x .outputs = dm6467_ch0_outputs, .output_count = ARRAY_SIZE(dm6467_ch0_outputs), }, - .card_name = "DM646x EVM", + .card_name = "DM646x EVM Video Display", };/**
@@ -699,6 +699,7 @@ static struct vpif_capture_config dm646x .fid_pol = 0, }, }, + .card_name = "DM646x EVM Video Capture", };static void __init evm_init_video (void )
PATCH 322/366 tick/broadcast: Use for_each_cpu() specially on UP kernels
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dexuan Cui <[email protected]>
commit 5596fe34495cf0f645f417eb928ef224df3e3cb4 upstream.
for_each_cpu() unintuitively reports CPU0 as set independent of the actual cpumask content on UP kernels. This causes an unexpected PIT interrupt storm on a UP kernel running in an SMP virtual machine on Hyper-V, and as a result, the virtual machine can suffer from a strange random delay of 1~20 minutes during boot-up, and sometimes it can hang forever.
Protect if by checking whether the cpumask is empty before entering the for_each_cpu() loop.
[ tglx: Use !IS_ENABLED(CONFIG_SMP) instead of #ifdeffery ]
--- kernel/time/tick-broadcast.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/time/tick-broadcast.c +8 -0
@@ -585,6 +585,14 @@ again: now =ktime_get ();/* Find all expired events */ for_each_cpu (cpu, tick_broadcast_oneshot_mask) { +/* +* Required for !SMP because for_each_cpu() reports +* unconditionally CPU0 as set on UP kernels. +*/ +if (!IS_ENABLED (CONFIG_SMP ) && +cpumask_empty (tick_broadcast_oneshot_mask)) +break ; + td = &per_cpu (tick_cpu_device, cpu);if (td->evtdev->next_event.tv64 <= now.tv64) {cpumask_set_cpu (cpu, tmpmask);
PATCH 323/366 tcp: purge write queue in tcp_connect_init()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 7f582b248d0a86bae5788c548d7bb5bca6f7691a upstream.
syzkaller found a reliable way to crash the host, hitting a BUG() in __tcp_retransmit_skb()
Malicous MSG_FASTOPEN is the root cause. We need to purge write queue in tcp_connect_init() at the point we init snd_una/write_seq.
This patch also replaces the BUG() by a less intrusive WARN_ON_ONCE()
kernel BUG at net/ipv4/tcp_output.c:2837!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 0 PID: 5276 Comm: syz-executor0 Not tainted 4.17.0-rc3+ #51 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__tcp_retransmit_skb+0x2992/0x2eb0 net/ipv4/tcp_output.c:2837 RSP: 0000:ffff8801dae06ff8 EFLAGS: 00010206 RAX: ffff8801b9fe61c0 RBX: 00000000ffc18a16 RCX: ffffffff864e1a49 RDX: 0000000000000100 RSI: ffffffff864e2e12 RDI: 0000000000000005 RBP: ffff8801dae073a0 R08: ffff8801b9fe61c0 R09: ffffed0039c40dd2 R10: ffffed0039c40dd2 R11: ffff8801ce206e93 R12: 00000000421eeaad R13: ffff8801ce206d4e R14: ffff8801ce206cc0 R15: ffff8801cd4f4a80 FS: 0000000000000000(0000) GS:ffff8801dae00000(0063) knlGS:00000000096bc900 CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 CR2: 0000000020000000 CR3: 00000001c47b6000 CR4: 00000000001406f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <IRQ> tcp_retransmit_skb+0x2e/0x250 net/ipv4/tcp_output.c:2923 tcp_retransmit_timer+0xc50/0x3060 net/ipv4/tcp_timer.c:488 tcp_write_timer_handler+0x339/0x960 net/ipv4/tcp_timer.c:573 tcp_write_timer+0x111/0x1d0 net/ipv4/tcp_timer.c:593 call_timer_fn+0x230/0x940 kernel/time/timer.c:1326 expire_timers kernel/time/timer.c:1363 [inline] __run_timers+0x79e/0xc50 kernel/time/timer.c:1666 run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692 __do_softirq+0x2e0/0xaf5 kernel/softirq.c:285 invoke_softirq kernel/softirq.c:365 [inline] irq_exit+0x1d1/0x200 kernel/softirq.c:405 exiting_irq arch/x86/include/asm/apic.h:525 [inline] smp_apic_timer_interrupt+0x17e/0x710 arch/x86/kernel/apic/apic.c:1052 apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:863
--- net/ipv4/tcp_output.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/tcp_output.c +5 -2
@@ -2450,8 +2450,10 @@ int __tcp_retransmit_skb(struct sock *skreturn -EBUSY ;if (before (TCP_SKB_CB (skb)->seq, tp->snd_una)) { -if (before (TCP_SKB_CB (skb)->end_seq, tp->snd_una)) -BUG (); +if (unlikely (before (TCP_SKB_CB (skb)->end_seq, tp->snd_una))) { +WARN_ON_ONCE (1 ); +return -EINVAL ; + }if (tcp_trim_head (sk, skb, tp->snd_una -TCP_SKB_CB (skb)->seq))return -ENOMEM ; }
@@ -2948,6 +2950,7 @@ static void tcp_connect_init(struct socksock_reset_flag (sk,SOCK_DONE ); tp->snd_wnd =0 ;tcp_init_wl (tp,0 ); +tcp_write_queue_purge (sk); tp->snd_una = tp->write_seq; tp->snd_sml = tp->write_seq; tp->snd_up = tp->write_seq;
PATCH 324/366 afs: Ignore AFS_ACE_READ and AFS_ACE_WRITE for directories
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marc Dionne <[email protected]>
commit fd2498211a551fd42b2d6b9050d649d43536e75c upstream.
The AFS_ACE_READ and AFS_ACE_WRITE permission bits should not be used to make access decisions for the directory itself. They are meant to control access for the objects contained in that directory.
Reading a directory is allowed if the AFS_ACE_LOOKUP bit is set. This would cause an incorrect access denied error for a directory with AFS_ACE_LOOKUP but not AFS_ACE_READ.
The AFS_ACE_WRITE bit does not allow operations that modify the directory. For a directory with AFS_ACE_WRITE but neither AFS_ACE_INSERT nor AFS_ACE_DELETE, this would result in trying operations that would ultimately be denied by the server.
--- fs/afs/security.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/afs/security.c +2 -3
@@ -327,12 +327,11 @@ int afs_permission(struct inode *inode,if (!(access &AFS_ACE_LOOKUP )) goto permission_denied; }else if (mask &MAY_READ ) { -if (!(access &AFS_ACE_READ )) +if (!(access &AFS_ACE_LOOKUP )) goto permission_denied; }else if (mask &MAY_WRITE ) {if (!(access & (AFS_ACE_DELETE |/* rmdir, unlink, rename from */ -AFS_ACE_INSERT |/* create, mkdir, symlink, rename to */ -AFS_ACE_WRITE )))/* chmod */ +AFS_ACE_INSERT )))/* create, mkdir, symlink, rename to */ goto permission_denied; }else {BUG ();
PATCH 325/366 afs: Fix directory permissions check
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit 378831e4daec75fbba6d3612bcf3b4dd00ddbf08 upstream.
Doing faccessat("/afs/some/directory", 0) triggers a BUG in the permissions check code.
Fix this by just removing the BUG section. If no permissions are asked for, just return okay if the file exists.
Also:
(1) Split up the directory check so that it has separate if-statements rather than if-else-if (e.g. checking for MAY_EXEC shouldn't skip the check for MAY_READ and MAY_WRITE).
(2) Check for MAY_CHDIR as MAY_EXEC.
Without the main fix, the following BUG may occur:
kernel BUG at fs/afs/security.c:386!
invalid opcode: 0000 [#1] SMP PTI
...
RIP: 0010:afs_permission+0x19d/0x1a0 [kafs] ... Call Trace: ? inode_permission+0xbe/0x180 ? do_faccessat+0xdc/0x270 ? do_syscall_64+0x60/0x1f0 ? entry_SYSCALL_64_after_hwframe+0x49/0xbe
--- fs/afs/security.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
fs/afs/security.c +3 -7
@@ -323,18 +323,14 @@ int afs_permission(struct inode *inode, mask, access, S_ISDIR(inode->i_mode) ? "dir" : "file");if (S_ISDIR (inode->i_mode)) { -if (mask &MAY_EXEC ) { +if (mask & (MAY_EXEC |MAY_READ |MAY_CHDIR )) {if (!(access &AFS_ACE_LOOKUP )) goto permission_denied; - }else if (mask &MAY_READ ) { -if (!(access &AFS_ACE_LOOKUP )) - goto permission_denied; - }else if (mask &MAY_WRITE ) { + } +if (mask &MAY_WRITE ) {if (!(access & (AFS_ACE_DELETE |/* rmdir, unlink, rename from */ AFS_ACE_INSERT )))/* create, mkdir, symlink, rename to */ goto permission_denied; - }else { -BUG (); } }else {if (!(access &AFS_ACE_LOOKUP ))
PATCH 328/366 string: provide strscpy()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chris Metcalf <[email protected]>
commit 30035e45753b708e7d47a98398500ca005e02b86 upstream.
The strscpy() API is intended to be used instead of strlcpy(), and instead of most uses of strncpy().
- Unlike strlcpy(), it doesn't read from memory beyond (src + size).
- Unlike strlcpy() or strncpy(), the API provides an easy way to check for destination buffer overflow: an -E2BIG error return value.
- The provided implementation is robust in the face of the source buffer being asynchronously changed during the copy, unlike the current implementation of strlcpy().
- Unlike strncpy(), the destination buffer will be NUL-terminated if the string in the source buffer is too long.
- Also unlike strncpy(), the destination buffer will not be updated beyond the NUL termination, avoiding strncpy's behavior of zeroing the entire tail end of the destination buffer. (A memset() after the strscpy() can be used if this behavior is desired.)
- The implementation should be reasonably performant on all platforms since it uses the asm/word-at-a-time.h API rather than simple byte copy. Kernel-to-kernel string copy is not considered to be performance critical in any case.
--- include/linux/string.h | 3 ++ lib/string.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+)
include/linux/string.h +3 -0
@@ -25,6 +25,9 @@ extern char * strncpy(char *,const char#ifndef __HAVE_ARCH_STRLCPYsize_t strlcpy (char *,const char *,size_t );#endif +#ifndef __HAVE_ARCH_STRSCPY +ssize_t __must_check strscpy (char *,const char *,size_t ); +#endif #ifndef __HAVE_ARCH_STRCATextern char *strcat (char *,const char *);#endif
lib/string.c +88 -0
100 lines not on this page · raw message
PATCH 335/366 xen-swiotlb: fix the check condition for xen_swiotlb_free_coherent
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joe Jin <[email protected]>
commit 4855c92dbb7b3b85c23e88ab7ca04f99b9677b41 upstream.
When run raidconfig from Dom0 we found that the Xen DMA heap is reduced, but Dom Heap is increased by the same size. Tracing raidconfig we found that the related ioctl() in megaraid_sas will call dma_alloc_coherent() to apply memory. If the memory allocated by Dom0 is not in the DMA area, it will exchange memory with Xen to meet the requiment. Later drivers call dma_free_coherent() to free the memory, on xen_swiotlb_free_coherent() the check condition (dev_addr + size - 1 <= dma_mask) is always false, it prevents calling xen_destroy_contiguous_region() to return the memory to the Xen DMA heap.
This issue introduced by commit 6810df88dcfc2 "xen-swiotlb: When doing coherent alloc/dealloc check before swizzling the MFNs.".
--- drivers/xen/swiotlb-xen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/swiotlb-xen.c +1 -1
@@ -366,7 +366,7 @@ xen_swiotlb_free_coherent(struct device* physical address */ phys =xen_bus_to_phys (dev_addr); -if (((dev_addr + size -1 > dma_mask)) || +if (((dev_addr + size -1 <= dma_mask)) ||range_straddles_page_boundary (phys, size))xen_destroy_contiguous_region (phys, order);
PATCH 337/366 ARM: 8771/1: kprobes: Prohibit kprobes on do_undefinstr
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu <[email protected]>
commit eb0146daefdde65665b7f076fbff7b49dade95b9 upstream.
Prohibit kprobes on do_undefinstr because kprobes on arm is implemented by undefined instruction. This means if we probe do_undefinstr(), it can cause infinit recursive exception.
--- arch/arm/kernel/traps.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/kernel/traps.c +4 -1
@@ -19,6 +19,7 @@#include <linux/uaccess.h> #include <linux/hardirq.h> #include <linux/kdebug.h> +#include <linux/kprobes.h> #include <linux/module.h> #include <linux/kexec.h> #include <linux/bug.h>
@@ -392,7 +393,8 @@ void unregister_undef_hook(struct undef_raw_spin_unlock_irqrestore (&undef_lock, flags); } -static int call_undef_hook (struct pt_regs *regs,unsigned int instr) +static nokprobe_inline +int call_undef_hook(struct pt_regs *regs, unsigned int instr) {struct undef_hook *hook;unsigned long flags;
@@ -465,6 +467,7 @@ die_sig:arm_notify_die ("Oops - undefined instruction" , regs, &info,0 ,6 ); } +NOKPROBE_SYMBOL (do_undefinstr) asmlinkage void do_unexp_fiq (struct pt_regs *regs) {
PATCH 345/366 fix io_destroy()/aio_complete() race
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 4faa99965e027cc057c5145ce45fa772caa04e8d upstream.
If io_destroy() gets to cancelling everything that can be cancelled and gets to kiocb_cancel() calling the function driver has left in ->ki_cancel, it becomes vulnerable to a race with IO completion. At that point req is already taken off the list and aio_complete() does *NOT* spin until we (in free_ioctx_users()) releases ->ctx_lock. As the result, it proceeds to kiocb_free(), freing req just it gets passed to ->ki_cancel().
Fix is simple - remove from the list after the call of kiocb_cancel(). All instances of ->ki_cancel() already have to cope with the being called with iocb still on list - that's what happens in io_cancel(2).
--- fs/aio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/aio.c +1 -2
@@ -565,9 +565,8 @@ static void free_ioctx_users(struct percwhile (!list_empty (&ctx->active_reqs)) { req =list_first_entry (&ctx->active_reqs, struct kiocb, ki_list); - -list_del_init (&req->ki_list);kiocb_cancel (req); +list_del_init (&req->ki_list); }spin_unlock_irq (&ctx->ctx_lock);
PATCH 351/366 ppp: fix race in ppp device destruction
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit 6151b8b37b119e8e3a8401b080d532520c95faf4 upstream.
ppp_release() tries to ensure that netdevices are unregistered before decrementing the unit refcount and running ppp_destroy_interface().
This is all fine as long as the the device is unregistered by ppp_release(): the unregister_netdevice() call, followed by rtnl_unlock(), guarantee that the unregistration process completes before rtnl_unlock() returns.
However, the device may be unregistered by other means (like ppp_nl_dellink()). If this happens right before ppp_release() calling rtnl_lock(), then ppp_release() has to wait for the concurrent unregistration code to release the lock.
But rtnl_unlock() releases the lock before completing the device unregistration process. This allows ppp_release() to proceed and eventually call ppp_destroy_interface() before the unregistration process completes. Calling free_netdev() on this partially unregistered device will BUG():
------------[ cut here ]------------ kernel BUG at net/core/dev.c:8141! invalid opcode: 0000 [#1] SMP CPU: 1 PID: 1557 Comm: pppd Not tainted 4.14.0-rc2+ #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1.fc26 04/01/2014 Call Trace: ppp_destroy_interface+0xd8/0xe0 [ppp_generic] ppp_disconnect_channel+0xda/0x110 [ppp_generic] ppp_unregister_channel+0x5e/0x110 [ppp_generic] pppox_unbind_sock+0x23/0x30 [pppox] pppoe_connect+0x130/0x440 [pppoe] SYSC_connect+0x98/0x110 ? do_fcntl+0x2c0/0x5d0 SyS_connect+0xe/0x10 entry_SYSCALL_64_fastpath+0x1a/0xa5 RIP: free_netdev+0x107/0x110 RSP: ffffc28a40573d88 ---[ end trace ed294ff0cc40eeff ]---
We could set the ->needs_free_netdev flag on PPP devices and move the ppp_destroy_interface() logic in the ->priv_destructor() callback. But that'd be quite intrusive as we'd first need to unlink from the other channels and units that depend on the device (the ones that used the PPPIOCCONNECT and PPPIOCATTACH ioctls).
Instead, we can just let the netdevice hold a reference on its ppp_file. This reference is dropped in ->priv_destructor(), at the very end of the unregistration process, so that neither ppp_release() nor ppp_disconnect_channel() can call ppp_destroy_interface() in the interim.
[bwh: Backported to 3.16: Set net_device::destructor instead of
priv_destructor, and call ppp_dev_priv_destructor() if register_netdevice() fails after call ppp_dev_init().]
--- drivers/net/ppp/ppp_generic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/net/ppp/ppp_generic.c +26 -0
@@ -1092,7 +1092,17 @@ ppp_get_stats64(struct net_device *dev,static struct lock_class_key ppp_tx_busylock;static int ppp_dev_init (struct net_device *dev) { +struct ppp *ppp; + dev->qdisc_tx_busylock = &ppp_tx_busylock; + + ppp =netdev_priv (dev); +/* Let the netdevice take a reference on the ppp file. This ensures +* that ppp_destroy_interface() won't run before the device gets +* unregistered. +*/ +atomic_inc (&ppp->file.refcnt); +return 0 ; }
@@ -1115,6 +1125,15 @@ static void ppp_dev_uninit(struct net_dewake_up_interruptible (&ppp->file.rwait); } +static void ppp_dev_priv_destructor (struct net_device *dev) +{ +struct ppp *ppp; + + ppp =netdev_priv (dev); +if (atomic_dec_and_test (&ppp->file.refcnt)) +ppp_destroy_interface (ppp); +} +static const struct net_device_ops ppp_netdev_ops = { .ndo_init = ppp_dev_init, .ndo_uninit = ppp_dev_uninit,
@@ -1134,6 +1153,7 @@ static void ppp_setup(struct net_device dev->flags =IFF_POINTOPOINT |IFF_NOARP |IFF_MULTICAST ; dev->features |=NETIF_F_NETNS_LOCAL ; dev->priv_flags &= ~IFF_XMIT_DST_RELEASE ; + dev->destructor = ppp_dev_priv_destructor; }/*
@@ -2769,6 +2789,12 @@ static struct ppp *ppp_create_interface( ret =register_netdevice (dev);if (ret !=0 ) { +/* register_netdevice() may have called ppp_dev_init() +* but will not have called our destructor, so do that +* now. +*/ +if (dev->qdisc_tx_busylock) +ppp_dev_priv_destructor (dev);unit_put (&pn->units_idr, unit);netdev_err (ppp->dev,"PPP: couldn't register device %s (%d)\n" , dev->name, ret);
PATCH 353/366 ppp: unlock all_ppp_mutex before registering device
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit 0171c41835591e9aa2e384b703ef9a6ae367c610 upstream.
ppp_dev_uninit(), which is the .ndo_uninit() handler of PPP devices, needs to lock pn->all_ppp_mutex. Therefore we mustn't call register_netdevice() with pn->all_ppp_mutex already locked, or we'd deadlock in case register_netdevice() fails and calls .ndo_uninit().
Fortunately, we can unlock pn->all_ppp_mutex before calling register_netdevice(). This lock protects pn->units_idr, which isn't used in the device registration process.
However, keeping pn->all_ppp_mutex locked during device registration did ensure that no device in transient state would be published in pn->units_idr. In practice, unlocking it before calling register_netdevice() doesn't change this property: ppp_unit_register() is called with 'ppp_mutex' locked and all searches done in pn->units_idr hold this lock too.
--- drivers/net/ppp/ppp_generic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ppp/ppp_generic.c +3 -1
@@ -2788,6 +2788,8 @@ static struct ppp *ppp_create_interface( ppp->file.index = unit;sprintf (dev->name,"ppp%d" , unit); +mutex_unlock (&pn->all_ppp_mutex); + ret =register_netdevice (dev);if (ret !=0 ) {/* register_netdevice() may have called ppp_dev_init()
@@ -2796,6 +2798,7 @@ static struct ppp *ppp_create_interface(*/ if (dev->qdisc_tx_busylock)ppp_dev_priv_destructor (dev); +mutex_lock (&pn->all_ppp_mutex);unit_put (&pn->units_idr, unit);netdev_err (ppp->dev,"PPP: couldn't register device %s (%d)\n" , dev->name, ret);
@@ -2803,7 +2806,6 @@ static struct ppp *ppp_create_interface( }atomic_inc (&ppp_unit_count); -mutex_unlock (&pn->all_ppp_mutex);rtnl_unlock (); *retp =0 ;
PATCH 357/366 ipc/shm: fix shmat() nil address after round-down when remapping
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Davidlohr Bueso <[email protected]>
commit 8f89c007b6dec16a1793cb88de88fcc02117bbbc upstream.
shmat()'s SHM_REMAP option forbids passing a nil address for; this is in fact the very first thing we check for. Andrea reported that for SHM_RND|SHM_REMAP cases we can end up bypassing the initial addr check, but we need to check again if the address was rounded down to nil. As of this patch, such cases will return -EINVAL.
--- ipc/shm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
ipc/shm.c +10 -2
@@ -1112,9 +1112,17 @@ long do_shmat(int shmid, char __user *sh goto out; else if ((addr = (ulong)shmaddr)) {if (addr & (shmlba -1 )) { -if (shmflg &SHM_RND ) +if (shmflg &SHM_RND ) { addr &= ~(shmlba -1 );/* round down */ - else + +/* +* Ensure that the round-down is non-nil +* when remapping. This can happen for +* cases when addr < shmlba. +*/ +if (!addr && (shmflg &SHM_REMAP )) + goto out; + } else#ifndef __ARCH_FORCE_SHMLBA if (addr & ~PAGE_MASK)#endif
PATCH 360/366 drm/i915: Disable LVDS on Radiant P845
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ondrej Zary <[email protected]>
commit b3fb22733ae61050f8d10a1d6a8af176c5c5db1a upstream.
Radiant P845 does not have LVDS, only VGA.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105468
--- drivers/gpu/drm/i915/intel_lvds.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/intel_lvds.c +8 -0
@@ -739,6 +739,14 @@ static const struct dmi_system_id intel_ DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"), }, }, + { + .callback = intel_no_lvds_dmi_callback, + .ident = "Radiant P845", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Radiant Systems Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "P845"), + }, + }, { }/* terminating entry */ };
PATCH 365/366 ip_tunnel: restore binding to ifaces with a large mtu
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dichtel <[email protected]>
commit 82612de1c98e610d194e34178bde3cca7dedce41 upstream.
After commit f6cc9c054e77, the following conf is broken (note that the default loopback mtu is 65536, ie IP_MAX_MTU + 1):
$ ip tunnel add gre1 mode gre local 10.125.0.1 remote 10.125.0.2 dev lo add tunnel "gre0" failed: Invalid argument $ ip l a type dummy $ ip l s dummy1 up $ ip l s dummy1 mtu 65535 $ ip tunnel add gre1 mode gre local 10.125.0.1 remote 10.125.0.2 dev dummy1 add tunnel "gre0" failed: Invalid argument
dev_set_mtu() doesn't allow to set a mtu which is too large. First, let's cap the mtu returned by ip_tunnel_bind_dev(). Second, remove the magic value 0xFFF8 and use IP_MAX_MTU instead.0xFFF8 seems to be there for ages, I don't know why this value was used.
With a recent kernel, it's also possible to set a mtu > IP_MAX_MTU:
$ ip l s dummy1 mtu 66000 After that patch, it's also possible to bind an ip tunnel on that kind of interface.
[bwh: Backported to 3.16:
- Drop change in ip_tunnel_create()
- Adjust context]
---
net/ipv4/ip_tunnel.c +3 -3
@@ -387,7 +387,7 @@ static int ip_tunnel_bind_dev(struct netif (tdev) { hlen = tdev->hard_header_len + tdev->needed_headroom; - mtu = tdev->mtu; + mtu =min (tdev->mtu,IP_MAX_MTU ); } dev->iflink = tunnel->parms.link;
@@ -851,7 +851,7 @@ int ip_tunnel_change_mtu(struct net_deviint t_hlen = tunnel->hlen +sizeof (struct iphdr );if (new_mtu <68 || - new_mtu >0xFFF8 - dev->hard_header_len - t_hlen) + new_mtu >IP_MAX_MTU - dev->hard_header_len - t_hlen)return -EINVAL ; dev->mtu = new_mtu;return 0 ;
@@ -979,7 +979,7 @@ int ip_tunnel_newlink(struct net_device mtu =ip_tunnel_bind_dev (dev);if (tb[IFLA_MTU ]) { -unsigned int max =0xfff8 - dev->hard_header_len - nt->hlen; +unsigned int max =IP_MAX_MTU - dev->hard_header_len - nt->hlen; mtu =clamp (dev->mtu, (unsigned int )ETH_MIN_MTU , (unsigned int )(max -sizeof (struct iphdr )));
PATCH 5/366 regmap: Correct offset handling in regmap_volatile_range
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Charles Keepax <[email protected]>
commit b8f9a03b741ddfdde4aa8b607fa7d88eb63a6338 upstream.
The current implementation is broken for regmaps that have a reg_stride, since it doesn't take the stride into account. Correct this by using the helper function to calculate the register offset.
[bwh: Backported to 3.16: Use simple multiplication instead of
regmap_get_offset()]
--- drivers/base/regmap/regmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regmap.c +1 -1
@@ -144,7 +144,7 @@ static bool regmap_volatile_range(structunsigned int i;for (i =0 ; i < num; i++) -if (!regmap_volatile (map, reg + i)) +if (!regmap_volatile (map, reg + (i * map->reg_stride)))return false;return true;
PATCH 18/366 serial: arc_uart: Fix out-of-bounds access through DT alias
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
commit f9f5786987e81d166c60833edcb7d1836aa16944 upstream.
The arc_uart_ports[] array is indexed using a value derived from the "serialN" alias in DT, which may lead to an out-of-bounds access.
Fix this by adding a range check.
Note that the array size is defined by a Kconfig symbol (CONFIG_SERIAL_ARC_NR_PORTS), so this can even be triggered using a legitimate DTB.
[bwh: Backported to 3.16: Put the check in arc_uart_init_one() and move
initialisation of the uart variable below it]
---
drivers/tty/serial/arc_uart.c +7 -1
@@ -531,8 +531,14 @@ arc_uart_init_one(struct platform_device {struct resource *res, *res2;unsigned long *plat_data; -struct arc_uart_port *uart = &arc_uart_ports[dev_id]; +struct arc_uart_port *uart; +if (dev_id >=ARRAY_SIZE (arc_uart_ports)) { +dev_err (&pdev->dev,"serial%d out of range\n" , dev_id); +return -EINVAL ; + } + + uart = &arc_uart_ports[dev_id]; plat_data =dev_get_platdata (&pdev->dev);if (!plat_data)return -ENODEV ;
PATCH 157/366 team: avoid adding twice the same option to the event list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
commit 4fb0534fb7bbc2346ba7d3a072b538007f4135a5 upstream.
When parsing the options provided by the user space, team_nl_cmd_options_set() insert them in a temporary list to send multiple events with a single message.
While each option's attribute is correctly validated, the code does not check for duplicate entries before inserting into the event list.
Exploiting the above, the syzbot was able to trigger the following splat:
kernel BUG at lib/list_debug.c:31!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 0 PID: 4466 Comm: syzkaller556835 Not tainted 4.16.0+ #17 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__list_add_valid+0xaa/0xb0 lib/list_debug.c:29 RSP: 0018:ffff8801b04bf248 EFLAGS: 00010286 RAX: 0000000000000058 RBX: ffff8801c8fc7a90 RCX: 0000000000000000 RDX: 0000000000000058 RSI: ffffffff815fbf41 RDI: ffffed0036097e3f RBP: ffff8801b04bf260 R08: ffff8801b0b2a700 R09: ffffed003b604f90 R10: ffffed003b604f90 R11: ffff8801db027c87 R12: ffff8801c8fc7a90 R13: ffff8801c8fc7a90 R14: dffffc0000000000 R15: 0000000000000000 FS: 0000000000b98880(0000) GS:ffff8801db000000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000043fc30 CR3: 00000001afe8e000 CR4: 00000000001406f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __list_add include/linux/list.h:60 [inline] list_add include/linux/list.h:79 [inline] team_nl_cmd_options_set+0x9ff/0x12b0 drivers/net/team/team.c:2571 genl_family_rcv_msg+0x889/0x1120 net/netlink/genetlink.c:599 genl_rcv_msg+0xc6/0x170 net/netlink/genetlink.c:624 netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2448 genl_rcv+0x28/0x40 net/netlink/genetlink.c:635 netlink_unicast_kernel net/netlink/af_netlink.c:1310 [inline] netlink_unicast+0x58b/0x740 net/netlink/af_netlink.c:1336 netlink_sendmsg+0x9f0/0xfa0 net/netlink/af_netlink.c:1901 sock_sendmsg_nosec net/socket.c:629 [inline] sock_sendmsg+0xd5/0x120 net/socket.c:639 ___sys_sendmsg+0x805/0x940 net/socket.c:2117 __sys_sendmsg+0x115/0x270 net/socket.c:2155 SYSC_sendmsg net/socket.c:2164 [inline] SyS_sendmsg+0x29/0x30 net/socket.c:2162 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x4458b9 RSP: 002b:00007ffd1d4a7278 EFLAGS: 00000213 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 000000000000001b RCX: 00000000004458b9 RDX: 0000000000000010 RSI: 0000000020000d00 RDI: 0000000000000004 RBP: 00000000004a74ed R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000213 R12: 00007ffd1d4a7348 R13: 0000000000402a60 R14: 0000000000000000 R15: 0000000000000000 Code: 75 e8 eb a9 48 89 f7 48 89 75 e8 e8 d1 85 7b fe 48 8b 75 e8 eb bb 48 89 f2 48 89 d9 4c 89 e6 48 c7 c7 a0 84 d8 87 e8 ea 67 28 fe <0f> 0b 0f 1f 40 00 48 b8 00 00 00 00 00 fc ff df 55 48 89 e5 41 RIP: __list_add_valid+0xaa/0xb0 lib/list_debug.c:29 RSP: ffff8801b04bf248
This changeset addresses the avoiding list_add() if the current option is already present in the event list.
--- drivers/net/team/team.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/team/team.c +19 -0
@@ -253,6 +253,17 @@ static void __team_option_inst_mark_remo } } +static bool __team_option_inst_tmp_find (const struct list_head *opts, +const struct team_option_inst *needle) +{ +struct team_option_inst *opt_inst; + +list_for_each_entry (opt_inst, opts, tmp_list) +if (opt_inst == needle) +return true; +return false; +} +static int __team_options_register (struct team *team,const struct team_option *option,size_t option_count)
@@ -2520,6 +2531,14 @@ static int team_nl_cmd_options_set(strucif (err) goto team_put; opt_inst->changed = true; + +/* dumb/evil user-space can send us duplicate opt, +* keep only the last one +*/ +if (__team_option_inst_tmp_find (&opt_inst_list, + opt_inst)) +continue ; +list_add (&opt_inst->tmp_list, &opt_inst_list); }if (!opt_found) {
PATCH 161/366 MIPS: memset.S: EVA & fault support for small_memset
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit 8a8158c85e1e774a44fbe81106fa41138580dfd1 upstream.
The MIPS kernel memset / bzero implementation includes a small_memset branch which is used when the region to be set is smaller than a long (4 bytes on 32bit, 8 bytes on 64bit). The current small_memset implementation uses a simple store byte loop to write the destination. There are 2 issues with this implementation:
1. When EVA mode is active, user and kernel address spaces may overlap. Currently the use of the sb instruction means kernel mode addressing is always used and an intended write to userspace may actually overwrite some critical kernel data.
2. If the write triggers a page fault, for example by calling __clear_user(NULL, 2), instead of gracefully handling the fault, an OOPS is triggered.
Fix these issues by replacing the sb instruction with the EX() macro, which will emit EVA compatible instuctions as required. Additionally implement a fault fixup for small_memset which sets a2 to the number of bytes that could not be cleared (as defined by __clear_user).
Patchwork: https://patchwork.linux-mips.org/patch/18975/
--- arch/mips/lib/memset.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/mips/lib/memset.S +6 -1
@@ -178,7 +178,7 @@ 1: PTR_ADDIU a0, 1 /* fill bytewise */ R10KCBARRIER(0(ra)) bne t1, a0, 1b - sb a1, -1(a0) + EX(sb, a1, -1(a0), .Lsmall_fixup\@) 2: jr ra /* done */ move a2, zero
@@ -212,6 +212,11 @@ jr ra andi v1, a2, STORMASK +.Lsmall_fixup\@: + PTR_SUBU a2, t1, a0 + jr ra + PTR_ADDIU a2, 1 + .endm /*
PATCH 363/366 net: davinci_emac: Fix runtime pm calls for davinci_emac
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tony Lindgren <[email protected]>
commit b5133e7a988b2cf8e1cd2b23231f36aff35ceffc upstream.
Commit 3ba97381343b ("net: ethernet: davinci_emac: add pm_runtime support") added support for runtime PM, but it causes issues on omap3 related devices that actually gate the clocks:
Unhandled fault: external abort on non-linefetch (0x1008)
...
[<c04160f0>] (emac_dev_getnetstats) from [<c04d6a3c>] (dev_get_stats+0x78/0xc8) [<c04d6a3c>] (dev_get_stats) from [<c04e9ccc>] (rtnl_fill_ifinfo+0x3b8/0x938) [<c04e9ccc>] (rtnl_fill_ifinfo) from [<c04eade4>] (rtmsg_ifinfo+0x68/0xd8) [<c04eade4>] (rtmsg_ifinfo) from [<c04dd35c>] (register_netdevice+0x3a0/0x4ec) [<c04dd35c>] (register_netdevice) from [<c04dd4bc>] (register_netdev+0x14/0x24) [<c04dd4bc>] (register_netdev) from [<c041755c>] (davinci_emac_probe+0x408/0x5c8) [<c041755c>] (davinci_emac_probe) from [<c0396d78>] (platform_drv_probe+0x48/0xa4)
Let's fix it by moving the pm_runtime_get() call earlier, and also add it to the emac_dev_getnetstats(). Also note that we want to use pm_runtime_get_sync() as we don't want to have deferred_resume happen. And let's also check the return value for pm_runtime_get_sync() as noted by Felipe Balbi <[email protected]>.
--- drivers/net/ethernet/ti/davinci_emac.c | 33 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/davinci_emac.c +29 -4
@@ -1537,7 +1537,13 @@ static int emac_dev_open(struct net_deviint i =0 ;struct emac_priv *priv =netdev_priv (ndev); -pm_runtime_get (&priv->pdev->dev); + ret =pm_runtime_get_sync (&priv->pdev->dev); +if (ret <0 ) { +pm_runtime_put_noidle (&priv->pdev->dev); +dev_err (&priv->pdev->dev,"%s: failed to get_sync(%d)\n" , + __func__, ret); +return ret; + }netif_carrier_off (ndev);for (cnt =0 ; cnt <ETH_ALEN ; cnt++)
@@ -1724,6 +1730,15 @@ static struct net_device_stats *emac_devstruct emac_priv *priv =netdev_priv (ndev);u32 mac_control;u32 stats_clear_mask; +int err; + + err =pm_runtime_get_sync (&priv->pdev->dev); +if (err <0 ) { +pm_runtime_put_noidle (&priv->pdev->dev); +dev_err (&priv->pdev->dev,"%s: failed to get_sync(%d)\n" , + __func__, err); +return &ndev->stats; + }/* update emac hardware stats and reset the registers*/
@@ -1766,6 +1781,8 @@ static struct net_device_stats *emac_dev ndev->stats.tx_fifo_errors +=emac_read (EMAC_TXUNDERRUN );emac_write (EMAC_TXUNDERRUN , stats_clear_mask); +pm_runtime_put (&priv->pdev->dev); +return &ndev->stats; }
@@ -1985,12 +2002,22 @@ static int davinci_emac_probe(struct pla ndev->ethtool_ops = ðtool_ops;netif_napi_add (ndev, &priv->napi, emac_poll,EMAC_POLL_WEIGHT ); +pm_runtime_enable (&pdev->dev); + rc =pm_runtime_get_sync (&pdev->dev); +if (rc <0 ) { +pm_runtime_put_noidle (&pdev->dev); +dev_err (&pdev->dev,"%s: failed to get_sync(%d)\n" , + __func__, rc); + goto no_cpdma_chan; + } +/* register the network device */ SET_NETDEV_DEV (ndev, &pdev->dev); rc =register_netdev (ndev);if (rc) {dev_err (&pdev->dev,"error in register_netdev\n" ); rc = -ENODEV ; +pm_runtime_put (&pdev->dev); goto no_cpdma_chan; }
@@ -2000,9 +2027,7 @@ static int davinci_emac_probe(struct pla"(regs: %p, irq: %d)\n" , (void *)priv->emac_base_phys, ndev->irq); } - -pm_runtime_enable (&pdev->dev); -pm_runtime_resume (&pdev->dev); +pm_runtime_put (&pdev->dev);return 0 ;
PATCH 330/366 powerpc/powernv: Fix NVRAM sleep in invalid context when crashing
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Piggin <[email protected]>
commit c1d2a31397ec51f0370f6bd17b19b39152c263cb upstream.
Similarly to opal_event_shutdown, opal_nvram_write can be called in the crash path with irqs disabled. Special case the delay to avoid sleeping in invalid context.
--- arch/powerpc/platforms/powernv/opal-nvram.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/opal-nvram.c +12 -2
@@ -43,6 +43,10 @@ static ssize_t opal_nvram_read(char *bufreturn count; } +/* +* This can be called in the panic path with interrupts off, so use +* mdelay in that case. +*/ static ssize_t opal_nvram_write (char *buf,size_t count,loff_t *index) {s64 rc =OPAL_BUSY ;
@@ -57,10 +61,16 @@ static ssize_t opal_nvram_write(char *buwhile (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { rc =opal_write_nvram (__pa (buf), count, off);if (rc ==OPAL_BUSY_EVENT ) { -msleep (OPAL_BUSY_DELAY_MS ); +if (in_interrupt () ||irqs_disabled ()) +mdelay (OPAL_BUSY_DELAY_MS ); +else +msleep (OPAL_BUSY_DELAY_MS );opal_poll_events (NULL ); }else if (rc ==OPAL_BUSY ) { -msleep (OPAL_BUSY_DELAY_MS ); +if (in_interrupt () ||irqs_disabled ()) +mdelay (OPAL_BUSY_DELAY_MS ); +else +msleep (OPAL_BUSY_DELAY_MS ); } }
PATCH 292/366 ufs: Fix possible deadlock when looking up directories
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 514d748f69c97a51a2645eb198ac5c6218f22ff9 upstream.
Commit e4502c63f56aeca88 (ufs: deal with nfsd/iget races) made ufs create inodes with I_NEW flag set. However ufs_mkdir() never cleared this flag. Thus if someone ever tried to lookup the directory by inode number, he would deadlock waiting for I_NEW to be cleared. Luckily this mostly happens only if the filesystem is exported over NFS since otherwise we have the inode attached to dentry and don't look it up by inode number. In rare cases dentry can get freed without inode being freed and then we'd hit the deadlock even without NFS export.
Fix the problem by clearing I_NEW before instantiating new directory inode.
--- fs/ufs/namei.c | 1 + 1 file changed, 1 insertion(+)
fs/ufs/namei.c +1 -0
@@ -212,6 +212,7 @@ static int ufs_mkdir(struct inode * dir, goto out_fail;unlock_ufs (dir->i_sb); +unlock_new_inode (inode);d_instantiate (dentry, inode); out:return err;
PATCH 275/366 cifs: Allocate validate negotiation request through kmalloc
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Long Li <[email protected]>
commit 2796d303e3c5ec213c578ed3a66872205c126eb8 upstream.
The data buffer allocated on the stack can't be DMA'ed, ib_dma_map_page will return an invalid DMA address for a buffer on stack. Even worse, this incorrect address can't be detected by ib_dma_mapping_error. Sending data from this address to hardware will not fail, but the remote peer will get junk data.
Fix this by allocating the request on the heap in smb3_validate_negotiate.
Changes in v2:
Removed duplicated code on freeing buffers on function exit. (Thanks to Parav Pandit <[email protected]>) Fixed typo in the patch title.
Changes in v3:
Added "Fixes" to the patch.
Changed several sizeof() to use *pointer in place of struct.
Changes in v4:
Added detailed comments on the failure through RDMA. Allocate request buffer using GPF_NOFS. Fixed possible memory leak.
Changes in v5:
Removed variable ret for checking return value.
Changed to use pneg_inbuf->Dialects[0] to calculate unused space in pneg_inbuf.
--- fs/cifs/smb2pdu.c | 68 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 30 deletions(-)
fs/cifs/smb2pdu.c +26 -19
@@ -477,8 +477,8 @@ neg_exit:int smb3_validate_negotiate (const unsigned int xid,struct cifs_tcon *tcon) { -int rc =0 ; -struct validate_negotiate_info_req vneg_inbuf; +int rc; +struct validate_negotiate_info_req *pneg_inbuf;struct validate_negotiate_info_rsp *pneg_rsp =NULL ;u32 rsplen;
@@ -502,42 +502,47 @@ int smb3_validate_negotiate(const unsignif (tcon->ses->session_flags &SMB2_SESSION_FLAG_IS_NULL )cifs_dbg (VFS ,"Unexpected null user (anonymous) auth flag sent by server\n" ); - vneg_inbuf.Capabilities = + pneg_inbuf =kmalloc (sizeof (*pneg_inbuf),GFP_NOFS ); +if (!pneg_inbuf) +return -ENOMEM ; + + pneg_inbuf->Capabilities =cpu_to_le32 (tcon->ses->server->vals->req_capabilities); -memcpy (vneg_inbuf.Guid, tcon->ses->server->client_guid, +memcpy (pneg_inbuf->Guid, tcon->ses->server->client_guid,SMB2_CLIENT_GUID_SIZE );if (tcon->ses->sign) - vneg_inbuf.SecurityMode = + pneg_inbuf->SecurityMode =cpu_to_le16 (SMB2_NEGOTIATE_SIGNING_REQUIRED );else if (global_secflags &CIFSSEC_MAY_SIGN ) - vneg_inbuf.SecurityMode = + pneg_inbuf->SecurityMode =cpu_to_le16 (SMB2_NEGOTIATE_SIGNING_ENABLED );else - vneg_inbuf.SecurityMode =0 ; + pneg_inbuf->SecurityMode =0 ; - vneg_inbuf.DialectCount =cpu_to_le16 (1 ); - vneg_inbuf.Dialects[0 ] = + pneg_inbuf->DialectCount =cpu_to_le16 (1 ); + pneg_inbuf->Dialects[0 ] =cpu_to_le16 (tcon->ses->server->vals->protocol_id); rc =SMB2_ioctl (xid, tcon,NO_FILE_ID ,NO_FILE_ID ,FSCTL_VALIDATE_NEGOTIATE_INFO , true/* is_fsctl */ , - (char *)&vneg_inbuf,sizeof (struct validate_negotiate_info_req ), + (char *)pneg_inbuf,sizeof (struct validate_negotiate_info_req ), (char **)&pneg_rsp, &rsplen);if (rc !=0 ) {cifs_dbg (VFS ,"validate protocol negotiate failed: %d\n" , rc); -return -EIO ; + rc = -EIO ; + goto out_free_inbuf; } -if (rsplen !=sizeof (struct validate_negotiate_info_rsp )) { + rc = -EIO ; +if (rsplen !=sizeof (*pneg_rsp)) {cifs_dbg (VFS ,"invalid protocol negotiate response size: %d\n" , rsplen);/* relax check since Mac returns max bufsize allowed on ioctl */ -if ((rsplen > CIFSMaxBufSize) - || (rsplen <sizeof (struct validate_negotiate_info_rsp ))) - goto err_rsp_free; +if (rsplen > CIFSMaxBufSize || rsplen <sizeof (*pneg_rsp)) + goto out_free_rsp; }/* check validate negotiate info response matches what we got earlier */
@@ -554,15 +559,17 @@ int smb3_validate_negotiate(const unsign goto vneg_out;/* validate negotiate successful */ + rc =0 ;cifs_dbg (FYI ,"validate negotiate info successful\n" ); -kfree (pneg_rsp); -return 0 ; + goto out_free_rsp; vneg_out:cifs_dbg (VFS ,"protocol revalidation - security settings mismatch\n" ); -err_rsp_free: +out_free_rsp:kfree (pneg_rsp); -return -EIO ; +out_free_inbuf: +kfree (pneg_inbuf); +return rc; }int
PATCH 271/366 drm/i915: Fix drm:intel_enable_lvds ERROR message in kernel log
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florent Flament <[email protected]>
commit e8f48f96db7e482995743f461b3e8a5c1a102533 upstream.
Fix [drm:intel_enable_lvds] *ERROR* timed out waiting for panel to power on in kernel log at boot time.
Toshiba Satellite Z930 laptops needs between 1 and 2 seconds to power on its screen during Intel i915 DRM initialization. This currently results in a [drm:intel_enable_lvds] *ERROR* timed out waiting for panel to power on message appearing in the kernel log during boot time and when stopping the machine.
This change increases the timeout of the intel_enable_lvds function from 1 to 5 seconds, letting enough time for the Satellite 930 LCD screen to power on, and suppressing the error message from the kernel log.
This patch has been successfully tested on Linux 4.14 running on a Toshiba Satellite Z930.
[vsyrjala: bump the timeout from 2 to 5 seconds to match the DP
code and properly cover the max hw timeout of ~4 seconds, and drop the comment about the specific machine since this is not a particulary surprising issue, nor specific to that one machine]
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103414
References: https://bugzilla.kernel.org/show_bug.cgi?id=57591
--- drivers/gpu/drm/i915/intel_lvds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_lvds.c +2 -1
@@ -219,7 +219,8 @@ static void intel_enable_lvds(struct intI915_WRITE (ctl_reg,I915_READ (ctl_reg) |POWER_TARGET_ON );POSTING_READ (lvds_encoder->reg); -if (wait_for ((I915_READ (stat_reg) &PP_ON ) !=0 ,1000 )) + +if (wait_for ((I915_READ (stat_reg) &PP_ON ) !=0 ,5000 ))DRM_ERROR ("timed out waiting for panel to power on\n" );intel_panel_enable_backlight (intel_connector);
PATCH 248/366 ALSA: pcm: Check PCM state at xfern compat ioctl
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f13876e2c33a657a71bcbb10f767c0951b165020 upstream.
Since snd_pcm_ioctl_xfern_compat() has no PCM state check, it may go further and hit the sanity check pcm_sanity_check() when the ioctl is called right after open. It may eventually spew a kernel warning, as triggered by syzbot, depending on kconfig.
The lack of PCM state check there was just an oversight. Although it's no real crash, the spurious kernel warning is annoying, so let's add the proper check.
--- sound/core/pcm_compat.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/pcm_compat.c +2 -0
@@ -334,6 +334,8 @@ static int snd_pcm_ioctl_xfern_compat(streturn -ENOTTY ;if (substream->stream != dir)return -EINVAL ; +if (substream->runtime->status->state ==SNDRV_PCM_STATE_OPEN ) +return -EBADFD ;if ((ch = substream->runtime->channels) >128 )return -EINVAL ;
PATCH 306/366 MIPS: ptrace: Expose FIR register through FP regset
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Maciej W. Rozycki" <[email protected]>
commit 71e909c0cdad28a1df1fa14442929e68615dee45 upstream.
Correct commit 7aeb753b5353 ("MIPS: Implement task_user_regset_view.") and expose the FIR register using the unused 4 bytes at the end of the NT_PRFPREG regset. Without that register included clients cannot use the PTRACE_GETREGSET request to retrieve the complete FPU register set and have to resort to one of the older interfaces, either PTRACE_PEEKUSR or PTRACE_GETFPREGS, to retrieve the missing piece of data. Also the register is irreversibly missing from core dumps.
This register is architecturally hardwired and read-only so the write path does not matter. Ignore data supplied on writes then.
Patchwork: https://patchwork.linux-mips.org/patch/19273/
--- arch/mips/kernel/ptrace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/mips/kernel/ptrace.c +16 -2
@@ -481,7 +481,7 @@ static int fpr_get_msa(struct task_struc/* * Copy the floating-point context to the supplied NT_PRFPREG buffer. * Choose the appropriate helper for general registers, and then copy -* the FCSR register separately. +* the FCSR and FIR registers separately. */ static int fpr_get(struct task_struct *target, const struct user_regset *regset,
@@ -489,6 +489,7 @@ static int fpr_get(struct task_struct *t void *kbuf, void __user *ubuf) {const int fcr31_pos =NUM_FPU_REGS *sizeof (elf_fpreg_t); +const int fir_pos = fcr31_pos +sizeof (u32);int err;if (sizeof (target->thread.fpu.fpr[0 ]) ==sizeof (elf_fpreg_t))
@@ -501,6 +502,12 @@ static int fpr_get(struct task_struct *t err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &target->thread.fpu.fcr31, fcr31_pos, fcr31_pos +sizeof (u32)); +if (err) +return err; + + err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + &boot_cpu_data.fpu_id, + fir_pos, fir_pos +sizeof (u32));return err; }
@@ -549,7 +556,8 @@ static int fpr_set_msa(struct task_struc/* * Copy the supplied NT_PRFPREG buffer to the floating-point context. * Choose the appropriate helper for general registers, and then copy -* the FCSR register separately. +* the FCSR register separately. Ignore the incoming FIR register +* contents though, as the register is read-only. * * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0', * which is supposed to have been guaranteed by the kernel before
@@ -563,6 +571,7 @@ static int fpr_set(struct task_struct *t const void *kbuf, const void __user *ubuf) { const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); +const int fir_pos = fcr31_pos +sizeof (u32);u32 fcr31;int err;
@@ -590,6 +599,11 @@ static int fpr_set(struct task_struct *tptrace_setfcr31 (target, fcr31); } +if (count >0 ) + err =user_regset_copyin_ignore (&pos, &count, &kbuf, &ubuf, + fir_pos, + fir_pos +sizeof (u32)); +return err; }
PATCH 188/366 l2tp: fix {pppol2tp, l2tp_dfs}_seq_stop() in case of seq_file overflow
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit 5411b6187adf62909e3b998ac782e722904c7487 upstream.
Commit 0e0c3fee3a59 ("l2tp: hold reference on tunnels printed in pppol2tp proc file") assumed that if pppol2tp_seq_stop() was called with non-NULL private data (the 'v' pointer), then pppol2tp_seq_start() would not be called again. It turns out that this isn't guaranteed, and overflowing the seq_file's buffer in pppol2tp_seq_show() is a way to get into this situation.
Therefore, pppol2tp_seq_stop() needs to reset pd->tunnel, so that pppol2tp_seq_start() won't drop a reference again if it gets called. We also have to clear pd->session, because the rest of the code expects a non-NULL tunnel when pd->session is set.
The l2tp_debugfs module has the same issue. Fix it in the same way.
--- net/l2tp/l2tp_debugfs.c | 5 ++++- net/l2tp/l2tp_ppp.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
net/l2tp/l2tp_debugfs.c +4 -1
@@ -106,8 +106,11 @@ static void l2tp_dfs_seq_stop(struct seqreturn ;/* Drop reference taken by last invocation of l2tp_dfs_next_tunnel() */ -if (pd->tunnel) +if (pd->tunnel) {l2tp_tunnel_dec_refcount (pd->tunnel); + pd->tunnel =NULL ; + pd->session =NULL ; + } }static void l2tp_dfs_seq_tunnel_show (struct seq_file *m,void *v)
net/l2tp/l2tp_ppp.c +4 -1
@@ -1650,8 +1650,11 @@ static void pppol2tp_seq_stop(struct seqreturn ;/* Drop reference taken by last invocation of pppol2tp_next_tunnel() */ -if (pd->tunnel) +if (pd->tunnel) {l2tp_tunnel_dec_refcount (pd->tunnel); + pd->tunnel =NULL ; + pd->session =NULL ; + } }static void pppol2tp_seq_tunnel_show (struct seq_file *m,void *v)
PATCH 168/366 KEYS: DNS: limit the length of option strings
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9c438d7a3a52dcc2b9ed095cb87d3a5e83cf7e60 upstream.
Adding a dns_resolver key whose payload contains a very long option name resulted in that string being printed in full. This hit the WARN_ONCE() in set_precision() during the printk(), because printk() only supports a precision of up to 32767 bytes:
precision 1000000 too large
WARNING: CPU: 0 PID: 752 at lib/vsprintf.c:2189 vsnprintf+0x4bc/0x5b0Fix it by limiting option strings (combined name + value) to a much more reasonable 128 bytes. The exact limit is arbitrary, but currently the only recognized option is formatted as "dnserror=%lu" which fits well within this limit.
Also ratelimit the printks.
Reproducer:
perl -e 'print "#", "A" x 1000000, "\x00"' | keyctl padd dns_resolver desc @s
This bug was found using syzkaller.
[bwh: Backported to 3.16:
- Also stop logging the key serial number
- Include <linux/ratelimit.h> directly]
---
net/dns_resolver/dns_key.c +6 -8
@@ -29,6 +29,7 @@#include <linux/keyctl.h> #include <linux/err.h> #include <linux/seq_file.h> +#include <linux/ratelimit.h> #include <keys/dns_resolver-type.h> #include <keys/user-type.h> #include "internal.h"
@@ -93,10 +94,9 @@ dns_resolver_instantiate(struct key *key next_opt =memchr (opt,'#' , end - opt) ?: end; opt_len = next_opt - opt; -if (!opt_len) { -printk (KERN_WARNING -"Empty option to dns_resolver key %d\n" , - key->serial); +if (opt_len <=0 || opt_len >128 ) { +pr_warn_ratelimited ("Invalid option length (%d) for dns_resolver key\n" , + opt_len);return -EINVAL ; }
@@ -130,10 +130,8 @@ dns_resolver_instantiate(struct key *key } bad_option_value: -printk (KERN_WARNING -"Option '%*.*s' to dns_resolver key %d:" -" bad/missing value\n" , - opt_nlen, opt_nlen, opt, key->serial); +pr_warn_ratelimited ("Option '%*.*s' to dns_resolver key: bad/missing value\n" , + opt_nlen, opt_nlen, opt);return -EINVAL ; }while (opt = next_opt +1 , opt < end); }
PATCH 220/366 ALSA: rme9652: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f526afcd8f71945c23ce581d7864ace93de8a4f7 upstream.
As recently Smatch suggested, one place in RME9652 driver may expand
the array directly from the user-space value with speculation:
sound/pci/rme9652/rme9652.c:2074 snd_rme9652_channel_info() warn: potential spectre issue 'rme9652->channel_map' (local cap)
This patch puts array_index_nospec() for hardening against it.
--- sound/pci/rme9652/rme9652.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/pci/rme9652/rme9652.c +4 -2
@@ -35,6 +35,7 @@#include <asm/current.h> #include <asm/io.h> +#include <linux/nospec.h> static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;/* Index 0-MAX */ static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;/* ID for this card */
@@ -2059,9 +2060,10 @@ static int snd_rme9652_channel_info(struif (snd_BUG_ON (info->channel >=RME9652_NCHANNELS ))return -EINVAL ; -if ((chn = rme9652->channel_map[info->channel]) <0 ) { + chn = rme9652->channel_map[array_index_nospec (info->channel, +RME9652_NCHANNELS )]; +if (chn <0 )return -EINVAL ; - } info->offset = chn *RME9652_CHANNEL_BUFFER_BYTES ; info->first =0 ;
PATCH 239/366 NET: usb: qmi_wwan: add support for ublox R410M PID 0x90b2
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: SZ Lin (林上智)
<[email protected]>
commit 9306b38e42cb266f98bff6f6f4c1c652aa79ba45 upstream.
This patch adds support for PID 0x90b2 of ublox R410M.
qmicli -d /dev/cdc-wdm0 --dms-get-manufacturer [/dev/cdc-wdm0] Device manufacturer retrieved:
Manufacturer: 'u-blox'
qmicli -d /dev/cdc-wdm0 --dms-get-model
[/dev/cdc-wdm0] Device model retrieved:
Model: 'SARA-R410M-02B'
--- drivers/net/usb/qmi_wwan.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/usb/qmi_wwan.c +1 -0
@@ -677,6 +677,7 @@ static const struct usb_device_id produc {QMI_FIXED_INTF(0x05c6, 0x9080, 8)}, {QMI_FIXED_INTF(0x05c6, 0x9083, 3)}, {QMI_FIXED_INTF(0x05c6, 0x9084, 4)}, + {QMI_FIXED_INTF(0x05c6, 0x90b2, 3)}, /* ublox R410M */ {QMI_FIXED_INTF(0x05c6, 0x920d, 0)}, {QMI_FIXED_INTF(0x05c6, 0x920d, 5)}, {QMI_FIXED_INTF(0x0846, 0x68a2, 8)},
PATCH 238/366 sctp: handle two v4 addrs comparison in sctp_inet6_cmp_addr
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit d625329b06e46bd20baf9ee40847d11982569204 upstream.
Since sctp ipv6 socket also supports v4 addrs, it's possible to compare two v4 addrs in pf v6 .cmp_addr, sctp_inet6_cmp_addr.
However after Commit 1071ec9d453a ("sctp: do not check port in sctp_inet6_cmp_addr"), it no longer calls af1->cmp_addr, which in this case is sctp_v4_cmp_addr, but calls __sctp_v6_cmp_addr where it handles them as two v6 addrs. It would cause a out of bounds crash.
syzbot found this crash when trying to bind two v4 addrs to a v6 socket.
This patch fixes it by adding the process for two v4 addrs in sctp_inet6_cmp_addr.
--- net/sctp/ipv6.c | 3 +++ 1 file changed, 3 insertions(+)
net/sctp/ipv6.c +3 -0
@@ -840,6 +840,9 @@ static int sctp_inet6_cmp_addr(const uniif (sctp_is_any (sk, addr1) ||sctp_is_any (sk, addr2))return 1 ; +if (addr1->sa.sa_family ==AF_INET && addr2->sa.sa_family ==AF_INET ) +return addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr; +return __sctp_v6_cmp_addr (addr1, addr2); }
PATCH 308/366 MIPS: Fix ptrace(2) PTRACE_PEEKUSR and PTRACE_POKEUSR accesses to o32 FGRs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Maciej W. Rozycki" <[email protected]>
commit 9a3a92ccfe3620743d4ae57c987dc8e9c5f88996 upstream.
Check the TIF_32BIT_FPREGS task setting of the tracee rather than the tracer in determining the layout of floating-point general registers in the floating-point context, correcting access to odd-numbered registers for o32 tracees where the setting disagrees between the two processes.
--- arch/mips/kernel/ptrace.c | 4 ++-- arch/mips/kernel/ptrace32.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/mips/kernel/ptrace.c +2 -2
@@ -741,7 +741,7 @@ long arch_ptrace(struct task_struct *chi fregs =get_fpu_regs (child);#ifdef CONFIG_32BIT -if (test_thread_flag (TIF_32BIT_FPREGS )) { +if (test_tsk_thread_flag (child,TIF_32BIT_FPREGS )) {/* * The odd registers are actually the high * order bits of the values stored in the even
@@ -830,7 +830,7 @@ long arch_ptrace(struct task_struct *chiinit_fp_ctx (child);#ifdef CONFIG_32BIT -if (test_thread_flag (TIF_32BIT_FPREGS )) { +if (test_tsk_thread_flag (child,TIF_32BIT_FPREGS )) {/* * The odd registers are actually the high * order bits of the values stored in the even
arch/mips/kernel/ptrace32.c +2 -2
@@ -97,7 +97,7 @@ long compat_arch_ptrace(struct task_strubreak ; } fregs =get_fpu_regs (child); -if (test_thread_flag (TIF_32BIT_FPREGS )) { +if (test_tsk_thread_flag (child,TIF_32BIT_FPREGS )) {/* * The odd registers are actually the high * order bits of the values stored in the even
@@ -203,7 +203,7 @@ long compat_arch_ptrace(struct task_stru sizeof(child->thread.fpu)); child->thread.fpu.fcr31 =0 ; } -if (test_thread_flag (TIF_32BIT_FPREGS )) { +if (test_tsk_thread_flag (child,TIF_32BIT_FPREGS )) {/* * The odd registers are actually the high * order bits of the values stored in the even
PATCH 211/366 packet: fix bitfield update race
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
commit a6361f0ca4b25460f2cdf3235ebe8115f622901e upstream.
Updates to the bitfields in struct packet_sock are not atomic. Serialize these read-modify-write cycles.
Move po->running into a separate variable. Its writes are protected by po->bind_lock (except for one startup case at packet_create). Also replace a textual precondition warning with lockdep annotation.
All others are set only in packet_setsockopt. Serialize these updates by holding the socket lock. Analogous to other field updates, also hold the lock when testing whether a ring is active (pg_vec).
--- net/packet/af_packet.c | 60 +++++++++++++++++++++++++++++++----------- net/packet/internal.h | 10 +++---- 2 files changed, 49 insertions(+), 21 deletions(-)
net/packet/af_packet.c +44 -16
@@ -343,11 +343,11 @@ static void packet_pick_tx_queue(structskb_set_queue_mapping (skb, queue_index); } -/* register_prot_hook must be invoked with the po->bind_lock held, +/* __register_prot_hook must be invoked through register_prot_hook * or from a context in which asynchronous accesses to the packet * socket is not possible (packet_create()). */ -static void register_prot_hook (struct sock *sk) +static void __register_prot_hook (struct sock *sk) {struct packet_sock *po =pkt_sk (sk);
@@ -362,8 +362,13 @@ static void register_prot_hook(struct so } } -/* {,__}unregister_prot_hook() must be invoked with the po->bind_lock -* held. If the sync parameter is true, we will temporarily drop +static void register_prot_hook (struct sock *sk) +{ +lockdep_assert_held_once (&pkt_sk (sk)->bind_lock); +__register_prot_hook (sk); +} + +/* If the sync parameter is true, we will temporarily drop * the po->bind_lock and do a synchronize_net to make sure no * asynchronous packet processing paths still refer to the elements * of po->prot_hook. If the sync parameter is false, it is the
@@ -373,6 +378,8 @@ static void __unregister_prot_hook(struc {struct packet_sock *po =pkt_sk (sk); +lockdep_assert_held_once (&po->bind_lock); + po->running =0 ;if (po->fanout)
@@ -2887,7 +2894,7 @@ static int packet_create(struct net *netif (proto) { po->prot_hook.type = proto; -register_prot_hook (sk); +__register_prot_hook (sk); }mutex_lock (&net->packet.sklist_lock);
@@ -3386,12 +3393,18 @@ packet_setsockopt(struct socket *sock, iif (optlen !=sizeof (val))return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->tp_loss = !!val; -return 0 ; + +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->tp_loss = !!val; + ret =0 ; + } +release_sock (sk); +return ret; }case PACKET_AUXDATA : {
@@ -3402,7 +3415,9 @@ packet_setsockopt(struct socket *sock, iif (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; +lock_sock (sk); po->auxdata = !!val; +release_sock (sk);return 0 ; }case PACKET_ORIGDEV :
@@ -3414,7 +3429,9 @@ packet_setsockopt(struct socket *sock, iif (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; +lock_sock (sk); po->origdev = !!val; +release_sock (sk);return 0 ; }case PACKET_VNET_HDR :
@@ -3423,15 +3440,20 @@ packet_setsockopt(struct socket *sock, iif (sock->type !=SOCK_RAW )return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (optlen <sizeof (val))return -EINVAL ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->has_vnet_hdr = !!val; -return 0 ; +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->has_vnet_hdr = !!val; + ret =0 ; + } +release_sock (sk); +return ret; }case PACKET_TIMESTAMP : {
@@ -3462,11 +3484,17 @@ packet_setsockopt(struct socket *sock, iif (optlen !=sizeof (val))return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->tp_tx_has_off = !!val; + +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->tp_tx_has_off = !!val; + ret =0 ; + } +release_sock (sk);return 0 ; }case PACKET_QDISC_BYPASS :
net/packet/internal.h +5 -5
@@ -100,10 +100,12 @@ struct packet_sock {int copy_thresh;spinlock_t bind_lock;struct mutex pg_vec_lock; - unsigned int running:1, /* prot_hook is attached*/ - auxdata:1, +unsigned int running;/* bind_lock must be held */ + unsigned int auxdata:1, /* writer must hold sock lock */ origdev:1, - has_vnet_hdr:1; + has_vnet_hdr:1, + tp_loss:1, + tp_tx_has_off:1;int ifindex;/* bound device */ __be16 num;struct packet_mclist *mclist;
@@ -111,8 +113,6 @@ struct packet_sock {enum tpacket_versions tp_version;unsigned int tp_hdrlen;unsigned int tp_reserve; - unsigned int tp_loss:1; - unsigned int tp_tx_has_off:1;unsigned int tp_tstamp;struct net_device __rcu *cached_dev;int (*xmit)(struct sk_buff *skb);
PATCH 346/366 MIPS: ptrace: Fix PTRACE_PEEKUSR requests for 64-bit FGRs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Maciej W. Rozycki" <[email protected]>
commit c7e814628df65f424fe197dde73bfc67e4a244d7 upstream.
Use 64-bit accesses for 64-bit floating-point general registers with PTRACE_PEEKUSR, removing the truncation of their upper halves in the FR=1 mode, caused by commit bbd426f542cb ("MIPS: Simplify FP context access"), which inadvertently switched them to using 32-bit accesses.
The PTRACE_POKEUSR side is fine as it's never been broken and continues using 64-bit accesses.
Patchwork: https://patchwork.linux-mips.org/patch/19334/
--- arch/mips/kernel/ptrace.c | 2 +- arch/mips/kernel/ptrace32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/kernel/ptrace.c +1 -1
@@ -752,7 +752,7 @@ long arch_ptrace(struct task_struct *chi break; }#endif - tmp =get_fpr32 (&fregs[addr -FPR_BASE ],0 ); + tmp =get_fpr64 (&fregs[addr -FPR_BASE ],0 );break ;case PC : tmp = regs->cp0_epc;
arch/mips/kernel/ptrace32.c +1 -1
@@ -107,7 +107,7 @@ long compat_arch_ptrace(struct task_stru addr & 1);break ; } - tmp =get_fpr32 (&fregs[addr -FPR_BASE ],0 ); + tmp =get_fpr64 (&fregs[addr -FPR_BASE ],0 );break ;case PC : tmp = regs->cp0_epc;
PATCH 256/366 USB: Accept bulk endpoints with 1024-byte maxpacket
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit fb5ee84ea72c5f1b6cabdd1c9d6e8648995ca7c6 upstream.
Some non-compliant high-speed USB devices have bulk endpoints with a 1024-byte maxpacket size. Although such endpoints don't work with xHCI host controllers, they do work with EHCI controllers. We used to accept these invalid sizes (with a warning), but we no longer do because of an unintentional change introduced by commit aed9d65ac327 ("USB: validate wMaxPacketValue entries in endpoint descriptors").
This patch restores the old behavior, so that people with these peculiar devices can use them without patching their kernels by hand.
--- drivers/usb/core/config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +3 -1
@@ -157,7 +157,9 @@ static const unsigned short full_speed_mstatic const unsigned short high_speed_maxpacket_maxes[4 ] = { [USB_ENDPOINT_XFER_CONTROL ] =64 , [USB_ENDPOINT_XFER_ISOC ] =1024 , - [USB_ENDPOINT_XFER_BULK ] =512 , + +/* Bulk should be 512, but some devices use 1024: we will warn below */ + [USB_ENDPOINT_XFER_BULK ] =1024 , [USB_ENDPOINT_XFER_INT ] =1024 , };static const unsigned short super_speed_maxpacket_maxes[4 ] = {
PATCH 207/366 team: fix netconsole setup over team
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit 9cf2f437ca5b39828984064fad213e68fc17ef11 upstream.
The same fix in Commit dbe173079ab5 ("bridge: fix netconsole setup over bridge") is also needed for team driver.
While at it, remove the unnecessary parameter *team from team_port_enable_netpoll().
v1->v2:
- fix it in a better way, as does bridge.
--- drivers/net/team/team.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/team/team.c +12 -7
@@ -1052,14 +1052,11 @@ static void team_port_leave(struct team }#ifdef CONFIG_NET_POLL_CONTROLLER -static int team_port_enable_netpoll (struct team *team,struct team_port *port) +static int __team_port_enable_netpoll (struct team_port *port) {struct netpoll *np;int err; -if (!team->dev->npinfo) -return 0 ; - np =kzalloc (sizeof (*np),GFP_KERNEL );if (!np)return -ENOMEM ;
@@ -1073,6 +1070,14 @@ static int team_port_enable_netpoll(strureturn err; } +static int team_port_enable_netpoll (struct team_port *port) +{ +if (!port->team->dev->npinfo) +return 0 ; + +return __team_port_enable_netpoll (port); +} +static void team_port_disable_netpoll (struct team_port *port) {struct netpoll *np = port->np;
@@ -1087,7 +1092,7 @@ static void team_port_disable_netpoll(st kfree(np); }#else -static int team_port_enable_netpoll (struct team *team,struct team_port *port) +static int team_port_enable_netpoll (struct team_port *port) {return 0 ; }
@@ -1175,7 +1180,7 @@ static int team_port_add(struct team *te goto err_vids_add; } - err =team_port_enable_netpoll (team, port); + err =team_port_enable_netpoll (port);if (err) {netdev_err (dev,"Failed to enable netpoll on device %s\n" , portname);
@@ -1880,7 +1885,7 @@ static int team_netpoll_setup(struct netmutex_lock (&team->lock);list_for_each_entry (port, &team->port_list, list) { - err =team_port_enable_netpoll (team, port); + err =__team_port_enable_netpoll (port);if (err) {__team_netpoll_cleanup (team);break ;
PATCH 240/366 RDMA/cxgb4: release hw resources on device removal
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Raju Rangoju <[email protected]>
commit 26bff1bd74a4f7417509a83295614e9dab995b2a upstream.
The c4iw_rdev_close() logic was not releasing all the hw resources (PBL and RQT memory) during the device removal event (driver unload / system reboot). This can cause panic in gen_pool_destroy().
The module remove function will wait for all the hw resources to be released during the device removal event.
Fixes c12a67fe(iw_cxgb4: free EQ queue memory on last deref)
---
drivers/infiniband/hw/cxgb4/device.c +8 -0
@@ -698,6 +698,12 @@ static int c4iw_rdev_open(struct c4iw_rd goto err4; } rdev->status_page->db_off =0 ; + +init_completion (&rdev->rqt_compl); +init_completion (&rdev->pbl_compl); +kref_init (&rdev->rqt_kref); +kref_init (&rdev->pbl_kref); +return 0 ; err4:c4iw_rqtpool_destroy (rdev);
@@ -714,6 +720,8 @@ static void c4iw_rdev_close(struct c4iw_free_page ((unsigned long )rdev->status_page);c4iw_pblpool_destroy (rdev);c4iw_rqtpool_destroy (rdev); +wait_for_completion (&rdev->pbl_compl); +wait_for_completion (&rdev->rqt_compl);c4iw_destroy_resource (&rdev->resource); }
drivers/infiniband/hw/cxgb4/iw_cxgb4.h +4 -0
@@ -157,6 +157,10 @@ struct c4iw_rdev {void __iomem *oc_mw_kva;struct c4iw_stats stats;struct t4_dev_status_page *status_page; +struct completion rqt_compl; +struct completion pbl_compl; +struct kref rqt_kref; +struct kref pbl_kref; };static inline int c4iw_fatal_error (struct c4iw_rdev *rdev)
drivers/infiniband/hw/cxgb4/resource.c +24 -2
@@ -260,12 +260,22 @@ u32 c4iw_pblpool_alloc(struct c4iw_rdev rdev->stats.pbl.cur +=roundup (size,1 <<MIN_PBL_SHIFT );if (rdev->stats.pbl.cur > rdev->stats.pbl.max) rdev->stats.pbl.max = rdev->stats.pbl.cur; +kref_get (&rdev->pbl_kref); }else rdev->stats.pbl.fail++;mutex_unlock (&rdev->stats.lock);return (u32 )addr; } +static void destroy_pblpool (struct kref *kref) +{ +struct c4iw_rdev *rdev; + + rdev = container_of(kref, struct c4iw_rdev, pbl_kref); +gen_pool_destroy (rdev->pbl_pool); +complete (&rdev->pbl_compl); +} +void c4iw_pblpool_free (struct c4iw_rdev *rdev,u32 addr,int size) {PDBG ("%s addr 0x%x size %d\n" , __func__, addr, size);
@@ -273,6 +283,7 @@ void c4iw_pblpool_free(struct c4iw_rdev rdev->stats.pbl.cur -=roundup (size,1 <<MIN_PBL_SHIFT );mutex_unlock (&rdev->stats.lock);gen_pool_free (rdev->pbl_pool, (unsigned long )addr, size); +kref_put (&rdev->pbl_kref, destroy_pblpool); }int c4iw_pblpool_create (struct c4iw_rdev *rdev)
@@ -312,7 +323,7 @@ int c4iw_pblpool_create(struct c4iw_rdevvoid c4iw_pblpool_destroy (struct c4iw_rdev *rdev) { -gen_pool_destroy (rdev->pbl_pool); +kref_put (&rdev->pbl_kref, destroy_pblpool); }/*
@@ -333,12 +344,22 @@ u32 c4iw_rqtpool_alloc(struct c4iw_rdev rdev->stats.rqt.cur +=roundup (size <<6 ,1 <<MIN_RQT_SHIFT );if (rdev->stats.rqt.cur > rdev->stats.rqt.max) rdev->stats.rqt.max = rdev->stats.rqt.cur; +kref_get (&rdev->rqt_kref); }else rdev->stats.rqt.fail++;mutex_unlock (&rdev->stats.lock);return (u32 )addr; } +static void destroy_rqtpool (struct kref *kref) +{ +struct c4iw_rdev *rdev; + + rdev = container_of(kref, struct c4iw_rdev, rqt_kref); +gen_pool_destroy (rdev->rqt_pool); +complete (&rdev->rqt_compl); +} +void c4iw_rqtpool_free (struct c4iw_rdev *rdev,u32 addr,int size) {PDBG ("%s addr 0x%x size %d\n" , __func__, addr, size <<6 );
@@ -346,6 +367,7 @@ void c4iw_rqtpool_free(struct c4iw_rdev rdev->stats.rqt.cur -=roundup (size <<6 ,1 <<MIN_RQT_SHIFT );mutex_unlock (&rdev->stats.lock);gen_pool_free (rdev->rqt_pool, (unsigned long )addr, size <<6 ); +kref_put (&rdev->rqt_kref, destroy_rqtpool); }int c4iw_rqtpool_create (struct c4iw_rdev *rdev)
@@ -383,7 +405,7 @@ int c4iw_rqtpool_create(struct c4iw_rdevvoid c4iw_rqtpool_destroy (struct c4iw_rdev *rdev) { -gen_pool_destroy (rdev->rqt_pool); +kref_put (&rdev->rqt_kref, destroy_rqtpool); }/*
PATCH 241/366 RDMA/iwpm: fix memory leak on map_info
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
commit f96416cea7bce9afe619c15e87fced70f93f9098 upstream.
In the cases where iwpm_hash_bucket is NULL and where function get_mapinfo_hash_bucket returns NULL then the map_info is never added to hash_bucket_head and hence there is a leak of map_info. Fix this by nullifying hash_bucket_head and if that is null we know that that map_info was not added to hash_bucket_head and hence map_info should be free'd.
Detected by CoverityScan, CID#1222481 ("Resource Leak")
--- drivers/infiniband/core/iwpm_util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/iwpm_util.c +4 -1
@@ -96,7 +96,7 @@ int iwpm_create_mapinfo(struct sockaddr_ struct sockaddr_storage *mapped_sockaddr, u8 nl_client) { -struct hlist_head *hash_bucket_head; +struct hlist_head *hash_bucket_head =NULL ;struct iwpm_mapping_info *map_info;unsigned long flags;
@@ -121,6 +121,9 @@ int iwpm_create_mapinfo(struct sockaddr_hlist_add_head (&map_info->hlist_node, hash_bucket_head); }spin_unlock_irqrestore (&iwpm_mapinfo_lock, flags); + +if (!hash_bucket_head) +kfree (map_info);return 0 ; }EXPORT_SYMBOL (iwpm_create_mapinfo);
PATCH 219/366 ALSA: hdspm: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 10513142a7114d251670361ad40cba2c61403406 upstream.
As recently Smatch suggested, a couple of places in HDSP MADI driver
may expand the array directly from the user-space value with
speculation:
sound/pci/rme9652/hdspm.c:5717 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_out' (local cap) sound/pci/rme9652/hdspm.c:5734 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_in' (local cap)
This patch puts array_index_nospec() for hardening against them.
--- sound/pci/rme9652/hdspm.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
sound/pci/rme9652/hdspm.c +14 -10
@@ -137,6 +137,7 @@#include <linux/pci.h> #include <linux/math64.h> #include <asm/io.h> +#include <linux/nospec.h> #include <sound/core.h> #include <sound/control.h>
@@ -5724,40 +5725,43 @@ static int snd_hdspm_channel_info(struct struct snd_pcm_channel_info *info) {struct hdspm *hdspm =snd_pcm_substream_chip (substream); +unsigned int channel = info->channel;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { -if (snd_BUG_ON (info->channel >= hdspm->max_channels_out)) { +if (snd_BUG_ON (channel >= hdspm->max_channels_out)) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: output channel out of range (%d)\n" , - info->channel); + channel);return -EINVAL ; } -if (hdspm->channel_map_out[info->channel] <0 ) { + channel =array_index_nospec (channel, hdspm->max_channels_out); +if (hdspm->channel_map_out[channel] <0 ) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: output channel %d mapped out\n" , - info->channel); + channel);return -EINVAL ; } - info->offset = hdspm->channel_map_out[info->channel] * + info->offset = hdspm->channel_map_out[channel] *HDSPM_CHANNEL_BUFFER_BYTES ; }else { -if (snd_BUG_ON (info->channel >= hdspm->max_channels_in)) { +if (snd_BUG_ON (channel >= hdspm->max_channels_in)) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: input channel out of range (%d)\n" , - info->channel); + channel);return -EINVAL ; } -if (hdspm->channel_map_in[info->channel] <0 ) { + channel =array_index_nospec (channel, hdspm->max_channels_in); +if (hdspm->channel_map_in[channel] <0 ) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: input channel %d mapped out\n" , - info->channel); + channel);return -EINVAL ; } - info->offset = hdspm->channel_map_in[info->channel] * + info->offset = hdspm->channel_map_in[channel] *HDSPM_CHANNEL_BUFFER_BYTES ; }
PATCH 245/366 tracepoint: Do not warn on ENOMEM
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mathieu Desnoyers <[email protected]>
commit d66a270be3310d7aa132fec0cea77d3d32a0ff75 upstream.
Tracepoint should only warn when a kernel API user does not respect the required preconditions (e.g. same tracepoint enabled twice, or called to remove a tracepoint that does not exist).
Silence warning in out-of-memory conditions, given that the error is returned to the caller.
This ensures that out-of-memory error-injection testing does not trigger warnings in tracepoint.c, which were seen by syzbot.
--- kernel/tracepoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +2 -2
@@ -185,7 +185,7 @@ static int tracepoint_add_func(struct tr lockdep_is_held(&tracepoints_mutex)); old =func_add (&tp_funcs, func);if (IS_ERR (old)) { -WARN_ON_ONCE (1 ); +WARN_ON_ONCE (PTR_ERR (old) != -ENOMEM );return PTR_ERR (old); }
@@ -218,7 +218,7 @@ static int tracepoint_remove_func(struct lockdep_is_held(&tracepoints_mutex)); old =func_remove (&tp_funcs, func);if (IS_ERR (old)) { -WARN_ON_ONCE (1 ); +WARN_ON_ONCE (PTR_ERR (old) != -ENOMEM );return PTR_ERR (old); }
PATCH 247/366 tcp: fix TCP_REPAIR_QUEUE bound checking
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit bf2acc943a45d2b2e8a9f1a5ddff6b6e43cc69d9 upstream.
syzbot is able to produce a nasty WARN_ON() in tcp_verify_left_out() with following C-repro :
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3setsockopt(3, SOL_TCP, TCP_REPAIR, [1], 4) = 0setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0bind(3, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 sendto(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
1242, MSG_FASTOPEN, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("127.0.0.1")}, 16) = 1242setsockopt(3, SOL_TCP, TCP_REPAIR_WINDOW, "\4\0\0@+\205\0\0\377\377\0\0\377\377\377\177\0\0\0\0", 20) = 0writev(3, [{"\270", 1}], 1) = 1
setsockopt(3, SOL_TCP, TCP_REPAIR_OPTIONS, "\10\0\0\0\0\0\0\0\0\0\0\0|\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 386) = 0 writev(3, [{"\210v\r[\226\320t\231qwQ\204\264l\254\t\1\20\245\214p\350H\223\254;\\\37\345\307p$"..., 3144}], 1) = 3144
The 3rd system call looks odd :setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0
This patch makes sure bound checking is using an unsigned compare.
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -2551,7 +2551,7 @@ static int do_tcp_setsockopt(struct sockcase TCP_REPAIR_QUEUE :if (!tp->repair) err = -EPERM ; -else if (val <TCP_QUEUES_NR ) +else if ((unsigned int )val <TCP_QUEUES_NR ) tp->repair_queue = val;else err = -EINVAL ;
PATCH 216/366 ALSA: opl3: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 7f054a5bee0987f1e2d4e59daea462421c76f2cb upstream.
As recently Smatch suggested, one place in OPL3 driver may expand the
array directly from the user-space value with speculation:
sound/drivers/opl3/opl3_synth.c:476 snd_opl3_set_voice() warn: potential spectre issue 'snd_opl3_regmap'
This patch puts array_index_nospec() for hardening against it.
--- sound/drivers/opl3/opl3_synth.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/drivers/opl3/opl3_synth.c +5 -2
@@ -21,6 +21,7 @@#include <linux/slab.h> #include <linux/export.h> +#include <linux/nospec.h> #include <sound/opl3.h> #include <sound/asound_fm.h>
@@ -448,7 +449,7 @@ static int snd_opl3_set_voice(struct snd {unsigned short reg_side;unsigned char op_offset; -unsigned char voice_offset; +unsigned char voice_offset, voice_op;unsigned short opl3_reg;unsigned char reg_val;
@@ -473,7 +474,9 @@ static int snd_opl3_set_voice(struct snd voice_offset = voice->voice -MAX_OPL2_VOICES ; }/* Get register offset of operator */ - op_offset = snd_opl3_regmap[voice_offset][voice->op]; + voice_offset =array_index_nospec (voice_offset,MAX_OPL2_VOICES ); + voice_op =array_index_nospec (voice->op,4 ); + op_offset = snd_opl3_regmap[voice_offset][voice_op]; reg_val =0x00 ;/* Set amplitude modulation (tremolo) effect */
PATCH 246/366 usb: musb: host: fix potential NULL pointer dereference
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bin Liu <[email protected]>
commit 2b63f1329df2cd814c1f8353fae4853ace6521d1 upstream.
musb_start_urb() doesn't check the pass-in parameter if it is NULL. But in musb_bulk_nak_timeout() the parameter passed to musb_start_urb() is returned from first_qh(), which could be NULL.
So wrap the musb_start_urb() call here with a if condition check to avoid the potential NULL pointer dereference.
--- drivers/usb/musb/musb_host.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_host.c +3 -1
@@ -1002,7 +1002,9 @@ static void musb_bulk_nak_timeout(struct/* set tx_reinit and schedule the next qh */ ep->tx_reinit =1 ; } -musb_start_urb (musb, is_in, next_qh); + +if (next_qh) +musb_start_urb (musb, is_in, next_qh); } }
PATCH 254/366 ipv4: fix fnhe usage by non-cached routes
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
commit 94720e3aee6884d8c8beb678001629da60ec6366 upstream.
Allow some non-cached routes to use non-expired fnhe:
1. ip_del_fnhe: moved above and now called by find_exception. The 4.5+ commit deed49df7390 expires fnhe only when caching routes. Change that to:
1.1. use fnhe for non-cached local output routes, with the help from (2)
1.2. allow __mkroute_input to detect expired fnhe (outdated fnhe_gw, for example) when do_cache is false, eg. when itag!=0 for unicast destinations.
2. __mkroute_output: keep fi to allow local routes with orig_oif != 0 to use fnhe info even when the new route will not be cached into fnhe. After commit 839da4d98960 ("net: ipv4: set orig_oif based on fib result for local traffic") it means all local routes will be affected because they are not cached. This change is used to solve a PMTU problem with IPVS (and probably Netfilter DNAT) setups that redirect local clients from target local IP (local route to Virtual IP) to new remote IP target, eg. IPVS TUN real server. Loopback has 64K MTU and we need to create fnhe on the local route that will keep the reduced PMTU for the Virtual IP. Without this change fnhe_pmtu is updated from ICMP but never exposed to non-cached local routes. This includes routes with flowi4_oif!=0 for 4.6+ and with flowi4_oif=any for 4.14+).
3. update_or_create_fnhe: make sure fnhe_expires is not 0 for new entries
--- net/ipv4/route.c | 118 +++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 65 deletions(-)
net/ipv4/route.c +53 -65
@@ -684,7 +684,7 @@ static void update_or_create_fnhe(struct fnhe->fnhe_gw = gw; fnhe->fnhe_pmtu = pmtu; fnhe->fnhe_mtu_locked = lock; - fnhe->fnhe_expires = expires; + fnhe->fnhe_expires =max (1UL , expires);/* Exception created; mark the cached routes for the nexthop * stale, so anyone caching it rechecks if this exception
@@ -1259,6 +1259,36 @@ static unsigned int ipv4_mtu(const struc return min_t(unsigned int, mtu, IP_MAX_MTU); } +static void ip_del_fnhe (struct fib_nh *nh,__be32 daddr) +{ +struct fnhe_hash_bucket *hash; +struct fib_nh_exception *fnhe,__rcu **fnhe_p; +u32 hval =fnhe_hashfun (daddr); + +spin_lock_bh (&fnhe_lock); + + hash =rcu_dereference_protected (nh->nh_exceptions, +lockdep_is_held (&fnhe_lock)); + hash += hval; + + fnhe_p = &hash->chain; + fnhe =rcu_dereference_protected (*fnhe_p,lockdep_is_held (&fnhe_lock)); +while (fnhe) { +if (fnhe->fnhe_daddr == daddr) { +rcu_assign_pointer (*fnhe_p,rcu_dereference_protected ( + fnhe->fnhe_next,lockdep_is_held (&fnhe_lock))); +fnhe_flush_routes (fnhe); +kfree_rcu (fnhe, rcu); +break ; + } + fnhe_p = &fnhe->fnhe_next; + fnhe =rcu_dereference_protected (fnhe->fnhe_next, +lockdep_is_held (&fnhe_lock)); + } + +spin_unlock_bh (&fnhe_lock); +} +static struct fib_nh_exception *find_exception (struct fib_nh *nh,__be32 daddr) {struct fnhe_hash_bucket *hash = nh->nh_exceptions;
@@ -1272,8 +1302,14 @@ static struct fib_nh_exception *find_excfor (fnhe =rcu_dereference (hash[hval].chain); fnhe; fnhe =rcu_dereference (fnhe->fnhe_next)) { -if (fnhe->fnhe_daddr == daddr) +if (fnhe->fnhe_daddr == daddr) { +if (fnhe->fnhe_expires && +time_after (jiffies, fnhe->fnhe_expires)) { +ip_del_fnhe (nh, daddr); +break ; + }return fnhe; + } }return NULL ; }
@@ -1568,36 +1604,6 @@ static void ip_handle_martian_source(str#endif } -static void ip_del_fnhe (struct fib_nh *nh,__be32 daddr) -{ -struct fnhe_hash_bucket *hash; -struct fib_nh_exception *fnhe,__rcu **fnhe_p; -u32 hval =fnhe_hashfun (daddr); - -spin_lock_bh (&fnhe_lock); - - hash =rcu_dereference_protected (nh->nh_exceptions, -lockdep_is_held (&fnhe_lock)); - hash += hval; - - fnhe_p = &hash->chain; - fnhe =rcu_dereference_protected (*fnhe_p,lockdep_is_held (&fnhe_lock)); -while (fnhe) { -if (fnhe->fnhe_daddr == daddr) { -rcu_assign_pointer (*fnhe_p,rcu_dereference_protected ( - fnhe->fnhe_next,lockdep_is_held (&fnhe_lock))); -fnhe_flush_routes (fnhe); -kfree_rcu (fnhe, rcu); -break ; - } - fnhe_p = &fnhe->fnhe_next; - fnhe =rcu_dereference_protected (fnhe->fnhe_next, -lockdep_is_held (&fnhe_lock)); - } - -spin_unlock_bh (&fnhe_lock); -} -/* called in rcu_read_lock() section */ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
@@ -1651,20 +1657,10 @@ static int __mkroute_input(struct sk_buf fnhe =find_exception (&FIB_RES_NH (*res), daddr);if (do_cache) { -if (fnhe) { +if (fnhe) rth =rcu_dereference (fnhe->fnhe_rth_input); -if (rth && rth->dst.expires && -time_after (jiffies, rth->dst.expires)) { -ip_del_fnhe (&FIB_RES_NH (*res), daddr); - fnhe =NULL ; - }else { - goto rt_cache; - } - } - - rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input); - -rt_cache: +else + rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input);if (rt_cache_valid (rth)) {skb_dst_set_noref (skb, &rth->dst); goto out;
@@ -2000,39 +1996,31 @@ static struct rtable *__mkroute_output(c* the loopback interface and the IP_PKTINFO ipi_ifindex will * be set to the loopback interface as well. */ - fi =NULL ; + do_cache = false; } fnhe =NULL ; do_cache &= fi !=NULL ; -if (do_cache) { +if (fi) {struct rtable __rcu **prth;struct fib_nh *nh = &FIB_RES_NH (*res); fnhe =find_exception (nh, fl4->daddr); +if (!do_cache) + goto add;if (fnhe) { prth = &fnhe->fnhe_rth_output; - rth =rcu_dereference (*prth); -if (rth && rth->dst.expires && -time_after (jiffies, rth->dst.expires)) { -ip_del_fnhe (nh, fl4->daddr); - fnhe =NULL ; - }else { - goto rt_cache; + }else { +if (unlikely (fl4->flowi4_flags & +FLOWI_FLAG_KNOWN_NH && + !(nh->nh_gw && + nh->nh_scope ==RT_SCOPE_LINK ))) { + do_cache = false; + goto add; } + prth =raw_cpu_ptr (nh->nh_pcpu_rth_output); } - -if (unlikely (fl4->flowi4_flags & -FLOWI_FLAG_KNOWN_NH && - !(nh->nh_gw && - nh->nh_scope ==RT_SCOPE_LINK ))) { - do_cache = false; - goto add; - } - prth =raw_cpu_ptr (nh->nh_pcpu_rth_output); rth =rcu_dereference (*prth); - -rt_cache:if (rt_cache_valid (rth)) {dst_hold (&rth->dst);return rth;
PATCH 261/366 sched/core: Fix possible Spectre-v1 indexing for sched_prio_to_weight[]
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 7281c8dec8a87685cb54d503d8cceef5a0fc2fdd upstream.
Quoted 1 line
kernel/sched/core.c:6921cpu_weight_nice_write_s64()warn: potential spectre issue 'sched_prio_to_weight'
Userspace controls @nice, so sanitize the value before using it to index an array.
---
kernel/sched/core.c +3 -0
@@ -74,6 +74,7 @@#include <linux/binfmts.h> #include <linux/context_tracking.h> #include <linux/compiler.h> +#include <linux/nospec.h> #include <asm/switch_to.h> #include <asm/tlb.h>
@@ -820,6 +821,8 @@ static void set_load_weight(struct task_return ; } + prio =array_index_nospec (prio,40 ); + load->weight =scale_load (prio_to_weight[prio]); load->inv_weight = prio_to_wmult[prio]; }
PATCH 244/366 ALSA: aloop: Add missing cable lock to ctl API callbacks
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 76b3421b39bd610546931fc923edcf90c18fa395 upstream.
Some control API callbacks in aloop driver are too lazy to take the loopback->cable_lock and it results in possible races of cable access while it's being freed. It eventually lead to a UAF, as reported by fuzzer recently.
This patch covers such control API callbacks and add the proper mutex locks.
--- sound/drivers/aloop.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/drivers/aloop.c +15 -2
@@ -829,9 +829,11 @@ static int loopback_rate_shift_get(struc {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate_shift; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -863,9 +865,11 @@ static int loopback_notify_get(struct sn {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -877,12 +881,14 @@ static int loopback_notify_put(struct snint change =0 ; val = ucontrol->value.integer.value[0 ] ?1 :0 ; +mutex_lock (&loopback->cable_lock);if (val != loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify) { loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify = val; change =1 ; } +mutex_unlock (&loopback->cable_lock);return change; }
@@ -890,13 +896,16 @@ static int loopback_active_get(struct sn struct snd_ctl_elem_value *ucontrol) {struct loopback *loopback =snd_kcontrol_chip (kcontrol); -struct loopback_cable *cable = loopback->cables - [kcontrol->id.subdevice][kcontrol->id.device ^1 ]; +struct loopback_cable *cable; +unsigned int val =0 ; +mutex_lock (&loopback->cable_lock); + cable = loopback->cables[kcontrol->id.subdevice][kcontrol->id.device ^1 ];if (cable !=NULL ) val = (cable->running & (1 <<SNDRV_PCM_STREAM_PLAYBACK )) ?1 :0 ; +mutex_unlock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = val;return 0 ; }
@@ -939,9 +948,11 @@ static int loopback_rate_get(struct snd_ {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -961,9 +972,11 @@ static int loopback_channels_get(struct {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].channels; +mutex_unlock (&loopback->cable_lock);return 0 ; }
PATCH 259/366 atm: zatm: Fix potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Gustavo A. R. Silva" <[email protected]>
commit 2be147f7459db5bbf292e0a6f135037b55e20b39 upstream.
pool can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
This issue was detected with the help of Smatch:
drivers/atm/zatm.c:1462 zatm_ioctl() warn: potential spectre issue 'zatm_dev->pool_info' (local cap)
Fix this by sanitizing pool before using it to index zatm_dev->pool_info
Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1].
[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2
--- drivers/atm/zatm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/atm/zatm.c +3 -0
@@ -28,6 +28,7 @@#include <asm/io.h> #include <linux/atomic.h> #include <asm/uaccess.h> +#include <linux/nospec.h> #include "uPD98401.h" #include "uPD98402.h"
@@ -1455,6 +1456,8 @@ static int zatm_ioctl(struct atm_dev *dereturn -EFAULT ;if (pool <0 || pool >ZATM_LAST_POOL )return -EINVAL ; + pool =array_index_nospec (pool, +ZATM_LAST_POOL +1 );spin_lock_irqsave (&zatm_dev->lock, flags); info = zatm_dev->pool_info[pool];if (cmd ==ZATM_GETPOOLZ ) {
PATCH 260/366 net: atm: Fix potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Gustavo A. R. Silva" <[email protected]>
commit acf784bd0ce257fe43da7ca266f7a10b837479d2 upstream.
ioc_data.dev_num can be controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
This issue was detected with the help of Smatch:net/atm/lec.c:702 lec_vcc_attach() warn: potential spectre issue 'dev_lec'
Fix this by sanitizing ioc_data.dev_num before using it to index dev_lec. Also, notice that there is another instance in which array dev_lec is being indexed using ioc_data.dev_num at line 705:
lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1].
[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2
--- net/atm/lec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/atm/lec.c +7 -2
@@ -41,6 +41,9 @@ static unsigned char bridge_ula_lec[] =#include <linux/module.h> #include <linux/init.h> +/* Hardening for Spectre-v1 */ +#include <linux/nospec.h> +#include "lec.h" #include "lec_arpc.h" #include "resources.h"
@@ -695,8 +698,10 @@ static int lec_vcc_attach(struct atm_vcc bytes_left =copy_from_user (&ioc_data, arg,sizeof (struct atmlec_ioc ));if (bytes_left !=0 )pr_info ("copy from user failed for %d bytes\n" , bytes_left); -if (ioc_data.dev_num <0 || ioc_data.dev_num >=MAX_LEC_ITF || - !dev_lec[ioc_data.dev_num]) +if (ioc_data.dev_num <0 || ioc_data.dev_num >=MAX_LEC_ITF ) +return -EINVAL ; + ioc_data.dev_num =array_index_nospec (ioc_data.dev_num,MAX_LEC_ITF ); +if (!dev_lec[ioc_data.dev_num])return -EINVAL ; vpriv =kmalloc (sizeof (struct lec_vcc_priv ),GFP_KERNEL );if (!vpriv)
PATCH 258/366 bdi: Fix oops in wb_workfn()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit b8b784958eccbf8f51ebeee65282ca3fd59ea391 upstream.
Syzbot has reported that it can hit a NULL pointer dereference in wb_workfn() due to wb->bdi->dev being NULL. This indicates that wb_workfn() was called for an already unregistered bdi which should not happen as wb_shutdown() called from bdi_unregister() should make sure all pending writeback works are completed before bdi is unregistered. Except that wb_workfn() itself can requeue the work with:
mod_delayed_work(bdi_wq, &wb->dwork, 0);
and if this happens while wb_shutdown() is waiting in:
flush_delayed_work(&wb->dwork);
the dwork can get executed after wb_shutdown() has finished and bdi_unregister() has cleared wb->bdi->dev.
Make wb_workfn() use wakeup_wb() for requeueing the work which takes all the necessary precautions against racing with bdi unregistration.
[bwh: Backported to 3.16:
- Use bdi_wakeup_thread() instead of wb_wakeup()
- Adjust context]
--- fs/fs-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs-writeback.c +1 -1
@@ -1071,7 +1071,7 @@ void bdi_writeback_workfn(struct work_st }if (!list_empty (&bdi->work_list)) -mod_delayed_work (bdi_wq, &wb->dwork,0 ); +bdi_wakeup_thread (bdi);else if (wb_has_dirty_io (wb) && dirty_writeback_interval)bdi_wakeup_thread_delayed (bdi);
PATCH 134/366 fs/proc/proc_sysctl.c: fix potential page fault while unregistering sysctl table
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Danilo Krummrich <[email protected]>
commit a0b0d1c345d0317efe594df268feb5ccc99f651e upstream.
proc_sys_link_fill_cache() does not take currently unregistering sysctl tables into account, which might result into a page fault in sysctl_follow_link() - add a check to fix it.
This bug has been present since v3.4.
--- fs/proc/proc_sysctl.c | 3 +++ 1 file changed, 3 insertions(+)
fs/proc/proc_sysctl.c +3 -0
@@ -654,7 +654,10 @@ static bool proc_sys_link_fill_cache(str struct ctl_table *table) {bool ret = true; + head =sysctl_head_grab (head); +if (IS_ERR (head)) +return false;if (S_ISLNK (table->mode)) {/* It is not an error if we can not follow the link ignore it */
PATCH 251/366 sctp: fix the issue that the cookie-ack with auth can't get processed
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit ce402f044e4e432c296f90eaabb8dbe8f3624391 upstream.
When auth is enabled for cookie-ack chunk, in sctp_inq_pop, sctp processes auth chunk first, then continues to the next chunk in this packet if chunk_end + chunk_hdr size < skb_tail_pointer(). Otherwise, it will go to the next packet or discard this chunk.
However, it missed the fact that cookie-ack chunk's size is equal to chunk_hdr size, which couldn't match that check, and thus this chunk would not get processed.
This patch fixes it by changing the check to chunk_end + chunk_hdr size <= skb_tail_pointer().
--- net/sctp/inqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/inqueue.c +1 -1
@@ -178,7 +178,7 @@ struct sctp_chunk *sctp_inq_pop(struct sskb_pull (chunk->skb,sizeof (sctp_chunkhdr_t)); chunk->subh.v =NULL ;/* Subheader is no longer valid. */ -if (chunk->chunk_end +sizeof (sctp_chunkhdr_t) < +if (chunk->chunk_end +sizeof (sctp_chunkhdr_t) <=skb_tail_pointer (chunk->skb)) {/* This is not a singleton */ chunk->singleton =0 ;
PATCH 250/366 clocksource: Initialize cs->wd_list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 5b9e886a4af97574ca3ce1147f35545da0e7afc7 upstream.
A number of places relies on list_empty(&cs->wd_list), however the list_head does not get initialized. Do so upon registration, such that thereafter it is possible to rely on list_empty() correctly reflecting the list membership status.
--- kernel/time/clocksource.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/clocksource.c +2 -0
@@ -385,6 +385,8 @@ static void clocksource_enqueue_watchdog {unsigned long flags; +INIT_LIST_HEAD (&cs->wd_list); +spin_lock_irqsave (&watchdog_lock, flags);if (cs->flags &CLOCK_SOURCE_MUST_VERIFY ) {/* cs is a clocksource to be watched. */
PATCH 44/366 usb: dwc3: pci: Properly cleanup resource
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Thinh Nguyen <[email protected]>
commit cabdf83dadfb3d83eec31e0f0638a92dbd716435 upstream.
Platform device is allocated before adding resources. Make sure to properly cleanup on error case.
--- drivers/usb/dwc3/dwc3-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-pci.c +1 -1
@@ -144,7 +144,7 @@ static int dwc3_pci_probe(struct pci_dev ret =platform_device_add_resources (dwc3, res,ARRAY_SIZE (res));if (ret) {dev_err (dev,"couldn't add resources to dwc3 device\n" ); -return ret; + goto err3; }pci_set_drvdata (pci, glue);
PATCH 252/366 bpf, x64: fix memleak when not converging after image
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
commit 3aab8884c9eb99189a3569ac4e6b205371c9ac0b upstream.
While reviewing x64 JIT code, I noticed that we leak the prior allocated JIT image in the case where proglen != oldproglen during the JIT passes. Prior to the commit e0ee9c12157d ("x86: bpf_jit: fix two bugs in eBPF JIT compiler") we would just break out of the loop, and using the image as the JITed prog since it could only shrink in size anyway. After e0ee9c12157d, we would bail out to out_addrs label where we free addrs and jit_data but not the image coming from bpf_jit_binary_alloc().
--- arch/x86/net/bpf_jit_comp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +2 -1
@@ -914,6 +914,7 @@ void bpf_int_jit_compile(struct sk_filtefor (pass =0 ; pass <10 || image; pass++) { proglen =do_jit (prog, addrs, image, oldproglen, &ctx);if (proglen <=0 ) { +out_image: image =NULL ;if (header)module_free (NULL , header);
@@ -923,7 +924,7 @@ void bpf_int_jit_compile(struct sk_filteif (proglen != oldproglen) {pr_err ("bpf_jit: proglen=%d != oldproglen=%d\n" , proglen, oldproglen); - goto out; + goto out_image; }break ; }
PATCH 52/366 ALSA: pcm: Use ERESTARTSYS instead of EINTR in OSS emulation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit c64ed5dd9feba193c76eb460b451225ac2a0d87b upstream.
Fix the last standing EINTR in the whole subsystem. Use more correct ERESTARTSYS for pending signals.
--- sound/core/oss/pcm_oss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/oss/pcm_oss.c +1 -1
@@ -852,7 +852,7 @@ static int snd_pcm_oss_change_params(strif (!(mutex_trylock (&runtime->oss.params_lock)))return -EAGAIN ; }else if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -EINTR ; +return -ERESTARTSYS ; sw_params =kmalloc (sizeof (*sw_params),GFP_KERNEL ); params =kmalloc (sizeof (*params),GFP_KERNEL ); sparams =kmalloc (sizeof (*sparams),GFP_KERNEL );
PATCH 48/366 USB: serial: ftdi_sio: add support for Harman FirmwareHubEmulator
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Clemens Werther <[email protected]>
commit 6555ad13a01952c16485c82a52ad1f3e07e34b3a upstream.
Add device id for Harman FirmwareHubEmulator to make the device auto-detectable by the driver.
--- drivers/usb/serial/ftdi_sio.c | 1 + drivers/usb/serial/ftdi_sio_ids.h | 6 ++++++ 2 files changed, 7 insertions(+)
drivers/usb/serial/ftdi_sio.c +1 -0
@@ -949,6 +949,7 @@ static const struct usb_device_id id_tab { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_LS_LOGBOOK_PID) }, { USB_DEVICE(FTDI_VID, FTDI_SCIENCESCOPE_HS_LOGBOOK_PID) }, { USB_DEVICE(FTDI_VID, FTDI_CINTERION_MC55I_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_FHE_PID) }, { USB_DEVICE(FTDI_VID, FTDI_DOTEC_PID) }, { USB_DEVICE(QIHARDWARE_VID, MILKYMISTONE_JTAGSERIAL_PID), .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
drivers/usb/serial/ftdi_sio_ids.h +6 -0
@@ -1444,6 +1444,12 @@#define FTDI_CINTERION_MC55I_PID 0xA951/* +* Product: FirmwareHubEmulator +* Manufacturer: Harman Becker Automotive Systems +*/ +#define FTDI_FHE_PID 0xA9A0 + +/* * Product: Comet Caller ID decoder * Manufacturer: Crucible Technologies */
PATCH 70/366 ipc/sem: make semctl setting sempid consistent
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Davidlohr Bueso <[email protected]>
commit a5f4db877177d2a3d7ae62a7bac3a5a27e083d7f upstream.
As indicated by bug#112271, Linux sets the sempid value upon semctl, and not only for semop calls. However, within semctl we only do this for SETVAL, leaving SETALL without updating the field, and therefore rather inconsistent behavior when compared to other Unices.
There is really no documentation regarding this and therefore users should not make assumptions. With this patch, along with updating semctl.2 manpages, this scenario should become less ambiguous As such, set sempid on SETALL cmd.
Also update some in-code documentation, specifying where the sempid is set.
Passes ltp and custom testcase where a child (fork) does SETALL to the set.
--- ipc/sem.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
ipc/sem.c +11 -2
@@ -92,7 +92,14 @@/* One semaphore structure for each semaphore in the system. */ struct sem {int semval;/* current value */ -int sempid;/* pid of last operation */ +/* +* PID of the process that last modified the semaphore. For +* Linux, specifically these are: +* - semop +* - semctl, via SETVAL and SETALL. +* - at task exit when performing undo adjustments (see exit_sem). +*/ +int sempid;spinlock_t lock;/* spinlock for fine-grained semtimedop */ struct list_head pending_alter;/* pending single-sop operations */ /* that alter the semaphore */
@@ -1469,8 +1476,10 @@ static int semctl_main(struct ipc_namesp goto out_unlock; } -for (i =0 ; i < nsems; i++) +for (i =0 ; i < nsems; i++) { sma->sem_base[i].semval = sem_io[i]; + sma->sem_base[i].sempid =task_tgid_vnr (current); + }ipc_assert_locked_object (&sma->sem_perm);list_for_each_entry (un, &sma->list_id, list_id) {
PATCH 249/366 USB: serial: visor: handle potential invalid device configuration
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 4842ed5bfcb9daf6660537d70503c18d38dbdbb8 upstream.
If we get an invalid device configuration from a palm 3 type device, we might incorrectly parse things, and we have the potential to crash in "interesting" ways.
Fix this up by verifying the size of the configuration passed to us by the device, and only if it is correct, will we handle it.
Note that this also fixes an information leak of slab data.
--- drivers/usb/serial/visor.c | 69 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
drivers/usb/serial/visor.c +35 -34
@@ -338,47 +338,48 @@ static int palm_os_3_probe(struct usb_se goto exit; } -if (retval ==sizeof (*connection_info)) { - connection_info = (struct visor_connection_info *) - transfer_buffer; - - num_ports =le16_to_cpu (connection_info->num_ports); -for (i =0 ; i < num_ports; ++i) { -switch ( - connection_info->connections[i].port_function_id) { -case VISOR_FUNCTION_GENERIC : - string ="Generic" ; -break ; -case VISOR_FUNCTION_DEBUGGER : - string ="Debugger" ; -break ; -case VISOR_FUNCTION_HOTSYNC : - string ="HotSync" ; -break ; -case VISOR_FUNCTION_CONSOLE : - string ="Console" ; -break ; -case VISOR_FUNCTION_REMOTE_FILE_SYS : - string ="Remote File System" ; -break ; -default : - string ="unknown" ; -break ; - } -dev_info (dev,"%s: port %d, is for %s use\n" , - serial->type->description, - connection_info->connections[i].port, string); - } +if (retval !=sizeof (*connection_info)) { +dev_err (dev,"Invalid connection information received from device\n" ); + retval = -ENODEV ; + goto exit; } -/* -* Handle devices that report invalid stuff here. -*/ + + connection_info = (struct visor_connection_info *)transfer_buffer; + + num_ports =le16_to_cpu (connection_info->num_ports); + +/* Handle devices that report invalid stuff here. */ if (num_ports ==0 || num_ports >2 ) {dev_warn (dev,"%s: No valid connect info available\n" , serial->type->description); num_ports =2 ; } +for (i =0 ; i < num_ports; ++i) { +switch (connection_info->connections[i].port_function_id) { +case VISOR_FUNCTION_GENERIC : + string ="Generic" ; +break ; +case VISOR_FUNCTION_DEBUGGER : + string ="Debugger" ; +break ; +case VISOR_FUNCTION_HOTSYNC : + string ="HotSync" ; +break ; +case VISOR_FUNCTION_CONSOLE : + string ="Console" ; +break ; +case VISOR_FUNCTION_REMOTE_FILE_SYS : + string ="Remote File System" ; +break ; +default : + string ="unknown" ; +break ; + } +dev_info (dev,"%s: port %d, is for %s use\n" , + serial->type->description, + connection_info->connections[i].port, string); + }dev_info (dev,"%s: Number of ports: %d\n" , serial->type->description, num_ports);
PATCH 45/366 ext4: protect i_disksize update by i_data_sem in direct write path
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eryu Guan <[email protected]>
commit 73fdad00b208b139cf43f3163fbc0f67e4c6047c upstream.
i_disksize update should be protected by i_data_sem, by either taking the lock explicitly or by using ext4_update_i_disksize() helper. But the i_disksize updates in ext4_direct_IO_write() are not protected at all, which may be racing with i_disksize updates in writeback path in delalloc buffer write path.
This is found by code inspection, and I didn't hit any i_disksize corruption due to this bug. Thanks to Jan Kara for catching this bug and suggesting the fix!
---
fs/ext4/indirect.c +2 -3
@@ -649,7 +649,6 @@ ssize_t ext4_ind_direct_IO(int rw, struc {struct file *file = iocb->ki_filp;struct inode *inode = file->f_mapping->host; -struct ext4_inode_info *ei =EXT4_I (inode);handle_t *handle;ssize_t ret;int orphan =0 ;
@@ -672,7 +671,7 @@ ssize_t ext4_ind_direct_IO(int rw, struc goto out; } orphan =1 ; - ei->i_disksize = inode->i_size; +ext4_update_i_disksize (inode, inode->i_size);ext4_journal_stop (handle); } }
@@ -731,7 +730,7 @@ locked:if (ret >0 ) {loff_t end = offset + ret;if (end > inode->i_size) { - ei->i_disksize = end; +ext4_update_i_disksize (inode, end);i_size_write (inode, end);/* * We're going to return a positive `ret'
PATCH 174/366 scsi: sd: Defer spinning up drive while SANITIZE is in progress
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mahesh Rajashekhara <[email protected]>
commit 505aa4b6a8834a2300971c5220c380c3271ebde3 upstream.
A drive being sanitized will return NOT READY / ASC 0x4 / ASCQ 0x1b ("LOGICAL UNIT NOT READY. SANITIZE IN PROGRESS").
Prevent spinning up the drive until this condition clears.
[mkp: tweaked commit message]
--- drivers/scsi/sd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/sd.c +2 -0
@@ -1832,6 +1832,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)break ;/* standby */ if (sshdr.asc ==4 && sshdr.ascq ==0xc )break ;/* unavailable */ +if (sshdr.asc ==4 && sshdr.ascq ==0x1b ) +break ;/* sanitize in progress */ /* * Issue command to spin up drive when not ready */
PATCH 118/366 crypto: af_alg - fix possible uninit-value in alg_bind()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit a466856e0b7ab269cdf9461886d007e88ff575b0 upstream.
syzbot reported :
BUG: KMSAN: uninit-value in alg_bind+0xe3/0xd90 crypto/af_alg.c:162
We need to check addr_len before dereferencing sa (or uaddr)
--- crypto/af_alg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
crypto/af_alg.c +4 -4
@@ -157,16 +157,16 @@ static int alg_bind(struct socket *sock,void *private;int err; -/* If caller uses non-allowed flag, return error. */ -if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed)) -return -EINVAL ; -if (sock->state ==SS_CONNECTED )return -EINVAL ;if (addr_len !=sizeof (*sa))return -EINVAL ; +/* If caller uses non-allowed flag, return error. */ +if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed)) +return -EINVAL ; + sa->salg_type[sizeof (sa->salg_type) -1 ] =0 ; sa->salg_name[sizeof (sa->salg_name) -1 ] =0 ;
PATCH 206/366 ALSA: usb-audio: Skip broken EU on Dell dock USB-audio
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 1d8d6428d1da642ddd75b0be2d1bb1123ff8e017 upstream.
The Dell Dock USB-audio device with 0bda:4014 is behaving notoriously bad, and we have already applied some workaround to avoid the firmware hiccup. Yet we still need to skip one thing, the Extension Unit at ID 4, which doesn't react correctly to the mixer ctl access.
Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1090658
--- sound/usb/mixer_maps.c | 3 +++ 1 file changed, 3 insertions(+)
sound/usb/mixer_maps.c +3 -0
@@ -346,8 +346,11 @@ static struct usbmix_name_map bose_compa/* * Dell usb dock with ALC4020 codec had a firmware problem where it got * screwed up when zero volume is passed; just skip it as a workaround +* +* Also the extension unit gives an access error, so skip it as well. */ static const struct usbmix_name_map dell_alc4020_map[] = { + {4 ,NULL },/* extension unit */ {16 ,NULL }, {19 ,NULL }, {0 }
PATCH 78/366 xen/acpi: off by one in read_acpi_id()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit c37a3c94775855567b90f91775b9691e10bd2806 upstream.
If acpi_id is == nr_acpi_bits, then we access one element beyond the end of the acpi_psd[] array or we set one bit beyond the end of the bit map when we do __set_bit(acpi_id, acpi_id_present);
--- drivers/xen/xen-acpi-processor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/xen/xen-acpi-processor.c +3 -3
@@ -362,9 +362,9 @@ read_acpi_id(acpi_handle handle, u32 lvl }/* There are more ACPI Processor objects than in x2APIC or MADT. * This can happen with incorrect ACPI SSDT declerations. */ -if (acpi_id > nr_acpi_bits) { -pr_debug ("We only have %u, trying to set %u\n" , - nr_acpi_bits, acpi_id); +if (acpi_id >= nr_acpi_bits) { +pr_debug ("max acpi id %u, trying to set %u\n" , + nr_acpi_bits -1 , acpi_id);return AE_OK ; }/* OK, There is a ACPI Processor object */
PATCH 57/366 s390/qdio: don't merge ERROR output buffers
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Wiedmann <[email protected]>
commit 0cf1e05157b9e5530dcc3ca9fec9bf617fc93375 upstream.
On an Output queue, both EMPTY and PENDING buffer states imply that the buffer is ready for completion-processing by the upper-layer drivers.
So for a non-QEBSM Output queue, get_buf_states() merges mixed batches of PENDING and EMPTY buffers into one large batch of EMPTY buffers. The upper-layer driver (ie. qeth) later distuingishes PENDING from EMPTY by inspecting the slsb_state for QDIO_OUTBUF_STATE_FLAG_PENDING.
But the merge logic in get_buf_states() contains a bug that causes us to erronously also merge ERROR buffers into such a batch of EMPTY buffers (ERROR is 0xaf, EMPTY is 0xa1; so ERROR & EMPTY == EMPTY). Effectively, most outbound ERROR buffers are currently discarded silently and processed as if they had succeeded.
Note that this affects _all_ non-QEBSM device types, not just IQD with CQ.
Fix it by explicitly spelling out the exact conditions for merging.
For extracting the "get initial state" part out of the loop, this relies on the fact that get_buf_states() is never called with a count of 0. The QEBSM path already strictly requires this, and the two callers with variable 'count' make sure of it.
--- drivers/s390/cio/qdio_main.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/s390/cio/qdio_main.c +20 -11
@@ -212,7 +212,10 @@ again:return 0 ; } -/* returns number of examined buffers and their common state in *state */ +/* +* Returns number of examined buffers and their common state in *state. +* Requested number of buffers-to-examine must be > 0. +*/ static inline int get_buf_states (struct qdio_q *q,unsigned int bufnr,unsigned char *state,unsigned int count,int auto_ack,int merge_pending)
@@ -223,17 +226,23 @@ static inline int get_buf_states(structif (is_qebsm (q))return qdio_do_eqbs (q, state, bufnr, count, auto_ack); -for (i =0 ; i < count; i++) { -if (!__state) { - __state = q->slsb.val[bufnr]; -if (merge_pending && __state ==SLSB_P_OUTPUT_PENDING ) - __state =SLSB_P_OUTPUT_EMPTY ; - }else if (merge_pending) { -if ((q->slsb.val[bufnr] & __state) != __state) -break ; - }else if (q->slsb.val[bufnr] != __state) -break ; +/* get initial state: */ + __state = q->slsb.val[bufnr]; +if (merge_pending && __state ==SLSB_P_OUTPUT_PENDING ) + __state =SLSB_P_OUTPUT_EMPTY ; + +for (i =1 ; i < count; i++) { bufnr =next_buf (bufnr); + +/* merge PENDING into EMPTY: */ +if (merge_pending && + q->slsb.val[bufnr] ==SLSB_P_OUTPUT_PENDING && + __state ==SLSB_P_OUTPUT_EMPTY ) +continue ; + +/* stop if next state differs from initial state: */ +if (q->slsb.val[bufnr] != __state) +break ; } *state = __state;return i;
PATCH 76/366 powerpc/powernv: Handle unknown OPAL errors in opal_nvram_write()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Piggin <[email protected]>
commit 741de617661794246f84a21a02fc5e327bffc9ad upstream.
opal_nvram_write currently just assumes success if it encounters an error other than OPAL_BUSY or OPAL_BUSY_EVENT. Have it return -EIO on other errors instead.
--- arch/powerpc/platforms/powernv/opal-nvram.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/powerpc/platforms/powernv/opal-nvram.c +4 -0
@@ -58,6 +58,10 @@ static ssize_t opal_nvram_write(char *buif (rc ==OPAL_BUSY_EVENT )opal_poll_events (NULL ); } + +if (rc) +return -EIO ; + *index += count;return count; }
PATCH 20/366 serial: imx: Fix out-of-bounds access through serial port index
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Geert Uytterhoeven <[email protected]>
commit 5673444821406dda5fc25e4b52aca419f8065a19 upstream.
The imx_ports[] array is indexed using a value derived from the "serialN" alias in DT, or from platform data, which may lead to an out-of-bounds access.
Fix this by adding a range check.
--- drivers/tty/serial/imx.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/tty/serial/imx.c +6 -0
@@ -1919,6 +1919,12 @@ static int serial_imx_probe(struct platfelse if (ret <0 )return ret; +if (sport->port.line >=ARRAY_SIZE (imx_ports)) { +dev_err (&pdev->dev,"serial%d out of range\n" , + sport->port.line); +return -EINVAL ; + } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); base =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (base))
PATCH 140/366 ALSA: line6: Use correct endpoint type for midi output
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Fabián Inostroza <[email protected]>
commit 7ecb46e9ee9af18e304eb9e7d6804c59a408e846 upstream.
Sending MIDI messages to a PODxt through the USB connection shows "usb_submit_urb failed" in dmesg and the message is not received by the POD.
The error is caused because in the funcion send_midi_async() in midi.c there is a call to usb_sndbulkpipe() for endpoint 3 OUT, but the PODxt USB descriptor shows that this endpoint it's an interrupt endpoint.
Patch tested with PODxt only.
[ The bug has been present from the very beginning in the staging
driver time, but Fixes below points to the commit moving to sound/ directory so that the fix can be cleanly applied -- tiwai ]
--- drivers/staging/line6/midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/line6/midi.c +1 -1
@@ -135,7 +135,7 @@ static int send_midi_async(struct usb_li }usb_fill_int_urb (urb, line6->usbdev, -usb_sndbulkpipe (line6->usbdev, +usb_sndintpipe (line6->usbdev, line6->ep_control_write), transfer_buffer, length, midi_sent, line6, line6->interval);
PATCH 103/366 Input: i8042 - enable MUX on Sony VAIO VGN-CS series to fix touchpad
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ondrej Zary <[email protected]>
commit 04bb1719c4de94700056241d4c0fe3c1413f5aff upstream.
The touch sensor buttons on Sony VAIO VGN-CS series laptops (e.g. VGN-CS31S) are a separate PS/2 device. As the MUX is disabled for all VAIO machines by the nomux blacklist, the data from touch sensor buttons and touchpad are combined. The protocol used by the buttons is probably similar to the touchpad protocol (both are Synaptics) so both devices get enabled. The controller combines the data, creating a mess which results in random button clicks, touchpad stopping working and lost sync error messages:
psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 4 psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 1 psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 1 psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 1 psmouse serio1: TouchPad at isa0060/serio1/input0 lost sync at byte 1 psmouse serio1: issuing reconnect request
Add a new i8042_dmi_forcemux_table whitelist with VGN-CS. With MUX enabled, touch sensor buttons are detected as separate device (and left disabled as there's currently no driver), fixing all touchpad problems.
--- drivers/input/serio/i8042-x86ia64io.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/input/serio/i8042-x86ia64io.h +17 -0
@@ -516,6 +516,20 @@ static const struct dmi_system_id __init { } }; +static const struct dmi_system_id i8042_dmi_forcemux_table[]__initconst = { + { +/* +* Sony Vaio VGN-CS series require MUX or the touch sensor +* buttons will disturb touchpad operation +*/ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Sony Corporation" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"VGN-CS" ), + }, + }, + { } +}; +static const struct dmi_system_id __initconst i8042_dmi_reset_table[] = { {/* MSI Wind U-100 */
@@ -1116,6 +1130,9 @@ static int __init i8042_platform_init(voif (dmi_check_system (i8042_dmi_nomux_table)) i8042_nomux = true; +if (dmi_check_system (i8042_dmi_forcemux_table)) + i8042_nomux = false; +if (dmi_check_system (i8042_dmi_notimeout_table)) i8042_notimeout = true;
PATCH 137/366 drm/radeon: add PX quirk for Asus K73TK
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nico Sneck <[email protected]>
commit b1550359d1eb392ee54f7cf47cffcfe0a602f6a7 upstream.
With this the dGPU turns on correctly.
--- drivers/gpu/drm/radeon/radeon_device.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/radeon/radeon_device.c +4 -0
@@ -131,6 +131,10 @@ static struct radeon_px_quirk radeon_px_* https://bugs.freedesktop.org/show_bug.cgi?id=101491 */ { PCI_VENDOR_ID_ATI, 0x6741, 0x1043, 0x2122, RADEON_PX_QUIRK_DISABLE_PX }, +/* Asus K73TK laptop with AMD A6-3420M APU and Radeon 7670m GPU +* https://bugzilla.kernel.org/show_bug.cgi?id=51381#c52 +*/ + { PCI_VENDOR_ID_ATI, 0x6840, 0x1043, 0x2123, RADEON_PX_QUIRK_DISABLE_PX }, { 0, 0, 0, 0, 0 }, };
PATCH 31/366 Input: i8042 - add Lenovo ThinkPad L460 to i8042 reset list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dennis Wassenberg <[email protected]>
commit b56af54ac78c54a519d82813836f305d7f76ef27 upstream.
Reset i8042 before probing because of insufficient BIOS initialisation of the i8042 serial controller. This makes Synaptics touchpad detection possible. Without resetting the Synaptics touchpad is not detected because there are always NACK messages from AUX port.
--- drivers/input/serio/i8042-x86ia64io.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/serio/i8042-x86ia64io.h +7 -0
@@ -595,6 +595,13 @@ static const struct dmi_system_id __init }, }, { +/* Lenovo ThinkPad L460 */ + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"LENOVO" ), + DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L460"), + }, + }, + {/* Clevo P650RS, 650RP6, Sager NP8152-S, and others */ .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Notebook"),
PATCH 71/366 ipc/sem: Fix semctl(..., GETPID, ...) between pid namespaces
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <[email protected]>
commit 51d6f2635b39709ee5e62479be23d423b760292c upstream.
Today the last process to update a semaphore is remembered and reported in the pid namespace of that process. If there are processes in any other pid namespace querying that process id with GETPID the result will be unusable nonsense as it does not make any sense in your own pid namespace.
Due to ipc_update_pid I don't think you will be able to get System V ipc semaphores into a troublesome cache line ping-pong. Using struct pids from separate process are not a problem because they do not share a cache line. Using struct pid from different threads of the same process are unlikely to be a problem as the reference count update can be avoided.
Further linux futexes are a much better tool for the job of mutual exclusion between processes than System V semaphores. So I expect programs that are performance limited by their interprocess mutual exclusion primitive will be using futexes.
So while it is possible that enhancing the storage of the last rocess of a System V semaphore from an integer to a struct pid will cause a performance regression because of the effect of frequently updating the pid reference count. I don't expect that to happen in practice.
This change updates semctl(..., GETPID, ...) to return the process id of the last process to update a semphore inthe pid namespace of the calling process.
[bwh: Backported to 3.16:
- sem_queue::pid was also used to store an error temporarily; add a new wake_error field for this purpose
- Adjust context]
--- ipc/sem.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
ipc/sem.c +16 -13
@@ -99,7 +99,7 @@ struct sem {* - semctl, via SETVAL and SETALL. * - at task exit when performing undo adjustments (see exit_sem). */ -int sempid; +struct pid *sempid;spinlock_t lock;/* spinlock for fine-grained semtimedop */ struct list_head pending_alter;/* pending single-sop operations */ /* that alter the semaphore */
@@ -113,7 +113,8 @@ struct sem_queue {struct list_head list;/* queue of pending operations */ struct task_struct *sleeper;/* this process */ struct sem_undo *undo;/* undo structure */ -int pid;/* process id of requesting process */ +struct pid *pid;/* process id of requesting process */ +int wake_error;int status;/* completion status of operation */ struct sembuf *sops;/* array of pending operations */ struct sembuf *blocking;/* the operation that blocked */
@@ -644,7 +645,8 @@ SYSCALL_DEFINE3(semget, key_t, key, int,*/ static int perform_atomic_semop (struct sem_array *sma,struct sem_queue *q) { -int result, sem_op, nsops, pid; +int result, sem_op, nsops; +struct pid *pid;struct sembuf *sop;struct sem *curr;struct sembuf *sops;
@@ -682,7 +684,7 @@ static int perform_atomic_semop(struct s sop--; pid = q->pid;while (sop >= sops) { - sma->sem_base[sop->sem_num].sempid = pid; +ipc_update_pid (&sma->sem_base[sop->sem_num].sempid, pid); sop--; }
@@ -730,7 +732,7 @@ static void wake_up_sem_queue_prepare(stpreempt_disable (); } q->status =IN_WAKEUP ; - q->pid = error; + q->wake_error = error;list_add_tail (&q->list, pt); }
@@ -754,7 +756,7 @@ static void wake_up_sem_queue_do(structwake_up_process (q->sleeper);/* q can disappear immediately after writing q->status. */ smp_wmb (); - q->status = q->pid; + q->status = q->wake_error; }if (did_something)preempt_enable ();
@@ -812,7 +814,7 @@ static int check_restart(struct sem_arra* be called with semnum = -1, as well as with the number of each modified * semaphore. * The tasks that must be woken up are added to @pt. The return code -* is stored in q->pid. +* is stored in q->wake_error. * The function returns 1 if at least one operation was completed successfully. */ static int wake_const_ops(struct sem_array *sma, int semnum,
@@ -912,7 +914,7 @@ static int do_smart_wakeup_zero(struct s* be called with semnum = -1, as well as with the number of each modified * semaphore. * The tasks that must be woken up are added to @pt. The return code -* is stored in q->pid. +* is stored in q->wake_error. * The function internally checks if const operations can now succeed. * * The function return 1 if at least one semop was completed successfully.
@@ -1156,6 +1158,7 @@ static void freeary(struct ipc_namespaceunlink_queue (sma, q);wake_up_sem_queue_prepare (&tasks, q, -EIDRM ); } +ipc_update_pid (&sem->sempid,NULL ); }/* Remove the semaphore set from the IDR */
@@ -1357,7 +1360,7 @@ static int semctl_setval(struct ipc_name un->semadj[semnum] =0 ; curr->semval = val; - curr->sempid =task_tgid_vnr (current); +ipc_update_pid (&curr->sempid,task_tgid (current)); sma->sem_ctime =get_seconds ();/* maybe some queued-up processes were waiting for this */ do_smart_update (sma,NULL ,0 ,0 , &tasks);
@@ -1478,7 +1481,7 @@ static int semctl_main(struct ipc_namespfor (i =0 ; i < nsems; i++) { sma->sem_base[i].semval = sem_io[i]; - sma->sem_base[i].sempid =task_tgid_vnr (current); +ipc_update_pid (&sma->sem_base[i].sempid,task_tgid (current)); }ipc_assert_locked_object (&sma->sem_perm);
@@ -1510,7 +1513,7 @@ static int semctl_main(struct ipc_namesp err = curr->semval; goto out_unlock;case GETPID : - err = curr->sempid; + err =pid_vnr (curr->sempid); goto out_unlock;case GETNCNT : err =count_semcnt (sma, semnum,0 );
@@ -1933,7 +1936,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, queue.sops = sops; queue.nsops = nsops; queue.undo = un; - queue.pid =task_tgid_vnr (current); + queue.pid =task_tgid (current); queue.alter = alter; error =perform_atomic_semop (sma, &queue);
@@ -2193,7 +2196,7 @@ void exit_sem(struct task_struct *tsk) semaphore->semval =0 ;if (semaphore->semval >SEMVMX ) semaphore->semval =SEMVMX ; - semaphore->sempid =task_tgid_vnr (current); +ipc_update_pid (&semaphore->sempid,task_tgid (current)); } }/* maybe some queued-up processes were waiting for this */
PATCH 100/366 ubifs: Check ubifs_wbuf_sync() return code
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Richard Weinberger <[email protected]>
commit aac17948a7ce01fb60b9ee6cf902967a47b3ce26 upstream.
If ubifs_wbuf_sync() fails we must not write a master node with the dirty marker cleared.
Otherwise it is possible that in case of an IO error while syncing we mark the filesystem as clean and UBIFS refuses to recover upon next mount.
--- fs/ubifs/super.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
fs/ubifs/super.c +10 -4
@@ -1726,8 +1726,11 @@ static void ubifs_remount_ro(struct ubifdbg_save_space_info (c); -for (i =0 ; i < c->jhead_cnt; i++) -ubifs_wbuf_sync (&c->jheads[i].wbuf); +for (i =0 ; i < c->jhead_cnt; i++) { + err =ubifs_wbuf_sync (&c->jheads[i].wbuf); +if (err) +ubifs_ro_mode (c, err); + } c->mst_node->flags &= ~cpu_to_le32 (UBIFS_MST_DIRTY ); c->mst_node->flags |=cpu_to_le32 (UBIFS_MST_NO_ORPHS );
@@ -1794,8 +1797,11 @@ static void ubifs_put_super(struct superint err;/* Synchronize write-buffers */ -for (i =0 ; i < c->jhead_cnt; i++) -ubifs_wbuf_sync (&c->jheads[i].wbuf); +for (i =0 ; i < c->jhead_cnt; i++) { + err =ubifs_wbuf_sync (&c->jheads[i].wbuf); +if (err) +ubifs_ro_mode (c, err); + }/* * We are being cleanly unmounted which means the
PATCH 253/366 net_sched: fq: take care of throttled flows before reuse
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 7df40c2673a1307c3260aab6f9d4b9bf97ca8fd7 upstream.
Normally, a socket can not be freed/reused unless all its TX packets left qdisc and were TX-completed. However connect(AF_UNSPEC) allows this to happen.
With commit fc59d5bdf1e3 ("pkt_sched: fq: clear time_next_packet for reused flows") we cleared f->time_next_packet but took no special action if the flow was still in the throttled rb-tree.
Since f->time_next_packet is the key used in the rb-tree searches, blindly clearing it might break rb-tree integrity. We need to make sure the flow is no longer in the rb-tree to avoid this problem.
--- net/sched/sch_fq.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
net/sched/sch_fq.c +25 -12
@@ -124,6 +124,28 @@ static bool fq_flow_is_detached(const streturn f->next == &detached; } +static bool fq_flow_is_throttled (const struct fq_flow *f) +{ +return f->next == &throttled; +} + +static void fq_flow_add_tail (struct fq_flow_head *head,struct fq_flow *flow) +{ +if (head->first) + head->last->next = flow; +else + head->first = flow; + head->last = flow; + flow->next =NULL ; +} + +static void fq_flow_unset_throttled (struct fq_sched_data *q,struct fq_flow *f) +{ +rb_erase (&f->rate_node, &q->delayed); + q->throttled_flows--; +fq_flow_add_tail (&q->old_flows, f); +} +static void fq_flow_set_throttled (struct fq_sched_data *q,struct fq_flow *f) {struct rb_node **p = &q->delayed.rb_node, *parent =NULL ;
@@ -151,15 +173,6 @@ static void fq_flow_set_throttled(structstatic struct kmem_cache *fq_flow_cachep__read_mostly ; -static void fq_flow_add_tail (struct fq_flow_head *head,struct fq_flow *flow) -{ -if (head->first) - head->last->next = flow; -else - head->first = flow; - head->last = flow; - flow->next =NULL ; -}/* limit number of collected flows per round */ #define FQ_GC_MAX 8
@@ -251,6 +264,8 @@ static struct fq_flow *fq_classify(struc f->socket_hash != sk->sk_hash)) { f->credit = q->initial_quantum; f->socket_hash = sk->sk_hash; +if (fq_flow_is_throttled (f)) +fq_flow_unset_throttled (q, f); f->time_next_packet =0ULL ; }return f;
@@ -407,9 +422,7 @@ static void fq_check_throttled(struct fq q->time_next_delayed_flow = f->time_next_packet;break ; } -rb_erase (p, &q->delayed); - q->throttled_flows--; -fq_flow_add_tail (&q->old_flows, f); +fq_flow_unset_throttled (q, f); } }
PATCH 104/366 media: v4l2-compat-ioctl32: don't oops on overlay
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 85ea29f19eab56ec16ec6b92bc67305998706afa upstream.
At put_v4l2_window32(), it tries to access kp->clips. However, kp points to an userspace pointer. So, it should be obtained via get_user(), otherwise it can OOPS:
vivid-000: ================== END STATUS ==================
BUG: unable to handle kernel paging request at 00000000fffb18e0 IP: [<ffffffffc05468d9>] __put_v4l2_format32+0x169/0x220 [videodev] PGD 3f5776067 PUD 3f576f067 PMD 3f5769067 PTE 800000042548f067 Oops: 0001 [#1] SMP Modules linked in: vivid videobuf2_vmalloc videobuf2_memops v4l2_dv_timings videobuf2_core v4l2_common videodev media xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack tun bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables bluetooth rfkill binfmt_misc snd_hda_codec_hdmi i915 snd_hda_intel snd_hda_controller snd_hda_codec intel_rapl x86_pkg_temp_thermal snd_hwdep intel_powerclamp snd_pcm coretemp snd_seq_midi kvm_intel kvm snd_seq_midi_event snd_rawmidi i2c_algo_bit drm_kms_helper snd_seq drm crct10dif_pclmul e1000e snd_seq_device crc32_pclmul snd_timer ghash_clmulni_intel snd mei_me mei ptp pps_core soundcore lpc_ich video crc32c_intel [last unloaded: media] CPU: 2 PID: 28332 Comm: v4l2-compliance Not tainted 3.18.102+ #107 Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0364.2017.0511.0949 05/11/2017 task: ffff8804293f8000 ti: ffff8803f5640000 task.ti: ffff8803f5640000 RIP: 0010:[<ffffffffc05468d9>] [<ffffffffc05468d9>] __put_v4l2_format32+0x169/0x220 [videodev] RSP: 0018:ffff8803f5643e28 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00000000fffb1ab4 RDX: 00000000fffb1a68 RSI: 00000000fffb18d8 RDI: 00000000fffb1aa8 RBP: ffff8803f5643e48 R08: 0000000000000001 R09: ffff8803f54b0378 R10: 0000000000000000 R11: 0000000000000168 R12: 00000000fffb18c0 R13: 00000000fffb1a94 R14: 00000000fffb18c8 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff880456d00000(0063) knlGS:00000000f7100980 CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 CR2: 00000000fffb18e0 CR3: 00000003f552b000 CR4: 00000000003407e0 Stack: 00000000fffb1a94 00000000c0cc5640 0000000000000056 ffff8804274f3600 ffff8803f5643ed0 ffffffffc0547e16 0000000000000003 ffff8803f5643eb0 ffffffff81301460 ffff88009db44b01 ffff880441942520 ffff8800c0d05640 Call Trace: [<ffffffffc0547e16>] v4l2_compat_ioctl32+0x12d6/0x1b1d [videodev] [<ffffffff81301460>] ? file_has_perm+0x70/0xc0 [<ffffffff81252a2c>] compat_SyS_ioctl+0xec/0x1200 [<ffffffff8173241a>] sysenter_dispatch+0x7/0x21 Code: 00 00 48 8b 80 48 c0 ff ff 48 83 e8 38 49 39 c6 0f 87 2b ff ff ff 49 8d 45 1c e8 a3 ce e3 c0 85 c0 0f 85 1a ff ff ff 41 8d 40 ff <4d> 8b 64 24 20 41 89 d5 48 8d 44 40 03 4d 8d 34 c4 eb 15 0f 1f RIP [<ffffffffc05468d9>] __put_v4l2_format32+0x169/0x220 [videodev] RSP <ffff8803f5643e28> CR2: 00000000fffb18e0
Tested with vivid driver on Kernel v3.18.102.
Same bug happens upstream too:
BUG: KASAN: user-memory-access in __put_v4l2_format32+0x98/0x4d0 [videodev] Read of size 8 at addr 00000000ffe48400 by task v4l2-compliance/8713 CPU: 0 PID: 8713 Comm: v4l2-compliance Not tainted 4.16.0-rc4+ #108 Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0364.2017.0511.0949 05/11/2017 Call Trace: dump_stack+0x5c/0x7c kasan_report+0x164/0x380 ? __put_v4l2_format32+0x98/0x4d0 [videodev] __put_v4l2_format32+0x98/0x4d0 [videodev] v4l2_compat_ioctl32+0x1aec/0x27a0 [videodev] ? __fsnotify_inode_delete+0x20/0x20 ? __put_v4l2_format32+0x4d0/0x4d0 [videodev] compat_SyS_ioctl+0x646/0x14d0 ? do_ioctl+0x30/0x30 do_fast_syscall_32+0x191/0x3f4 entry_SYSENTER_compat+0x6b/0x7a ================================================================== Disabling lock debugging due to kernel taint BUG: unable to handle kernel paging request at 00000000ffe48400 IP: __put_v4l2_format32+0x98/0x4d0 [videodev] PGD 3a22fb067 P4D 3a22fb067 PUD 39b6f0067 PMD 39b6f1067 PTE 80000003256af067 Oops: 0001 [#1] SMP KASAN Modules linked in: vivid videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops v4l2_tpg v4l2_dv_timings videobuf2_v4l2 videobuf2_common v4l2_common videodev xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack nf_conntrack libcrc32c tun bridge stp llc ebtable_filter ebtables ip6table_filter ip6_tables bluetooth rfkill ecdh_generic binfmt_misc snd_hda_codec_hdmi intel_rapl x86_pkg_temp_thermal intel_powerclamp i915 coretemp snd_hda_intel snd_hda_codec kvm_intel snd_hwdep snd_hda_core kvm snd_pcm irqbypass crct10dif_pclmul crc32_pclmul snd_seq_midi ghash_clmulni_intel snd_seq_midi_event i2c_algo_bit intel_cstate snd_rawmidi intel_uncore snd_seq drm_kms_helper e1000e snd_seq_device snd_timer intel_rapl_perf drm ptp snd mei_me mei lpc_ich pps_core soundcore video crc32c_intel CPU: 0 PID: 8713 Comm: v4l2-compliance Tainted: G B 4.16.0-rc4+ #108 Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0364.2017.0511.0949 05/11/2017 RIP: 0010:__put_v4l2_format32+0x98/0x4d0 [videodev] RSP: 0018:ffff8803b9be7d30 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffff8803ac983e80 RCX: ffffffff8cd929f2 RDX: 1ffffffff1d0a149 RSI: 0000000000000297 RDI: 0000000000000297 RBP: 00000000ffe485c0 R08: fffffbfff1cf5123 R09: ffffffff8e7a8948 R10: 0000000000000001 R11: fffffbfff1cf5122 R12: 00000000ffe483e0 R13: 00000000ffe485c4 R14: ffff8803ac985918 R15: 00000000ffe483e8 FS: 0000000000000000(0000) GS:ffff880407400000(0063) knlGS:00000000f7a46980 CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 CR2: 00000000ffe48400 CR3: 00000003a83f2003 CR4: 00000000003606f0 Call Trace: v4l2_compat_ioctl32+0x1aec/0x27a0 [videodev] ? __fsnotify_inode_delete+0x20/0x20 ? __put_v4l2_format32+0x4d0/0x4d0 [videodev] compat_SyS_ioctl+0x646/0x14d0 ? do_ioctl+0x30/0x30 do_fast_syscall_32+0x191/0x3f4 entry_SYSENTER_compat+0x6b/0x7a Code: 4c 89 f7 4d 8d 7c 24 08 e8 e6 a4 69 cb 48 8b 83 98 1a 00 00 48 83 e8 10 49 39 c7 0f 87 9d 01 00 00 49 8d 7c 24 20 e8 c8 a4 69 cb <4d> 8b 74 24 20 4c 89 ef 4c 89 fe ba 10 00 00 00 e8 23 d9 08 cc RIP: __put_v4l2_format32+0x98/0x4d0 [videodev] RSP: ffff8803b9be7d30 CR2: 00000000ffe48400
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +3 -1
@@ -101,7 +101,7 @@ static int get_v4l2_window32(struct v4l2static int put_v4l2_window32 (struct v4l2_window __user *kp,struct v4l2_window32 __user *up) { -struct v4l2_clip __user *kclips = kp->clips; +struct v4l2_clip __user *kclips;struct v4l2_clip32 __user *uclips;compat_caddr_t p;u32 clipcount;
@@ -116,6 +116,8 @@ static int put_v4l2_window32(struct v4l2if (!clipcount)return 0 ; +if (get_user (kclips, &kp->clips)) +return -EFAULT ;if (get_user (p, &up->clips))return -EFAULT ; uclips =compat_ptr (p);
PATCH 66/366 ipc/util: Helpers for making the sysvipc operations pid namespace aware
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <[email protected]>
commit 03f1fc09180b345582889a344b012d069b3a6dbe upstream.
Capture the pid namespace when /proc/sysvipc/msg /proc/sysvipc/shm and /proc/sysvipc/sem are opened, and make it available through the new helper ipc_seq_pid_ns.
This makes it possible to report the pids in these files in the pid namespace of the opener of the files.
Implement ipc_update_pid. A simple impline helper that will only update a struct pid pointer if the new value does not equal the old value. This removes the need for wordy code sequences like:
old = object->pid; object->pid = new; put_pid(old);
and
old = object->pid;
if (old != new) {
object->pid = new;
put_pid(old);
}Allowing the following to be written instead:
ipc_update_pid(&object->pid, new);
Which is easier to read and ensures that the pid reference count is not touched the old and the new values are the same. Not touching the reference count in this case is important to help avoid issues like af_unix experienced, where multiple threads of the same process managed to bounce the struct pid between cpu cache lines, but updating the pids reference count.
--- ipc/util.c | 9 +++++++++ ipc/util.h | 11 +++++++++++ 2 files changed, 20 insertions(+)
ipc/util.c +9 -0
@@ -777,9 +777,16 @@ int ipc_parse_version(int *cmd)#ifdef CONFIG_PROC_FS struct ipc_proc_iter {struct ipc_namespace *ns; +struct pid_namespace *pid_ns;struct ipc_proc_iface *iface; }; +struct pid_namespace *ipc_seq_pid_ns (struct seq_file *s) +{ +struct ipc_proc_iter *iter = s->private; +return iter->pid_ns; +} +/* * This routine locks the ipc structure found at least at position pos. */
@@ -914,6 +921,7 @@ static int sysvipc_proc_open(struct inod iter->iface =PDE_DATA (inode); iter->ns =get_ipc_ns (current->nsproxy->ipc_ns); + iter->pid_ns =get_pid_ns (task_active_pid_ns (current)); out:return ret; }
@@ -923,6 +931,7 @@ static int sysvipc_proc_release(struct istruct seq_file *seq = file->private_data;struct ipc_proc_iter *iter = seq->private;put_ipc_ns (iter->ns); +put_pid_ns (iter->pid_ns);return seq_release_private (inode, file); }
ipc/util.h +11 -0
@@ -20,6 +20,7 @@ void msg_init(void);void shm_init (void );struct ipc_namespace ; +struct pid_namespace ;#ifdef CONFIG_POSIX_MQUEUE extern void mq_clear_sbinfo (struct ipc_namespace *ns);
@@ -90,6 +91,7 @@ void ipc_init_ids(struct ipc_ids *);#ifdef CONFIG_PROC_FS void __init ipc_init_proc_interface (const char *path,const char *header,int ids,int (*show)(struct seq_file *,void *)); +struct pid_namespace *ipc_seq_pid_ns (struct seq_file *);#else #define ipc_init_proc_interface (path, header, ids, show) do {} while (0)#endif
@@ -141,6 +143,15 @@ struct kern_ipc_perm *ipcctl_pre_down_no struct ipc_ids *ids, int id, int cmd, struct ipc64_perm *perm, int extra_perm); +static inline void ipc_update_pid (struct pid **pos,struct pid *pid) +{ +struct pid *old = *pos; +if (old != pid) { + *pos =get_pid (pid); +put_pid (old); + } +} +#ifndef CONFIG_ARCH_WANT_IPC_PARSE_VERSION /* On IA-64, we always use the "64-bit version" of the IPC structures. */ # define ipc_parse_version (cmd) IPC_64
PATCH 105/366 Btrfs: fix NULL pointer dereference in log_dir_items
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 80c0b4210a963e31529e15bf90519708ec947596 upstream.
0, 1 and <0 can be returned by btrfs_next_leaf(), and when <0 is returned, path->nodes[0] could be NULL, log_dir_items lacks such a check for <0 and we may run into a null pointer dereference panic.
--- fs/btrfs/tree-log.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/tree-log.c +5 -2
@@ -3082,8 +3082,11 @@ static noinline int log_dir_items(struct* from this directory and from this transaction */ ret =btrfs_next_leaf (root, path); -if (ret ==1 ) { - last_offset = (u64)-1 ; +if (ret) { +if (ret ==1 ) + last_offset = (u64)-1 ; +else + err = ret; goto done; }btrfs_item_key_to_cpu (path->nodes[0 ], &tmp, path->slots[0 ]);
PATCH 195/366 tty: handle the case where we cannot restore a line discipline
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Cox <[email protected]>
commit 8a8dabf2dd68caff842d38057097c23bc514ea6e upstream.
Historically the N_TTY driver could never fail but this has become broken over time. Rather than trying to rewrite half the ldisc layer to fix the breakage introduce a second level of fallback with an N_NULL ldisc which cannot fail, and thus restore the guarantees required by the ldisc layer.
We still try and fail to N_TTY first. It's much more useful to find yourself back in your old ldisc (first attempt) or in N_TTY (second attempt), and while I'm not aware of any code out there that makes those assumptions it's good to drive(r) defensively.
---
drivers/tty/Makefile +2 -1
@@ -1,5 +1,6 @@ obj-$(CONFIG_TTY) += tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \ - tty_buffer.o tty_port.o tty_mutex.o tty_ldsem.o + tty_buffer.o tty_port.o tty_mutex.o \ + tty_ldsem.o n_null.o obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o obj-$(CONFIG_AUDIT) += tty_audit.o
drivers/tty/n_null.c new file +80 -0
80 lines not on this page · raw message
drivers/tty/tty_ldisc.c +30 -13
61 lines not on this page · raw message
include/uapi/linux/tty.h +1 -0
@@ -34,5 +34,6 @@#define N_TI_WL 22/* for TI's WL BT, FM, GPS combo chips */ #define N_TRACESINK 23/* Trace data routing for MIPI P1149.7 */ #define N_TRACEROUTER 24/* Trace data routing for MIPI P1149.7 */ +#define N_NULL 27/* Null ldisc used for error handling */ #endif /* _UAPI_LINUX_TTY_H */
PATCH 107/366 btrfs: Fix possible softlock on single core machines
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Borisov <[email protected]>
commit 1e1c50a929bc9e49bc3f9935b92450d9e69f8158 upstream.
do_chunk_alloc implements a loop checking whether there is a pending chunk allocation and if so causes the caller do loop. Generally this loop is executed only once, however testing with btrfs/072 on a single core vm machines uncovered an extreme case where the system could loop indefinitely. This is due to a missing cond_resched when loop which doesn't give a chance to the previous chunk allocator finish its job.
The fix is to simply add the missing cond_resched.
--- fs/btrfs/extent-tree.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/extent-tree.c +1 -0
@@ -3969,6 +3969,7 @@ again:if (wait_for_alloc) {mutex_unlock (&fs_info->chunk_mutex); wait_for_alloc =0 ; +cond_resched (); goto again; }
PATCH 198/366 hwmon: (nct6683) Enable EC access if disabled at boot
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
commit dbac00f0cf634120d77edee10d25e3f6899d7636 upstream.
On Asrock Z370M Pro4, it was observed that EC access was disabled after initially booting the system. As a result, the driver failed to load with
nct6683: EC is disabled
After a suspend/resume cycle, the driver loaded correctly.
nct6683: Found NCT6683D or compatible chip at 0x2e:0xa20 nct6683 nct6683.2592: NCT6683D EC firmware version 1.0 build 07/18/16
Enable EC access after identifying the chip if disabled to fix the problem. Warn the user that the data it reports may be unusable, similar to other drivers for chips from Nuvoton.
--- drivers/hwmon/nct6683.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/nct6683.c +2 -2
@@ -1335,8 +1335,8 @@ static int __init nct6683_find(int sioad/* Activate logical device if needed */ val =superio_inb (sioaddr,SIO_REG_ENABLE );if (!(val &0x01 )) { -pr_err ("EC is disabled\n" ); - goto fail; +pr_warn ("Forcibly enabling EC access. Data may be unusable.\n" ); +superio_outb (sioaddr,SIO_REG_ENABLE , val |0x01 ); }superio_exit (sioaddr);
PATCH 178/366 Don't leak MNT_INTERNAL away from internal mounts
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 16a34adb9392b2fe4195267475ab5b472e55292c upstream.
We want it only for the stuff created by SB_KERNMOUNT mounts, *not* for their copies. As it is, creating a deep stack of bindings of /proc/*/ns/* somewhere in a new namespace and exiting yields a stack overflow.
--- fs/namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namespace.c +2 -1
@@ -903,7 +903,8 @@ static struct mount *clone_mnt(struct mo goto out_free; } - mnt->mnt.mnt_flags = old->mnt.mnt_flags & ~(MNT_WRITE_HOLD |MNT_MARKED ); + mnt->mnt.mnt_flags = old->mnt.mnt_flags; + mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD |MNT_MARKED |MNT_INTERNAL );/* Don't allow unprivileged users to change mount flags */ if (flag &CL_UNPRIVILEGED ) { mnt->mnt.mnt_flags |=MNT_LOCK_ATIME ;
PATCH 114/366 hugetlbfs: fix bug in pgoff overflow checking
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mike Kravetz <[email protected]>
commit 5df63c2a149ae65a9ec239e7c2af44efa6f79beb upstream.
This is a fix for a regression in 32 bit kernels caused by an invalid check for pgoff overflow in hugetlbfs mmap setup. The check incorrectly specified that the size of a loff_t was the same as the size of a long. The regression prevents mapping hugetlbfs files at offsets greater than 4GB on 32 bit kernels.
On 32 bit kernels conversion from a page based unsigned long can not overflow a loff_t byte offset. Therefore, skip this check if sizeof(unsigned long) != sizeof(loff_t).
--- fs/hugetlbfs/inode.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/hugetlbfs/inode.c +7 -3
@@ -127,10 +127,14 @@ static int hugetlbfs_file_mmap(struct fi/* * page based offset in vm_pgoff could be sufficiently large to -* overflow a (l)off_t when converted to byte offset. +* overflow a loff_t when converted to byte offset. This can +* only happen on architectures where sizeof(loff_t) == +* sizeof(unsigned long). So, only check in those instances. */ -if (vma->vm_pgoff &PGOFF_LOFFT_MAX ) -return -EINVAL ; +if (sizeof (unsigned long ) ==sizeof (loff_t)) { +if (vma->vm_pgoff &PGOFF_LOFFT_MAX ) +return -EINVAL ; + }/* must be huge page aligned */ if (vma->vm_pgoff & (~huge_page_mask (h) >>PAGE_SHIFT ))
PATCH 99/366 kvm: x86: fix a compile warning
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peng Hao <[email protected]>
commit 3140c156e919b0f5fad5c5f6cf7876c39d1d4f06 upstream.
fix a "warning: no previous prototype".
--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
@@ -6640,7 +6640,7 @@ int kvm_task_switch(struct kvm_vcpu *vcp }EXPORT_SYMBOL_GPL (kvm_task_switch); -int kvm_valid_sregs (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs) +static int kvm_valid_sregs (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs) {if ((sregs->efer &EFER_LME ) && (sregs->cr0 &X86_CR0_PG )) {/*
PATCH 199/366 tcp: don't read out-of-bounds opsize
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit 7e5a206ab686f098367b61aca989f5cdfa8114a3 upstream.
The old code reads the "opsize" variable from out-of-bounds memory (first byte behind the segment) if a broken TCP segment ends directly after an opcode that is neither EOL nor NOP.
The result of the read isn't used for anything, so the worst thing that could theoretically happen is a pagefault; and since the physmap is usually mostly contiguous, even that seems pretty unlikely.
The following C reproducer triggers the uninitialized read - however, you can't actually see anything happen unless you put something like a pr_warn() in tcp_parse_md5sig_option() to print the opsize.
====================================
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <net/if.h>
#include <linux/if.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/in.h>
#include <linux/if_tun.h>
#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <assert.h>
void systemf(const char *command, ...) {
char *full_command;
va_list ap;
va_start(ap, command);
if (vasprintf(&full_command, command, ap) == -1)
err(1, "vasprintf");
va_end(ap);
printf("systemf: <<<%s>>>\n", full_command);
system(full_command);
}
char *devname;
int tun_alloc(char *name) {
int fd = open("/dev/net/tun", O_RDWR);
if (fd == -1)
err(1, "open tun dev");
static struct ifreq req = { .ifr_flags = IFF_TUN|IFF_NO_PI };
strcpy(req.ifr_name, name);
if (ioctl(fd, TUNSETIFF, &req))
err(1, "TUNSETIFF"); devname = req.ifr_name;
printf("device name: %s\n", devname);
return fd;
}
#define IPADDR(a,b,c,d) (((a)<<0)+((b)<<8)+((c)<<16)+((d)<<24))
void sum_accumulate(unsigned int *sum, void *data, int len) {
assert((len&2)==0);
for (int i=0; i<len/2; i++) {
*sum += ntohs(((unsigned short *)data)[i]); }
}
unsigned short sum_final(unsigned int sum) {
sum = (sum >> 16) + (sum & 0xffff);
sum = (sum >> 16) + (sum & 0xffff);
return htons(~sum);
}
void fix_ip_sum(struct iphdr *ip) {
unsigned int sum = 0;
sum_accumulate(&sum, ip, sizeof(*ip));
ip->check = sum_final(sum);
}
void fix_tcp_sum(struct iphdr *ip, struct tcphdr *tcp) {
unsigned int sum = 0;
struct {
unsigned int saddr;
unsigned int daddr;
unsigned char pad;
unsigned char proto_num;
unsigned short tcp_len;
} fakehdr = {
.saddr = ip->saddr,
.daddr = ip->daddr,
.proto_num = ip->protocol,
.tcp_len = htons(ntohs(ip->tot_len) - ip->ihl*4) };
sum_accumulate(&sum, &fakehdr, sizeof(fakehdr)); sum_accumulate(&sum, tcp, tcp->doff*4); tcp->check = sum_final(sum);
}
int main(void) {
int tun_fd = tun_alloc("inject_dev%d"); systemf("ip link set %s up", devname); systemf("ip addr add 192.168.42.1/24 dev %s", devname);
struct {
struct iphdr ip;
struct tcphdr tcp;
unsigned char tcp_opts[20];
} __attribute__((packed)) syn_packet = {
.ip = {
.ihl = sizeof(struct iphdr)/4,
.version = 4,
.tot_len = htons(sizeof(syn_packet)),
.ttl = 30,
.protocol = IPPROTO_TCP,
/* FIXUP check */
.saddr = IPADDR(192,168,42,2),
.daddr = IPADDR(192,168,42,1)
},
.tcp = {
.source = htons(1),
.dest = htons(1337),
.seq = 0x12345678,
.doff = (sizeof(syn_packet.tcp)+sizeof(syn_packet.tcp_opts))/4,
.syn = 1,
.window = htons(64),
.check = 0 /*FIXUP*/
},
.tcp_opts = {
/* INVALID: trailing MD5SIG opcode after NOPs */
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 19
}
};
fix_ip_sum(&syn_packet.ip);
fix_tcp_sum(&syn_packet.ip, &syn_packet.tcp);
while (1) {
int write_res = write(tun_fd, &syn_packet, sizeof(syn_packet));
if (write_res != sizeof(syn_packet))
err(1, "packet write failed"); }
}
====================================
--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/ipv4/tcp_input.c +2 -5
@@ -3675,11 +3675,8 @@ const u8 *tcp_parse_md5sig_option(constint length = (th->doff <<2 ) -sizeof (*th);const u8 *ptr = (const u8 *)(th +1 ); -/* If the TCP option is too short, we can short cut */ -if (length <TCPOLEN_MD5SIG ) -return NULL ; - -while (length >0 ) { +/* If not enough data remaining, we can short cut */ +while (length >=TCPOLEN_MD5SIG ) {int opcode = *ptr++;int opsize;
PATCH 132/366 powerpc/powernv: define a standard delay for OPAL_BUSY type retry loops
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Piggin <[email protected]>
commit 34dd25de9fe3f60bfdb31b473bf04b28262d0896 upstream.
This is the start of an effort to tidy up and standardise all the delays. Existing loops have a range of delay/sleep periods from 1ms to 20ms, and some have no delay. They all loop forever except rtc, which times out after 10 retries, and that uses 10ms delays. So use 10ms as our standard delay. The OPAL maintainer agrees 10ms is a reasonable starting point.
The idea is to use the same recipe everywhere, once this is proven to work then it will be documented as an OPAL API standard. Then both firmware and OS can agree, and if a particular call needs something else, then that can be documented with reasoning.
This is not the end-all of this effort, it's just a relatively easy change that fixes some existing high latency delays. There should be provision for standardising timeouts and/or interruptible loops where possible, so non-fatal firmware errors don't cause hangs.
--- arch/powerpc/include/asm/opal.h | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/include/asm/opal.h +3 -0
@@ -707,6 +707,9 @@ typedef struct oppanel_line {uint64_t line_len; } oppanel_line_t; +/* Default time to sleep or delay between OPAL_BUSY/OPAL_BUSY_EVENT loops */ +#define OPAL_BUSY_DELAY_MS 10 +/* /sys/firmware/opal */ extern struct kobject *opal_kobj;
PATCH 59/366 ALSA: pcm: Fix mutex unbalance in OSS emulation ioctls
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f6d297df4dd47ef949540e4a201230d0c5308325 upstream.
The previous fix 40cab6e88cb0 ("ALSA: pcm: Return -EBUSY for OSS ioctls changing busy streams") introduced some mutex unbalance; the check of runtime->oss.rw_ref was inserted in a wrong place after the mutex lock.
This patch fixes the inconsistency by rewriting with the helper functions to lock/unlock parameters with the stream check.
--- sound/core/oss/pcm_oss.c | 67 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-)
sound/core/oss/pcm_oss.c +42 -25
@@ -833,6 +833,23 @@ static int choose_rate(struct snd_pcm_sureturn snd_pcm_hw_param_near (substream, params,SNDRV_PCM_HW_PARAM_RATE , best_rate,NULL ); } +/* parameter locking: returns immediately if tried during streaming */ +static int lock_params (struct snd_pcm_runtime *runtime) +{ +if (mutex_lock_interruptible (&runtime->oss.params_lock)) +return -ERESTARTSYS ; +if (atomic_read (&runtime->oss.rw_ref)) { +mutex_unlock (&runtime->oss.params_lock); +return -EBUSY ; + } +return 0 ; +} + +static void unlock_params (struct snd_pcm_runtime *runtime) +{ +mutex_unlock (&runtime->oss.params_lock); +} +/* call with params_lock held */ static int snd_pcm_oss_change_params_locked (struct snd_pcm_substream *substream) {
@@ -1774,6 +1791,8 @@ static int snd_pcm_oss_set_rate(struct sfor (idx =1 ; idx >=0 ; --idx) {struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];struct snd_pcm_runtime *runtime; +int err; +if (substream ==NULL )continue ; runtime = substream->runtime;
@@ -1781,15 +1800,14 @@ static int snd_pcm_oss_set_rate(struct s rate =1000 ; else if (rate > 192000) rate =192000 ; -if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -ERESTARTSYS ; -if (atomic_read (&runtime->oss.rw_ref)) -return -EBUSY ; + err =lock_params (runtime); +if (err <0 ) +return err;if (runtime->oss.rate != rate) { runtime->oss.params =1 ; runtime->oss.rate = rate; } -mutex_unlock (&runtime->oss.params_lock); +unlock_params (runtime); }return snd_pcm_oss_get_rate (pcm_oss_file); }
@@ -1814,18 +1832,19 @@ static int snd_pcm_oss_set_channels(strufor (idx =1 ; idx >=0 ; --idx) {struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];struct snd_pcm_runtime *runtime; +int err; +if (substream ==NULL )continue ; runtime = substream->runtime; -if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -ERESTARTSYS ; -if (atomic_read (&runtime->oss.rw_ref)) -return -EBUSY ; + err =lock_params (runtime); +if (err <0 ) +return err;if (runtime->oss.channels != channels) { runtime->oss.params =1 ; runtime->oss.channels = channels; } -mutex_unlock (&runtime->oss.params_lock); +unlock_params (runtime); }return snd_pcm_oss_get_channels (pcm_oss_file); }
@@ -1896,6 +1915,7 @@ static int snd_pcm_oss_get_formats(strucstatic int snd_pcm_oss_set_format (struct snd_pcm_oss_file *pcm_oss_file,int format) {int formats, idx; +int err;if (format !=AFMT_QUERY ) { formats =snd_pcm_oss_get_formats (pcm_oss_file);
@@ -1909,15 +1929,14 @@ static int snd_pcm_oss_set_format(structif (substream ==NULL )continue ; runtime = substream->runtime; -if (atomic_read (&runtime->oss.rw_ref)) -return -EBUSY ; -if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -ERESTARTSYS ; + err =lock_params (runtime); +if (err <0 ) +return err;if (runtime->oss.format != format) { runtime->oss.params =1 ; runtime->oss.format = format; } -mutex_unlock (&runtime->oss.params_lock); +unlock_params (runtime); } }return snd_pcm_oss_get_format (pcm_oss_file);
@@ -1965,12 +1984,11 @@ static int snd_pcm_oss_set_subdivide(strif (substream ==NULL )continue ; runtime = substream->runtime; -if (atomic_read (&runtime->oss.rw_ref)) -return -EBUSY ; -if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -ERESTARTSYS ; + err =lock_params (runtime); +if (err <0 ) +return err; err =snd_pcm_oss_set_subdivide1 (substream, subdivide); -mutex_unlock (&runtime->oss.params_lock); +unlock_params (runtime);if (err <0 )return err; }
@@ -2005,12 +2023,11 @@ static int snd_pcm_oss_set_fragment(struif (substream ==NULL )continue ; runtime = substream->runtime; -if (atomic_read (&runtime->oss.rw_ref)) -return -EBUSY ; -if (mutex_lock_interruptible (&runtime->oss.params_lock)) -return -ERESTARTSYS ; + err =lock_params (runtime); +if (err <0 ) +return err; err =snd_pcm_oss_set_fragment1 (substream, val); -mutex_unlock (&runtime->oss.params_lock); +unlock_params (runtime);if (err <0 )return err; }
PATCH 75/366 iio:kfifo_buf: check for uint overflow
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Martin Kelly <[email protected]>
commit 3d13de4b027d5f6276c0f9d3a264f518747d83f2 upstream.
Currently, the following causes a kernel OOPS in memcpy:
echo 1073741825 > buffer/length
echo 1 > buffer/enable
Note that using 1073741824 instead of 1073741825 causes "write error:
Cannot allocate memory" but no OOPS.
This is because 1073741824 == 2^30 and 1073741825 == 2^30+1. Since kfifo rounds up to the nearest power of 2, it will actually call kmalloc with roundup_pow_of_two(length) * bytes_per_datum.
Using length == 1073741825 and bytes_per_datum == 2, we get:
kmalloc(roundup_pow_of_two(1073741825) * 2
or kmalloc(2147483648 * 2)
or kmalloc(4294967296)
or kmalloc(UINT_MAX + 1)
so this overflows to 0, causing kmalloc to return ZERO_SIZE_PTR and subsequent memcpy to fail once the device is enabled.
Fix this by checking for overflow prior to allocating a kfifo. With this check added, the above code returns -EINVAL when enabling the buffer, rather than causing an OOPS.
--- drivers/iio/kfifo_buf.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iio/kfifo_buf.c +7 -0
@@ -24,6 +24,13 @@ static inline int __iio_allocate_kfifo(sif ((length ==0 ) || (bytes_per_datum ==0 ))return -EINVAL ; +/* +* Make sure we don't overflow an unsigned int after kfifo rounds up to +* the next power of 2. +*/ +if (roundup_pow_of_two (length) >UINT_MAX / bytes_per_datum) +return -EINVAL ; +return __kfifo_alloc ((struct __kfifo *)&buf->kf, length, bytes_per_datum,GFP_KERNEL ); }
PATCH 95/366 powerpc/mm/hugetlb: initialize the pagetable cache correctly for hugetlb
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Aneesh Kumar K.V" <[email protected]>
commit 6fa504835d6969144b2bd3699684dd447c789ba2 upstream.
With 64k page size, we have hugetlb pte entries at the pmd and pud level for book3s64. We don't need to create a separate page table cache for that. With 4k we need to make sure hugepd page table cache for 16M is placed at PUD level and 16G at the PGD level.
Simplify all these by not using HUGEPD_PD_SHIFT which is confusing for book3s64.
Without this patch, with 64k page size we create pagetable caches with shift value 10 and 7 which are not used at all.
[bwh: Backported to 3.16: Don't use an #ifdef because this implementation of
hugetlbpage_init() is only used if CONFIG_PPC_BOOK3S_64 is enabled.]
---
arch/powerpc/mm/hugetlbpage.c +8 -9
@@ -175,9 +175,6 @@ static int __hugepte_alloc(struct mm_str#ifdef CONFIG_PPC_FSL_BOOK3E #define HUGEPD_PGD_SHIFT PGDIR_SHIFT#define HUGEPD_PUD_SHIFT PUD_SHIFT -#else -#define HUGEPD_PGD_SHIFT PUD_SHIFT -#define HUGEPD_PUD_SHIFT PMD_SHIFT#endif #ifdef CONFIG_PPC_BOOK3S_64
@@ -871,15 +868,17 @@ static int __init hugetlbpage_init(void) shift =mmu_psize_to_shift (psize); -if (add_huge_page_size (1ULL << shift) <0 ) +if (shift >PGDIR_SHIFT )continue ; - -if (shift <PMD_SHIFT ) - pdshift =PMD_SHIFT ; -else if (shift <PUD_SHIFT ) +else if (shift >PUD_SHIFT ) + pdshift =PGDIR_SHIFT ; +else if (shift >PMD_SHIFT ) pdshift =PUD_SHIFT ;else - pdshift =PGDIR_SHIFT ; + pdshift =PMD_SHIFT ; + +if (add_huge_page_size (1ULL << shift) <0 ) +continue ;/* * if we have pdshift and shift value same, we don't * use pgt cache for hugepd.
PATCH 204/366 l2tp: check sockaddr length in pppol2tp_connect()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit eb1c28c05894a4b1f6b56c5bf072205e64cfa280 upstream.
Check sockaddr_len before dereferencing sp->sa_protocol, to ensure that it actually points to valid data.
--- net/l2tp/l2tp_ppp.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/l2tp/l2tp_ppp.c +7 -0
@@ -641,6 +641,13 @@ static int pppol2tp_connect(struct sockelock_sock (sk); error = -EINVAL ; + +if (sockaddr_len !=sizeof (struct sockaddr_pppol2tp ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpv3 ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpin6 ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpv3in6 )) + goto end; +if (sp->sa_protocol !=PX_PROTO_OL2TP ) goto end;
PATCH 171/366 MIPS: uaccess: Add micromips clobbers to bzero invocation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit b3d7e55c3f886493235bfee08e1e5a4a27cbcce8 upstream.
The micromips implementation of bzero additionally clobbers registers t7 & t8. Specify this in the clobbers list when invoking bzero.
Patchwork: https://patchwork.linux-mips.org/patch/19110/
--- arch/mips/include/asm/uaccess.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/mips/include/asm/uaccess.h +9 -2
@@ -1210,6 +1210,13 @@ __clear_user(void __user *addr, __kernel {__kernel_size_t res; +#ifdef CONFIG_CPU_MICROMIPS +/* micromips memset / bzero also clobbers t7 & t8 */ +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31" +#else +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31" +#endif /* CONFIG_CPU_MICROMIPS */ +if (config_enabled (CONFIG_EVA ) &&segment_eq (get_fs (),get_ds ())) { __asm__ __volatile__( "move\t$4, %1\n\t"
@@ -1219,7 +1226,7 @@ __clear_user(void __user *addr, __kernel "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"); + : bzero_clobbers); }else {might_fault (); __asm__ __volatile__(
@@ -1230,7 +1237,7 @@ __clear_user(void __user *addr, __kernel "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"); + : bzero_clobbers); }return res;
PATCH 193/366 ALSA: core: Report audio_tstamp in snd_pcm_sync_ptr
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Henningsson <[email protected]>
commit f853dcaae2f5bbe021161e421bd1576845bae8f6 upstream.
It looks like a simple mistake that this struct member was forgotten.
Audio_tstamp isn't used much, and on some archs (such as x86) this ioctl is not used by default, so that might be the reason why this has slipped for so long.
--- sound/core/pcm_native.c | 1 + 1 file changed, 1 insertion(+)
sound/core/pcm_native.c +1 -0
@@ -2527,6 +2527,7 @@ static int snd_pcm_sync_ptr(struct snd_p sync_ptr.s.status.hw_ptr = status->hw_ptr; sync_ptr.s.status.tstamp = status->tstamp; sync_ptr.s.status.suspended_state = status->suspended_state; + sync_ptr.s.status.audio_tstamp = status->audio_tstamp;snd_pcm_stream_unlock_irq (substream);if (copy_to_user (_sync_ptr, &sync_ptr,sizeof (sync_ptr)))return -EFAULT ;
PATCH 131/366 tracing/uprobe_event: Fix strncpy corner case
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu <[email protected]>
commit 50268a3d266ecfdd6c5873d62b2758d9732fc598 upstream.
Fix string fetch function to terminate with NUL.
It is OK to drop the rest of string.
--- kernel/trace/trace_uprobe.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/trace/trace_uprobe.c +2 -0
@@ -149,6 +149,8 @@ static void FETCH_FUNC_NAME(memory, strireturn ; ret =strncpy_from_user (dst, src, maxlen); +if (ret == maxlen) + dst[--ret] ='\0' ;if (ret <0 ) {/* Failed to fetch string */ ((u8 *)get_rloc_data (dest))[0 ] ='\0' ;
PATCH 120/366 net: fix rtnh_ok()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit b1993a2de12c9e75c35729e2ffbc3a92d50c0d31 upstream.
syzbot reported :
BUG: KMSAN: uninit-value in rtnh_ok include/net/nexthop.h:11 [inline] BUG: KMSAN: uninit-value in fib_count_nexthops net/ipv4/fib_semantics.c:469 [inline] BUG: KMSAN: uninit-value in fib_create_info+0x554/0x8d20 net/ipv4/fib_semantics.c:1091
@remaining is an integer, coming from user space. If it is negative we want rtnh_ok() to return false.
--- include/net/nexthop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +1 -1
@@ -6,7 +6,7 @@static inline int rtnh_ok (const struct rtnexthop *rtnh,int remaining) { -return remaining >=sizeof (*rtnh) && +return remaining >= (int )sizeof (*rtnh) && rtnh->rtnh_len >=sizeof (*rtnh) && rtnh->rtnh_len <= remaining; }
PATCH 65/366 ipc/shm: handle removed segments gracefully in shm_mmap()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Kirill A. Shutemov" <[email protected]>
commit 1ac0b6dec656f3f78d1c3dd216fad84cb4d0a01e upstream.
remap_file_pages(2) emulation can reach file which represents removed IPC ID as long as a memory segment is mapped. It breaks expectations of IPC subsystem.
Test case (rewritten to be more human readable, originally autogenerated by syzkaller[1]):
#define _GNU_SOURCE
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/mman.h>
#include <sys/shm.h>
#define PAGE_SIZE 4096
int main()
{
int id;
void *p;
id = shmget(IPC_PRIVATE, 3 * PAGE_SIZE, 0);
p = shmat(id, NULL, 0);
shmctl(id, IPC_RMID, NULL);
remap_file_pages(p, 3 * PAGE_SIZE, 0, 7, 0);
return 0;
}The patch changes shm_mmap() and code around shm_lock() to propagate locking error back to caller of shm_mmap().
[1] http://github.com/google/syzkaller
--- ipc/shm.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-)
ipc/shm.c +43 -10
@@ -156,11 +156,12 @@ static inline struct shmid_kernel *shm_lstruct kern_ipc_perm *ipcp =ipc_lock (&shm_ids (ns), id);/* -* We raced in the idr lookup or with shm_destroy(). Either way, the -* ID is busted. +* Callers of shm_lock() must validate the status of the returned ipc +* object pointer (as returned by ipc_lock()), and error out as +* appropriate. */ -WARN_ON (IS_ERR (ipcp)); - +if (IS_ERR (ipcp)) +return (void *)ipcp; return container_of(ipcp, struct shmid_kernel, shm_perm); }
@@ -185,18 +186,33 @@ static inline void shm_rmid(struct ipc_n } -/* This is called by fork, once for every shm attach. */ -static void shm_open (struct vm_area_struct *vma) +static int __shm_open (struct vm_area_struct *vma) {struct file *file = vma->vm_file;struct shm_file_data *sfd =shm_file_data (file);struct shmid_kernel *shp; shp =shm_lock (sfd->ns, sfd->id); + +if (IS_ERR (shp)) +return PTR_ERR (shp); + shp->shm_atim =get_seconds (); shp->shm_lprid =task_tgid_vnr (current); shp->shm_nattch++;shm_unlock (shp); +return 0 ; +} + +/* This is called by fork, once for every shm attach. */ +static void shm_open (struct vm_area_struct *vma) +{ +int err =__shm_open (vma); +/* +* We raced in the idr lookup or with shm_destroy(). +* Either way, the ID is busted. +*/ +WARN_ON_ONCE (err); }/*
@@ -258,6 +274,14 @@ static void shm_close(struct vm_area_strdown_write (&shm_ids (ns).rwsem);/* remove from the list of attaches of the shm segment */ shp =shm_lock (ns, sfd->id); + +/* +* We raced in the idr lookup or with shm_destroy(). +* Either way, the ID is busted. +*/ +if (WARN_ON_ONCE (IS_ERR (shp))) + goto done;/* no-op */ + shp->shm_lprid =task_tgid_vnr (current); shp->shm_dtim =get_seconds (); shp->shm_nattch--;
@@ -265,6 +289,7 @@ static void shm_close(struct vm_area_strshm_destroy (ns, shp); elseshm_unlock (shp ); +done:up_write (&shm_ids (ns).rwsem); }
@@ -385,17 +410,25 @@ static int shm_mmap(struct file *file, sstruct shm_file_data *sfd =shm_file_data (file);int ret; +/* +* In case of remap_file_pages() emulation, the file can represent +* removed IPC ID: propogate shm_lock() error to caller. +*/ + ret =__shm_open (vma); +if (ret) +return ret; + ret = sfd->file->f_op->mmap (sfd->file, vma); -if (ret !=0 ) +if (ret) { +shm_close (vma);return ret; + } sfd->vm_ops = vma->vm_ops;#ifdef CONFIG_MMU WARN_ON (!sfd->vm_ops->fault);#endif vma->vm_ops = &shm_vm_ops; -shm_open (vma); - -return ret; +return 0 ; }static int shm_release (struct inode *ino,struct file *file)