drm/r128: Fix undefined behavior due to shift overflowing the constant
Subsystems (8)
Sasha Levin
maintainerPATCH 1/12 drm/r128: Fix undefined behavior due to shift overflowing the constant
From: Borislav Petkov <[email protected]>
[ Upstream commit 6556551f8848f98eff356c8aacae42c8dd65b2df ]
Fix:
drivers/gpu/drm/r128/r128_cce.c: In function ‘r128_do_init_cce’:
drivers/gpu/drm/r128/r128_cce.c:417:2: error: case label does not reduce to an integer constant
case R128_PM4_64BM_64VCBM_64INDBM:
^~~~
drivers/gpu/drm/r128/r128_cce.c:418:2: error: case label does not reduce to an integer constant
case R128_PM4_64PIO_64VCPIO_64INDPIO:
^~~~See https://lore.kernel.org/r/YkwQ6%[email protected] for the gory details as to why it triggers with older gccs only.
--- drivers/gpu/drm/r128/r128_drv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/r128/r128_drv.h +2 -2
@@ -289,8 +289,8 @@ extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,# define R128_PM4_64PIO_128INDBM (5 << 28)# define R128_PM4_64BM_128INDBM (6 << 28)# define R128_PM4_64PIO_64VCBM_64INDBM (7 << 28) -# define R128_PM4_64BM_64VCBM_64INDBM (8 << 28) -# define R128_PM4_64PIO_64VCPIO_64INDPIO (15 << 28) +# define R128_PM4_64BM_64VCBM_64INDBM (8U << 28) +# define R128_PM4_64PIO_64VCPIO_64INDPIO (15U << 28)# define R128_PM4_BUFFER_CNTL_NOUPDATE (1 << 27)#define R128_PM4_BUFFER_WM_CNTL 0x0708
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 2/12 drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole
From: Xiaohui Zhang <[email protected]>
[ Upstream commit 0381ac3ca2e727d4dfb7264d9416a8ba6bb6c18b ]
Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8 ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"), we thought a patch might be needed here as well.
The entries were only initialized once in radeon_sa_bo_new. If a fence wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then got signalled before a later radeon_sa_bo_next_hole call, it could destroy the fence but leave its pointer in the array, resulting in use-after-free in radeon_sa_bo_new.
--- drivers/gpu/drm/radeon/radeon_sa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_sa.c +3 -3
@@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager,for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {struct radeon_sa_bo *sa_bo; + fences[i] =NULL ; +if (list_empty (&sa_manager->flist[i])) {continue ; }
@@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev,spin_lock (&sa_manager->wq.lock); do { - for (i = 0; i < RADEON_NUM_RINGS; ++i) { - fences[i] = NULL; + for (i = 0; i < RADEON_NUM_RINGS; ++i) tries[i] = 0; - } do { radeon_sa_bo_try_free(sa_manager);
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 3/12 media: airspy: respect the DMA coherency rules
In reply to Sasha LevinFrom: Oliver Neukum <[email protected]>
[ Upstream commit ca9dc8d06ab64543a6a31adac5003349c5671218 ]
If we want to avoid memory corruption
on incoherent architectures, buffers for DMA
must not reside
- on the stack
- embedded within other structures
Allocate them separately.
v2: fix uninitialized return value
--- drivers/media/usb/airspy/airspy.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/media/usb/airspy/airspy.c +15 -2
@@ -134,7 +134,7 @@ struct airspy {/* USB control message buffer */ #define BUF_SIZE 128 -u8 buf[BUF_SIZE ]; +u8 *buf;/* Current configuration */ unsigned int f_adc;
@@ -872,6 +872,7 @@ static void airspy_video_release(struct v4l2_device *v)v4l2_ctrl_handler_free (&s->hdl);v4l2_device_unregister (&s->v4l2_dev); +kfree (s->buf);kfree (s); }
@@ -979,7 +980,10 @@ static int airspy_probe(struct usb_interface *intf, {struct airspy *s;int ret; -u8 u8tmp, buf[BUF_SIZE ]; +u8 u8tmp, *buf; + + buf =NULL ; + ret = -ENOMEM ; s =kzalloc (sizeof (struct airspy ),GFP_KERNEL );if (s ==NULL ) {
@@ -987,6 +991,13 @@ static int airspy_probe(struct usb_interface *intf,return -ENOMEM ; } + s->buf =kzalloc (BUF_SIZE ,GFP_KERNEL ); +if (!s->buf) + goto err_free_mem; + buf =kzalloc (BUF_SIZE ,GFP_KERNEL ); +if (!buf) + goto err_free_mem; +mutex_init (&s->v4l2_lock);mutex_init (&s->vb_queue_lock);spin_lock_init (&s->queued_bufs_lock);
@@ -1082,6 +1093,8 @@ static int airspy_probe(struct usb_interface *intf,v4l2_ctrl_handler_free (&s->hdl);v4l2_device_unregister (&s->v4l2_dev); err_free_mem: +kfree (buf); +kfree (s->buf);kfree (s);return ret; }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 4/12 media: pvrusb2: fix memory leak in pvr_probe
In reply to Sasha LevinFrom: Dongliang Mu <[email protected]>
[ Upstream commit 945a9a8e448b65bec055d37eba58f711b39f66f0 ]
The error handling code in pvr2_hdw_create forgets to unregister the v4l2 device. When pvr2_hdw_create returns back to pvr2_context_create, it calls pvr2_context_destroy to destroy context, but mp->hdw is NULL, which leads to that pvr2_hdw_destroy directly returns.
Fix this by adding v4l2_device_unregister to decrease the refcount of usb interface.
--- drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +1 -0
@@ -2656,6 +2656,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,del_timer_sync (&hdw->encoder_run_timer);del_timer_sync (&hdw->encoder_wait_timer);flush_work (&hdw->workpoll); +v4l2_device_unregister (&hdw->v4l2_dev);usb_free_urb (hdw->ctl_read_urb);usb_free_urb (hdw->ctl_write_urb);kfree (hdw->ctl_read_buffer);
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 5/12 mlxsw: cmd: Increase 'config_profile.flood_mode' length
In reply to Sasha LevinFrom: Amit Cohen <[email protected]>
[ Upstream commit 89df3c6261f271c550f120b5ccf4d9c5132e870c ]
Currently, the length of 'config_profile.flood_mode' is defined as 2 bits, while the correct length is 3 bits.
As preparation for unified bridge model, which will use the whole field length, fix it and increase the field to the correct size.
--- drivers/net/ethernet/mellanox/mlxsw/cmd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/cmd.h +1 -1
@@ -722,7 +722,7 @@ MLXSW_ITEM32(cmd_mbox, config_profile, max_vid_flood_tables, 0x30, 8, 4);* max_fid_offset_flood_tables indicates the number of FID-offset tables. * max_fid_flood_tables indicates the number of per-FID tables. */ -MLXSW_ITEM32 (cmd_mbox, config_profile, flood_mode,0x30 ,0 ,2 ); +MLXSW_ITEM32 (cmd_mbox, config_profile, flood_mode,0x30 ,0 ,3 );/* cmd_mbox_config_profile_max_fid_offset_flood_tables * Maximum number of FID-offset flooding tables.
Signature · 1 line
2.35.1
Re: [PATCH AUTOSEL 4.9 05/12] mlxsw: cmd: Increase 'config_profile.flood_mode' length
Hi!
Quoted 9 lines
From: Amit Cohen <[email protected]>
[ Upstream commit
89df3c6261f271c550f120b5ccf4d9c5132e870c]Currently, the length of 'config_profile.flood_mode' is defined as 2 bits, while the correct length is 3 bits.
As preparation for unified bridge model, which will use the whole field length, fix it and increase the field to the correct size.
I don't think we need here as follow-up patches are not queued for at least 4.9 and 4.19...
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Sasha Levin
maintainerPATCH 6/12 iov_iter_get_pages{,_alloc}(): cap the maxsize with MAX_RW_COUNT
In reply to Sasha LevinFrom: Al Viro <[email protected]>
[ Upstream commit 7392ed1734c319150b5ddec3f192a6405728e8d0 ]
All callers can and should handle iov_iter_get_pages() returning fewer pages than requested. All in-kernel ones do. And it makes the arithmetical overflow analysis much simpler...
--- lib/iov_iter.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/iov_iter.c +4 -0
@@ -951,6 +951,8 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,if (!maxsize)return 0 ; +if (maxsize >MAX_RW_COUNT ) + maxsize =MAX_RW_COUNT ;if (unlikely (i->type &ITER_PIPE ))return pipe_get_pages (i, pages, maxsize, maxpages, start);
@@ -1031,6 +1033,8 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,if (!maxsize)return 0 ; +if (maxsize >MAX_RW_COUNT ) + maxsize =MAX_RW_COUNT ;if (unlikely (i->type &ITER_PIPE ))return pipe_get_pages_alloc (i, pages, maxsize, start);
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 7/12 crypto: vmx - Fix warning on p8_ghash_alg
In reply to Sasha LevinFrom: Herbert Xu <[email protected]>
[ Upstream commit cc8166bfc829043020b5cc3b7cdba02a17d03b6d ]
The compiler complains that p8_ghash_alg isn't declared which is because the header file aesp8-ppc.h isn't included in ghash.c. This patch fixes the warning.
--- drivers/crypto/vmx/ghash.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/vmx/ghash.c +1 -0
@@ -22,6 +22,7 @@#include <crypto/scatterwalk.h> #include <crypto/internal/hash.h> #include <crypto/b128ops.h> +#include "aesp8-ppc.h" #define IN_INTERRUPT in_interrupt()
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 8/12 can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller
In reply to Sasha LevinFrom: Biju Das <[email protected]>
[ Upstream commit 2d99bfbf3386962692dcccd73931cb0db07a1a43 ]
As per Chapter 6.5.16 of the RZ/N1 Peripheral Manual, The SJA1000 CAN controller does not support Clock Divider Register compared to the reference Philips SJA1000 device.
This patch adds a device quirk to handle this difference.
--- drivers/net/can/sja1000/sja1000.c | 8 +++++--- drivers/net/can/sja1000/sja1000.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-)
drivers/net/can/sja1000/sja1000.c +5 -3
@@ -184,8 +184,9 @@ static void chipset_init(struct net_device *dev) {struct sja1000_priv *priv =netdev_priv (dev); -/* set clock divider and output control register */ - priv->write_reg (priv,SJA1000_CDR , priv->cdr |CDR_PELICAN ); +if (!(priv->flags &SJA1000_QUIRK_NO_CDR_REG )) +/* set clock divider and output control register */ + priv->write_reg (priv,SJA1000_CDR , priv->cdr |CDR_PELICAN );/* set acceptance filter (accept all) */ priv->write_reg (priv,SJA1000_ACCC0 ,0x00 );
@@ -210,7 +211,8 @@ static void sja1000_start(struct net_device *dev)set_reset_mode (dev);/* Initialize chip if uninitialized at this stage */ -if (!(priv->read_reg (priv,SJA1000_CDR ) &CDR_PELICAN )) +if (!(priv->flags &SJA1000_QUIRK_NO_CDR_REG || + priv->read_reg (priv,SJA1000_CDR ) &CDR_PELICAN ))chipset_init (dev);/* Clear error counters and error code capture */
drivers/net/can/sja1000/sja1000.h +2 -1
@@ -145,7 +145,8 @@/* * Flags for sja1000priv.flags */ -#define SJA1000_CUSTOM_IRQ_HANDLER 0x1 +#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0) +#define SJA1000_QUIRK_NO_CDR_REG BIT(1)/* * SJA1000 private data structure
Signature · 1 line
2.35.1
Re: [PATCH AUTOSEL 4.9 08/12] can: sja1000: Add Quirk for RZ/N1 SJA1000 CAN controller
Hi!
Quoted 5 lines
As per Chapter 6.5.16 of the RZ/N1 Peripheral Manual, The SJA1000 CAN controller does not support Clock Divider Register compared to the reference Philips SJA1000 device.
This patch adds a device quirk to handle this difference.
I don't think this is suitable for stable (at least 5.10.X and older) as we don't have user of the quirk queued up.
Best regards,
Pavel
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Sasha Levin
maintainerPATCH 9/12 net/cdc_ncm: Increase NTB max RX/TX values to 64kb
In reply to Sasha LevinFrom: Łukasz Spintzyk <[email protected]>
[ Upstream commit 5588d628027092e66195097bdf6835ddf64418b3 ]
DisplayLink ethernet devices require NTB buffers larger then 32kb in order to run with highest performance.
This patch is changing upper limit of the rx and tx buffers. Those buffers are initialized with CDC_NCM_NTB_DEF_SIZE_RX and CDC_NCM_NTB_DEF_SIZE_TX which is 16kb so by default no device is affected by increased limit.
Rx and tx buffer is increased under two conditions:
- Device need to advertise that it supports higher buffer size in dwNtbMaxInMaxSize and dwNtbMaxOutMaxSize.
- cdc_ncm/rx_max and cdc_ncm/tx_max driver parameters must be adjusted with udev rule or ethtool.
Summary of testing and performance results:
Tests were performed on following devices:
- DisplayLink DL-3xxx family device
- DisplayLink DL-6xxx family device
- ASUS USB-C2500 2.5G USB3 ethernet adapter
- Plugable USB3 1G USB3 ethernet adapter
- EDIMAX EU-4307 USB-C ethernet adapter
- Dell DBQBCBC064 USB-C ethernet adapter
Performance measurements were done with:
- iperf3 between two linux boxes
- http://openspeedtest.com/ instance running on local test machine
Insights from tests results:
- All except one from third party usb adapters were not affected by increased buffer size to their advertised dwNtbOutMaxSize and dwNtbInMaxSize.
Devices were generally reaching 912-940Mbps both download and upload.
Only EDIMAX adapter experienced decreased download size from 929Mbps to 827Mbps with iper3, with openspeedtest decrease was from 968Mbps to 886Mbps.
- DisplayLink DL-3xxx family devices experienced performance increase with iperf3 download from 300Mbps to 870Mbps and
upload from 782Mbps to 844Mbps.
With openspeedtest download increased from 556Mbps to 873Mbps and upload from 727Mbps to 973Mbps
- DiplayLink DL-6xxx family devices are not affected by increased buffer size.
--- include/linux/usb/cdc_ncm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/usb/cdc_ncm.h +2 -2
@@ -49,8 +49,8 @@#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10/* Maximum NTB length */ -#define CDC_NCM_NTB_MAX_SIZE_TX 32768/* bytes */ -#define CDC_NCM_NTB_MAX_SIZE_RX 32768/* bytes */ +#define CDC_NCM_NTB_MAX_SIZE_TX 65536/* bytes */ +#define CDC_NCM_NTB_MAX_SIZE_RX 65536/* bytes */ /* Initial NTB length */ #define CDC_NCM_NTB_DEF_SIZE_TX 16384/* bytes */
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 10/12 wifi: rtl8xxxu: Fix the error handling of the probe function
In reply to Sasha LevinFrom: Zheyu Ma <[email protected]>
[ Upstream commit 13876f2a087ad352bf640a7a0a4a4229ea6e9e4f ]
When the driver fails at ieee80211_alloc_hw() at the probe time, the driver will free the 'hw' which is not allocated, causing a bug.
The following log can reveal it:
[ 15.981294] BUG: KASAN: user-memory-access in mutex_is_locked+0xe/0x40 [ 15.981558] Read of size 8 at addr 0000000000001ab0 by task modprobe/373 [ 15.982583] Call Trace: [ 15.984282] ieee80211_free_hw+0x22/0x390 [ 15.984446] rtl8xxxu_probe+0x3a1/0xab30 [rtl8xxxu]
Fix the bug by changing the order of the error handling.
--- .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +11 -10
@@ -6023,7 +6023,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,if (!hw) { ret = -ENOMEM ; priv =NULL ; - goto exit; + goto err_put_dev; } priv = hw->priv;
@@ -6042,24 +6042,24 @@ static int rtl8xxxu_probe(struct usb_interface *interface, ret =rtl8xxxu_parse_usb (priv, interface);if (ret) - goto exit; + goto err_set_intfdata; ret =rtl8xxxu_identify_chip (priv);if (ret) {dev_err (&udev->dev,"Fatal - failed to identify chip\n" ); - goto exit; + goto err_set_intfdata; } ret =rtl8xxxu_read_efuse (priv);if (ret) {dev_err (&udev->dev,"Fatal - failed to read EFuse\n" ); - goto exit; + goto err_set_intfdata; } ret = priv->fops->parse_efuse (priv);if (ret) {dev_err (&udev->dev,"Fatal - failed to parse EFuse\n" ); - goto exit; + goto err_set_intfdata; }rtl8xxxu_print_chipinfo (priv);
@@ -6067,12 +6067,12 @@ static int rtl8xxxu_probe(struct usb_interface *interface, ret = priv->fops->load_firmware (priv);if (ret) {dev_err (&udev->dev,"Fatal - failed to load firmware\n" ); - goto exit; + goto err_set_intfdata; } ret =rtl8xxxu_init_device (hw);if (ret) - goto exit; + goto err_set_intfdata; hw->wiphy->max_scan_ssids =1 ; hw->wiphy->max_scan_ie_len =IEEE80211_MAX_DATA_LEN ;
@@ -6120,12 +6120,12 @@ static int rtl8xxxu_probe(struct usb_interface *interface,if (ret) {dev_err (&udev->dev,"%s: Failed to register: %i\n" , __func__, ret); - goto exit; + goto err_set_intfdata; }return 0 ; -exit: +err_set_intfdata:usb_set_intfdata (interface,NULL );if (priv) {
@@ -6133,9 +6133,10 @@ static int rtl8xxxu_probe(struct usb_interface *interface,mutex_destroy (&priv->usb_buf_mutex);mutex_destroy (&priv->h2c_mutex); } -usb_put_dev (udev);ieee80211_free_hw (hw); +err_put_dev: +usb_put_dev (udev);return ret; }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 11/12 d_add_ci(): make sure we don't miss d_lookup_done()
In reply to Sasha LevinFrom: Al Viro <[email protected]>
[ Upstream commit 40a3cb0d2314a41975aa385a74643878454f6eac ]
All callers of d_alloc_parallel() must make sure that resulting in-lookup dentry (if any) will encounter __d_lookup_done() before the final dput(). d_add_ci() might end up creating in-lookup dentries; they are fed to d_splice_alias(), which will normally make sure they meet __d_lookup_done(). However, it is possible to end up with d_splice_alias() failing with ERR_PTR(-ELOOP) without having done so. It takes a corrupted ntfs or case-insensitive xfs image, but neither should end up with memory corruption...
--- fs/dcache.c | 1 + 1 file changed, 1 insertion(+)
fs/dcache.c +1 -0
@@ -2089,6 +2089,7 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, } res =d_splice_alias (inode, found);if (res) { +d_lookup_done (found);dput (found);return res; }
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 12/12 fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT
In reply to Sasha LevinFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit cf634d540a29018e8d69ab1befb7e08182bc6594 ]
i_dir_seq is a sequence counter with a lock which is represented by the lowest bit. The writer atomically updates the counter which ensures that it can be modified by only one writer at a time. This requires preemption to be disabled across the write side critical section.
On !PREEMPT_RT kernels this is implicit by the caller acquiring dentry::lock. On PREEMPT_RT kernels spin_lock() does not disable preemption which means that a preempting writer or reader would live lock. It's therefore required to disable preemption explicitly.
An alternative solution would be to replace i_dir_seq with a seqlock_t for PREEMPT_RT, but that comes with its own set of problems due to arbitrary lock nesting. A pure sequence count with an associated spinlock is not possible because the locks held by the caller are not necessarily related.
As the critical section is small, disabling preemption is a sensible solution.
--- fs/dcache.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
fs/dcache.c +11 -1
@@ -2425,7 +2425,15 @@ EXPORT_SYMBOL(d_rehash);static inline unsigned start_dir_add (struct inode *dir) { - +/* +* The caller holds a spinlock (dentry::d_lock). On !PREEMPT_RT +* kernels spin_lock() implicitly disables preemption, but not on +* PREEMPT_RT. So for RT it has to be done explicitly to protect +* the sequence count write side critical section against a reader +* or another writer preempting, which would result in a live lock. +*/ +if (IS_ENABLED (CONFIG_PREEMPT_RT )) +preempt_disable ();for (;;) {unsigned n = dir->i_dir_seq;if (!(n &1 ) &&cmpxchg (&dir->i_dir_seq, n, n +1 ) == n)
@@ -2437,6 +2445,8 @@ static inline unsigned start_dir_add(struct inode *dir)static inline void end_dir_add (struct inode *dir,unsigned n) {smp_store_release (&dir->i_dir_seq, n +2 ); +if (IS_ENABLED (CONFIG_PREEMPT_RT )) +preempt_enable (); }static void d_wait_lookup (struct dentry *dentry)
Signature · 1 line
2.35.1