Re: [PATCH] thermal: core: Move initial num_trips assignment before memcpy()

2024-02-28 Thread Lukasz Luba
Hi Nathan and Kees, On 2/27/24 17:00, Kees Cook wrote: On Tue, Feb 27, 2024 at 05:47:44PM +0100, Daniel Lezcano wrote: Ok my misunderstanding was I thought sizeof() was calling _bdos under the hood, so when calling sizeof(flex_array), it was returning the computed size inferring from the __coun

Re: [PATCH] arm64: smp: smp_send_stop() and crash_smp_send_stop() should try non-NMI first

2024-02-28 Thread Daniel Thompson
On Tue, Feb 27, 2024 at 04:57:31PM -0800, Doug Anderson wrote: > Hi, > > On Mon, Jan 8, 2024 at 4:54 PM Doug Anderson wrote: > > > > Hi, > > > > On Thu, Dec 7, 2023 at 5:03 PM Douglas Anderson > > wrote: > > > > > > When testing hard lockup handling on my sc7180-trogdor-lazor device > > > with p

Re: [PATCH] thermal: core: Move initial num_trips assignment before memcpy()

2024-02-28 Thread Nathan Chancellor
On Wed, Feb 28, 2024 at 08:41:07AM +, Lukasz Luba wrote: > Hi Nathan and Kees, > > On 2/27/24 17:00, Kees Cook wrote: > > On Tue, Feb 27, 2024 at 05:47:44PM +0100, Daniel Lezcano wrote: > > > Ok my misunderstanding was I thought sizeof() was calling _bdos under the > > > hood, so when calling

Re: [PATCH] thermal: core: Move initial num_trips assignment before memcpy()

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 09:56:51AM -0700, Nathan Chancellor wrote: > On Wed, Feb 28, 2024 at 08:41:07AM +, Lukasz Luba wrote: > > Hi Nathan and Kees, > > > > On 2/27/24 17:00, Kees Cook wrote: > > > On Tue, Feb 27, 2024 at 05:47:44PM +0100, Daniel Lezcano wrote: > > > > Ok my misunderstanding

[PATCH v4 4/8] iio: core: Calculate alloc_size only once in iio_device_alloc()

2024-02-28 Thread Andy Shevchenko
No need to rewrite the value, instead use 'else' branch. This will also help further refactoring the code later on. Signed-off-by: Andy Shevchenko --- drivers/iio/industrialio-core.c | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/dr

[PATCH v4 2/8] overflow: Add struct_size_with_data() and struct_data_pointer() helpers

2024-02-28 Thread Andy Shevchenko
Introduce two helper macros to calculate the size of the structure with trailing aligned data and to retrieve the pointer to that data. Signed-off-by: Andy Shevchenko --- include/linux/overflow.h | 27 ++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/incl

[PATCH v4 0/8] iio: core: New macros and making use of them

2024-02-28 Thread Andy Shevchenko
Added new macros to overflow.h and reuse it in IIO. For the sake of examples a few more places were updated (requested by Kees). In case maintainers are okay, tags will be appreciated. v4: - dropped applied patches - refactored macros and code to make them simpler (Jonathan) - moved (renamed) mac

[PATCH v4 3/8] iio: core: NULLify private pointer when there is no private data

2024-02-28 Thread Andy Shevchenko
In iio_device_alloc() when size of the private data is 0, the private pointer is calculated to behind the valid data. NULLify it for good. Fixes: 6d4ebd565d15 ("iio: core: wrap IIO device into an iio_dev_opaque object") Signed-off-by: Andy Shevchenko --- drivers/iio/industrialio-core.c | 8 +

[PATCH v4 1/8] overflow: Use POD in check_shl_overflow()

2024-02-28 Thread Andy Shevchenko
The check_shl_overflow() uses u64 type that is defined in types.h. Instead of including that header, just switch to use POD type directly. Signed-off-by: Andy Shevchenko --- include/linux/overflow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/overflow.h b/in

[PATCH v4 6/8] spi: Use new helpers from overflow.h in __spi_alloc_controller()

2024-02-28 Thread Andy Shevchenko
We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in __spi_alloc_controller(). Do it so. Signed-off-by: Andy Shevchenko --- drivers/spi/spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.

[PATCH v4 8/8] dmaengine: ste_dma40: Use new helpers from overflow.h

2024-02-28 Thread Andy Shevchenko
We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in d40_hw_detect_init(). Do it so. Signed-off-by: Andy Shevchenko --- drivers/dma/ste_dma40.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/dma/ste_dma40.c b/d

[PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Andy Shevchenko
We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in alloc_netdev_mqs() and netdev_priv(). Do it so. Signed-off-by: Andy Shevchenko --- include/linux/netdevice.h | 3 ++- net/core/dev.c| 10 +- 2 files changed, 7 insertions(+), 6 d

[PATCH v4 5/8] iio: core: Use new helpers from overflow.h in iio_device_alloc()

2024-02-28 Thread Andy Shevchenko
We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in iio_device_alloc(). Do it so. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers

Re: [PATCH v4 4/8] iio: core: Calculate alloc_size only once in iio_device_alloc()

2024-02-28 Thread David Lechner
On Wed, Feb 28, 2024 at 2:49 PM Andy Shevchenko wrote: > > No need to rewrite the value, instead use 'else' branch. > This will also help further refactoring the code later on. > > Signed-off-by: Andy Shevchenko > --- > drivers/iio/industrialio-core.c | 9 - > 1 file changed, 4 insertion

Re: [PATCH v4 6/8] spi: Use new helpers from overflow.h in __spi_alloc_controller()

2024-02-28 Thread Mark Brown
On Wed, Feb 28, 2024 at 10:41:36PM +0200, Andy Shevchenko wrote: > We have two new helpers struct_size_with_data() and struct_data_pointer() > that we can utilize in __spi_alloc_controller(). Do it so. Acked-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH v4 3/8] iio: core: NULLify private pointer when there is no private data

2024-02-28 Thread David Lechner
On Wed, Feb 28, 2024 at 2:50 PM Andy Shevchenko wrote: > > In iio_device_alloc() when size of the private data is 0, > the private pointer is calculated to behind the valid data. > NULLify it for good. > > Fixes: 6d4ebd565d15 ("iio: core: wrap IIO device into an iio_dev_opaque > object") > Signed

Re: [PATCH v4 4/8] iio: core: Calculate alloc_size only once in iio_device_alloc()

2024-02-28 Thread Andy Shevchenko
On Wed, Feb 28, 2024 at 02:57:36PM -0600, David Lechner wrote: > On Wed, Feb 28, 2024 at 2:49 PM Andy Shevchenko > wrote: ... > > - alloc_size = sizeof(struct iio_dev_opaque); > > - if (sizeof_priv) { > > - alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN); > > -

Re: [PATCH v4 1/8] overflow: Use POD in check_shl_overflow()

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:41:31PM +0200, Andy Shevchenko wrote: > The check_shl_overflow() uses u64 type that is defined in types.h. > Instead of including that header, just switch to use POD type > directly. > > Signed-off-by: Andy Shevchenko Acked-by: Kees Cook -- Kees Cook

Re: [PATCH v4 3/8] iio: core: NULLify private pointer when there is no private data

2024-02-28 Thread Andy Shevchenko
On Wed, Feb 28, 2024 at 03:06:42PM -0600, David Lechner wrote: > On Wed, Feb 28, 2024 at 2:50 PM Andy Shevchenko > wrote: ... > > - indio_dev->priv = (char *)iio_dev_opaque + > > - ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); > > + > > + if (sizeof_priv) > >

Re: [PATCH v4 2/8] overflow: Add struct_size_with_data() and struct_data_pointer() helpers

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:41:32PM +0200, Andy Shevchenko wrote: > Introduce two helper macros to calculate the size of the structure > with trailing aligned data and to retrieve the pointer to that data. > > Signed-off-by: Andy Shevchenko > --- > include/linux/overflow.h | 27 ++

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:41:37PM +0200, Andy Shevchenko wrote: > We have two new helpers struct_size_with_data() and struct_data_pointer() > that we can utilize in alloc_netdev_mqs() and netdev_priv(). Do it so. > > Signed-off-by: Andy Shevchenko > --- > include/linux/netdevice.h | 3 ++- > n

Re: [PATCH v4 2/8] overflow: Add struct_size_with_data() and struct_data_pointer() helpers

2024-02-28 Thread Andy Shevchenko
On Wed, Feb 28, 2024 at 01:37:36PM -0800, Kees Cook wrote: > On Wed, Feb 28, 2024 at 10:41:32PM +0200, Andy Shevchenko wrote: ... > > +#define struct_data_pointer(p, a) PTR_ALIGN((void *)((p) + 1), (a)) > > I'm not super excited about propagating the "p + 1" code pattern to find > things after

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Andy Shevchenko
On Wed, Feb 28, 2024 at 01:46:10PM -0800, Kees Cook wrote: > On Wed, Feb 28, 2024 at 10:41:37PM +0200, Andy Shevchenko wrote: ... > > static inline void *netdev_priv(const struct net_device *dev) > > { > > - return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); > > + return s

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Jakub Kicinski
On Wed, 28 Feb 2024 13:46:10 -0800 Kees Cook wrote: > I really don't like hiding these trailing allocations from the compiler. > Why can't something like this be done (totally untested): > > > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > index 118c40258d07..dae6df4fb177 10

[PATCH v2 0/7] scsi: replace deprecated strncpy

2024-02-28 Thread Justin Stitt
This series contains multiple replacements of strncpy throughout the scsi subsystem. strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. The details of each replacement will be in their respective

[PATCH v2 1/7] scsi: mpi3mr: replace deprecated strncpy with assignments

2024-02-28 Thread Justin Stitt
Really, there's no bug with the current code. Let's just ditch strncpy() all together. We can just copy the const strings instead of reserving room on the stack. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.deb

[PATCH v2 2/7] scsi: mpt3sas: replace deprecated strncpy with strscpy

2024-02-28 Thread Justin Stitt
The replacement in mpt3sas_base.c is a trivial one because desc is already zero-initialized meaning there is no functional change here. For mpt3sas_transport.c, we know edev is zero-initialized as well while manufacture_reply comes from dma_alloc_coherent(). No functional change here either. For

[PATCH v2 3/7] scsi: qedf: replace deprecated strncpy with strscpy

2024-02-28 Thread Justin Stitt
We expect slowpath_params.name to be NUL-terminated based on its future usage with other string APIs: | static int qed_slowpath_start(struct qed_dev *cdev, | struct qed_slowpath_params *params) ... | strscpy(drv_version.name, params->name, |

[PATCH v2 4/7] scsi: qla4xxx: replace deprecated strncpy with strscpy

2024-02-28 Thread Justin Stitt
Replace 3 instances of strncpy in ql4_mbx.c No bugs exist in the current implementation as some care was taken to ensure the write length was decreased by one to leave some space for a NUL-byte. However, instead of using strncpy(dest, src, LEN-1) we can opt for strscpy(dest, src, sizeof(dest)) whi

[PATCH v2 5/7] scsi: devinfo: replace strncpy and manual pad

2024-02-28 Thread Justin Stitt
Depending on the state of @compatible, we are going to do different things with our @to buffer. When @compatible is true we want a NUL-term'd and NUL-padded destination buffer. Conversely, if @compatible is false we just want a space-padded destination buffer (no NUL-term required). As per: /**

[PATCH v2 7/7] scsi: wd33c93: replace deprecated strncpy with strscpy

2024-02-28 Thread Justin Stitt
@p1 is assigned to @setup_buffer and then we manually assign a NUL-byte at the first index. This renders the following strlen() call useless. Moreover, we don't need to reassign p1 to setup_buffer for any reason -- neither do we need to manually set a NUL-byte at the end. strscpy() resolves all thi

[PATCH v2 6/7] scsi: smartpqi: replace deprecated strncpy with strscpy

2024-02-28 Thread Justin Stitt
buffer->driver_version is sized 32: | struct bmic_host_wellness_driver_version { | ... | chardriver_version[32]; ... the source string "Linux " + DRIVER_VERISON is sized at 16. There's really no bug in the existing code since the buffers are sized appropriately with gr

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 02:41:48PM -0800, Jakub Kicinski wrote: > On Wed, 28 Feb 2024 13:46:10 -0800 Kees Cook wrote: > > I really don't like hiding these trailing allocations from the compiler. > > Why can't something like this be done (totally untested): > > > > > > diff --git a/include/linux/n

Re: [PATCH v2 1/7] scsi: mpi3mr: replace deprecated strncpy with assignments

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:59:01PM +, Justin Stitt wrote: > Really, there's no bug with the current code. Let's just ditch strncpy() > all together. > > We can just copy the const strings instead of reserving room on the > stack. > > Link: > https://www.kernel.org/doc/html/latest/process/dep

Re: [PATCH v2 2/7] scsi: mpt3sas: replace deprecated strncpy with strscpy

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:59:02PM +, Justin Stitt wrote: > The replacement in mpt3sas_base.c is a trivial one because desc is > already zero-initialized meaning there is no functional change here. > > For mpt3sas_transport.c, we know edev is zero-initialized as well while > manufacture_reply

Re: [PATCH v2 3/7] scsi: qedf: replace deprecated strncpy with strscpy

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:59:03PM +, Justin Stitt wrote: > We expect slowpath_params.name to be NUL-terminated based on its future > usage with other string APIs: > > | static int qed_slowpath_start(struct qed_dev *cdev, > | struct qed_slowpath_params *pa

Re: [PATCH v2 4/7] scsi: qla4xxx: replace deprecated strncpy with strscpy

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:59:04PM +, Justin Stitt wrote: > Replace 3 instances of strncpy in ql4_mbx.c > > No bugs exist in the current implementation as some care was taken to > ensure the write length was decreased by one to leave some space for a > NUL-byte. However, instead of using strnc

Re: [PATCH v2 0/7] scsi: replace deprecated strncpy

2024-02-28 Thread Kees Cook
On Wed, Feb 28, 2024 at 10:59:00PM +, Justin Stitt wrote: > This series contains multiple replacements of strncpy throughout the > scsi subsystem. > > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Gustavo A. R. Silva
On 2/28/24 18:01, Kees Cook wrote: On Wed, Feb 28, 2024 at 02:41:48PM -0800, Jakub Kicinski wrote: On Wed, 28 Feb 2024 13:46:10 -0800 Kees Cook wrote: I really don't like hiding these trailing allocations from the compiler. Why can't something like this be done (totally untested): diff --g

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Jakub Kicinski
On Wed, 28 Feb 2024 16:01:49 -0800 Kees Cook wrote: > So, I found several cases where struct net_device is included in the > middle of another structure, which makes my proposal more awkward. But I > also don't understand why it's in the _middle_. Shouldn't it always be > at the beginning (with pri

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Jakub Kicinski
On Wed, 28 Feb 2024 18:49:25 -0600 Gustavo A. R. Silva wrote: > struct net_device { > struct_group_tagged(net_device_hdr, hdr, > ... > u32 priv_size; > ); > u8 priv_data[] __counted_by(priv_size) > __aligned(NET

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Gustavo A. R. Silva
On 2/28/24 18:57, Jakub Kicinski wrote: On Wed, 28 Feb 2024 18:49:25 -0600 Gustavo A. R. Silva wrote: struct net_device { struct_group_tagged(net_device_hdr, hdr, ... u32 priv_size; ); u8 priv_dat

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Jakub Kicinski
On Wed, 28 Feb 2024 19:03:12 -0600 Gustavo A. R. Silva wrote: > On 2/28/24 18:57, Jakub Kicinski wrote: > > On Wed, 28 Feb 2024 18:49:25 -0600 Gustavo A. R. Silva wrote: > >> struct net_device { > >>struct_group_tagged(net_device_hdr, hdr, > >>... > >>u32

Re: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs

2024-02-28 Thread Gustavo A. R. Silva
On 2/28/24 19:15, Jakub Kicinski wrote: On Wed, 28 Feb 2024 19:03:12 -0600 Gustavo A. R. Silva wrote: On 2/28/24 18:57, Jakub Kicinski wrote: On Wed, 28 Feb 2024 18:49:25 -0600 Gustavo A. R. Silva wrote: struct net_device { struct_group_tagged(net_device_hdr, hdr, ..

Re: [PATCH] leaking_addresses: Provide mechanism to scan binary files

2024-02-28 Thread Tobin Harding
On Thu, Feb 22, 2024 at 04:49:26PM -0700, Tycho Andersen wrote: > On Thu, Feb 22, 2024 at 01:00:40PM -0800, Kees Cook wrote: > > > This does bring up some interesting questions. From off-list > > > discussions with Tobin, I believe he is not particularly interested in > > > maintaining this script

Re: [PATCH] leaking_addresses: Provide mechanism to scan binary files

2024-02-28 Thread Kees Cook
On Thu, Feb 29, 2024 at 03:40:13PM +1100, Tobin Harding wrote: > On Thu, Feb 22, 2024 at 04:49:26PM -0700, Tycho Andersen wrote: > > On Thu, Feb 22, 2024 at 01:00:40PM -0800, Kees Cook wrote: > > > > This does bring up some interesting questions. From off-list > > > > discussions with Tobin, I beli

[PATCH v3] driver core: Cancel scheduled pm_runtime_idle() on device removal

2024-02-28 Thread Kai-Heng Feng
When inserting an SD7.0 card to Realtek card reader, the card reader unplugs itself and morph into a NVMe device. The slot Link down on hot unplugged can cause the following error: pcieport :00:1c.0: pciehp: Slot(8): Link Down BUG: unable to handle page fault for address: b24d403e5010 PGD

Re: [PATCH v3] driver core: Cancel scheduled pm_runtime_idle() on device removal

2024-02-28 Thread Greg KH
On Thu, Feb 29, 2024 at 02:22:00PM +0800, Kai-Heng Feng wrote: > When inserting an SD7.0 card to Realtek card reader, the card reader > unplugs itself and morph into a NVMe device. The slot Link down on hot > unplugged can cause the following error: > > pcieport :00:1c.0: pciehp: Slot(8): Link

Re: [PATCH] thermal: core: Move initial num_trips assignment before memcpy()

2024-02-28 Thread Lukasz Luba
On 2/28/24 17:48, Kees Cook wrote: On Wed, Feb 28, 2024 at 09:56:51AM -0700, Nathan Chancellor wrote: On Wed, Feb 28, 2024 at 08:41:07AM +, Lukasz Luba wrote: Hi Nathan and Kees, On 2/27/24 17:00, Kees Cook wrote: On Tue, Feb 27, 2024 at 05:47:44PM +0100, Daniel Lezcano wrote: Ok my m

RE: [PATCH v3] driver core: Cancel scheduled pm_runtime_idle() on device removal

2024-02-28 Thread Ricky WU
> When inserting an SD7.0 card to Realtek card reader, the card reader > unplugs itself and morph into a NVMe device. The slot Link down on hot > unplugged can cause the following error: > > pcieport :00:1c.0: pciehp: Slot(8): Link Down > BUG: unable to handle page fault for address: b24d4