Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Christoph Hellwig
On Fri, Oct 20, 2023 at 11:30:49AM -0700, Kees Cook wrote: > I'm curious where you looked and didn't find documentation -- perhaps > there is an improvement to be made to aim one to where the existing > documentation lives? My order was the following: - look for kernel doc on the main function i

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread James Bottomley
On Thu, 2023-10-26 at 12:01 +0200, Christoph Hellwig wrote: > > > There's some docs at [1]. Perhaps there could be more? > > > > > > [1]: > > > https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 > > > > Right, And it's even valid kern-doc, which gets rendered in

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Andrew Lunn
> > > [1]: > > > https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 I found that https://elixir.bootlin.com/linux is the best way to find Documentation for functions and structures. I would suggest try it first, and only when what fails to start using grep.

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Laurent Pinchart
On Thu, Oct 26, 2023 at 03:44:22PM +0200, Andrew Lunn wrote: > > > > [1]: > > > > https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 > > I found that https://elixir.bootlin.com/linux is the best way to find > Documentation for functions and structures. I would su

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 07:39:44 -0400 James Bottomley wrote: > While it's nice in theory to have everything documented, it's not much > use if no one can actually find the information ... Does kerneldoc provide an automated index? That is, if we had a single file that had every function in the kern

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Geert Uytterhoeven
Hi Steven, On Thu, Oct 26, 2023 at 3:52 PM Steven Rostedt wrote: > On Thu, 26 Oct 2023 07:39:44 -0400 > James Bottomley wrote: > > > While it's nice in theory to have everything documented, it's not much > > use if no one can actually find the information ... > > Does kerneldoc provide an automa

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread Jonathan Corbet
Steven Rostedt writes: > On Thu, 26 Oct 2023 07:39:44 -0400 > James Bottomley wrote: > >> While it's nice in theory to have everything documented, it's not much >> use if no one can actually find the information ... > > Does kerneldoc provide an automated index? If you go to https://www.kernel.

Re: the nul-terminated string helper desk chair rearrangement

2023-10-26 Thread James Bottomley
On Thu, 2023-10-26 at 15:44 +0200, Andrew Lunn wrote: > > > > [1]: > > > > https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 > > I found that https://elixir.bootlin.com/linux That's a 404, I think you mean https://elixir.bootlin.com/linux/latest/source >  is t

[PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Kees Cook
Solve two ergonomic issues with struct seq_buf: 1) Too much boilerplate is required to initialize: struct seq_buf s; char buf[32]; seq_buf_init(s, buf, sizeof(buf)); Instead, we can build this directly on the stack. Provide DECLARE_SEQ_BUF() macro to do this: DE

[RFC][PATCH] wifi: wil6210: Replace strlcat() usage with seq_buf

2023-10-26 Thread Kees Cook
The use of strlcat() is fragile at best, and we'd like to remove it from the available string APIs in the kernel. Instead, use the safer seq_buf APIs. Cc: Kalle Valo Cc: Johannes Berg Cc: Max Chen Cc: Yang Shen Cc: Steven Rostedt Cc: "Matthew Wilcox (Oracle)" Cc: Christoph Hellwig Cc: Justi

Re: [PATCH v2] EDAC/thunderx: Fix some potential buffer overflow in thunderx_ocx_com_threaded_isr()

2023-10-26 Thread Kees Cook
On Tue, Oct 24, 2023 at 04:39:36PM -0700, Kees Cook wrote: > As the replacements get longer, I would encourage you to use seq_buf > instead -- it does all the length math internally. For example: There's some ongoing work to make seq_buf easier to use: https://lore.kernel.org/lkml/20231026170722.w

Re: [PATCH v3 1/2] wifi: brcm80211: replace deprecated strncpy with strscpy

2023-10-26 Thread Kees Cook
On Tue, Oct 17, 2023 at 08:11:28PM +, Justin Stitt wrote: > Let's move away from using strncpy and instead favor a less ambiguous > and more robust interface. > > For ifp->ndev->name, we expect ifp->ndev->name to be NUL-terminated based > on its use in format strings within core.c: > 67 |

Re: [PATCH v3 2/2] wifi: brcmsmac: replace deprecated strncpy with memcpy

2023-10-26 Thread Kees Cook
On Wed, Oct 18, 2023 at 05:03:02PM -0700, Kees Cook wrote: > On Tue, Oct 17, 2023 at 08:11:29PM +, Justin Stitt wrote: > > Let's move away from using strncpy and instead use the more obvious > > interface for this context. > [...] > So, this change results in the same behavior ... I should hav

Re: [PATCH] airo: replace deprecated strncpy with strscpy_pad

2023-10-26 Thread Kees Cook
On Tue, Oct 17, 2023 at 03:51:58PM -0700, Jeff Johnson wrote: > On 10/17/2023 2:12 PM, Justin Stitt wrote: > > strncpy() is deprecated for use on NUL-terminated destination strings > > [1] and as such we should prefer more robust and less ambiguous string > > interfaces. > > > > `extra` is clearly

Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 10:07:28 -0700 Kees Cook wrote: > Solve two ergonomic issues with struct seq_buf: "ergonomic"? Does it cause carpal tunnel? ;-) > > 1) Too much boilerplate is required to initialize: > > struct seq_buf s; > char buf[32]; > > seq_buf_init(s, buf, sizeof(b

Re: [PATCH] scsi: hpsa: replace deprecated strncpy with strscpy/kmemdup_nul

2023-10-26 Thread Kees Cook
On Thu, Oct 26, 2023 at 01:47:32AM +, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > This whole process of 1) determining smaller length so we don't overread

Re: [PATCH v2] scsi: elx: libefc: replace deprecated strncpy with strscpy_pad/memcpy

2023-10-26 Thread Kees Cook
On Thu, Oct 26, 2023 at 01:53:13AM +, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > To keep node->current_state_name and node->prev_state_name NUL-padded > a

Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Kees Cook
On Thu, Oct 26, 2023 at 01:38:50PM -0400, Steven Rostedt wrote: > On Thu, 26 Oct 2023 10:07:28 -0700 > Kees Cook wrote: > > > Solve two ergonomic issues with struct seq_buf: > > "ergonomic"? Does it cause carpal tunnel? ;-) > > > > > 1) Too much boilerplate is required to initialize: > > > >

Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 10:54:26 -0700 Kees Cook wrote: > > Do we really need to call it _cstr? Why not just have seq_buf_str() ? > > > > I mean, this is C, do we need to state that in the name too? > > I'm fine either way. I did that just to make the distinction between our > length-managed stri

Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Kees Cook
On Thu, Oct 26, 2023 at 02:02:47PM -0400, Steven Rostedt wrote: > On Thu, 26 Oct 2023 10:54:26 -0700 > Kees Cook wrote: > > > > Do we really need to call it _cstr? Why not just have seq_buf_str() ? > > > > > > I mean, this is C, do we need to state that in the name too? > > > > I'm fine eithe

Re: [PATCH] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_cstr()

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 12:35:43 -0700 Kees Cook wrote: > I'll send a v2 as seq_buf_str()... Thanks. -- Steve

[PATCH v2] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-10-26 Thread Kees Cook
Solve two ergonomic issues with struct seq_buf; 1) Too much boilerplate is required to initialize: struct seq_buf s; char buf[32]; seq_buf_init(s, buf, sizeof(buf)); Instead, we can build this directly on the stack. Provide DECLARE_SEQ_BUF() macro to do this: DE

Re: [PATCH v2] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 12:40:37 -0700 Kees Cook wrote: > @@ -81,16 +88,20 @@ static inline unsigned int seq_buf_used(struct seq_buf *s) > * > * After this function is called, s->buffer is safe to use > * in string operations. > + * > + * Returns @s->buf after making sure it is terminated. >

Re: [PATCH v2] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-10-26 Thread Andy Shevchenko
On Thu, Oct 26, 2023 at 12:40:37PM -0700, Kees Cook wrote: > Solve two ergonomic issues with struct seq_buf; > > 1) Too much boilerplate is required to initialize: > > struct seq_buf s; > char buf[32]; > > seq_buf_init(s, buf, sizeof(buf)); > > Instead, we can build this direc

Re: [PATCH v2] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-10-26 Thread Steven Rostedt
On Thu, 26 Oct 2023 23:20:15 +0300 Andy Shevchenko wrote: > > +#define DECLARE_SEQ_BUF(NAME, SIZE) > > \ > > + char __ ## NAME ## _buffer[SIZE] = ""; \ > > + struct seq_buf NAME = { .buffer = &__ ## NAME ## _buffer, \ > >

Re: [RFC][PATCH] wifi: wil6210: Replace strlcat() usage with seq_buf

2023-10-26 Thread Justin Stitt
On Thu, Oct 26, 2023 at 10:13 AM Kees Cook wrote: > > The use of strlcat() is fragile at best, and we'd like to remove it from > the available string APIs in the kernel. Instead, use the safer seq_buf > APIs. > > Cc: Kalle Valo > Cc: Johannes Berg > Cc: Max Chen > Cc: Yang Shen > Cc: Steven Ro

[PATCH v2] scsi: hpsa: replace deprecated strncpy

2023-10-26 Thread Justin Stitt
nux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Cc: Kees Cook Signed-off-by: Justin Stitt --- Changes in v2: - use stack for buffers (thanks Kees) - use kstrtoint (thanks Kees) - Link to v1: https://lore.kernel.org/r/202310

[PATCH v2] airo: replace deprecated strncpy with strscpy_pad

2023-10-26 Thread Justin Stitt
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. `extra` is clearly supposed to be NUL-terminated which is evident by the manual NUL-byte assignment as well as its immediate usage with strlen().

[PATCH v2] iio: sx9324: avoid copying property strings

2023-10-26 Thread Justin Stitt
We're doing some needless string copies when trying to assign the proper `prop` string. We can make `prop` a const char* and simply assign to string literals. For the case where a format string is used, let's allocate some memory via kasprintf() and point prop to it. This also cleans up some depr

Re: [PATCH] iio: sx9324: replace deprecated strncpy

2023-10-26 Thread Justin Stitt
ARRAY_SIZE(prop)); > > + strscpy(prop, "semtech,ph01-proxraw-strength", > > sizeof(prop)); > > else > > - strncpy(prop, "semtech,ph23-proxraw-strength", > > - ARRAY_SIZE(prop)); > > + strscpy(prop, "semtech,ph23-proxraw-strength", > > sizeof(prop)); > > ret = device_property_read_u32(dev, prop, &raw); > > if (ret) > > break; > > > > --- > > base-commit: 2cf0f715623872823a72e451243bbf555d10d032 > > change-id: 20230921-strncpy-drivers-iio-proximity-sx9324-c-8c3437676039 > > > > Best regards, > > -- > > Justin Stitt > > > [v2]: https://lore.kernel.org/r/20231026-strncpy-drivers-iio-proximity-sx9324-c-v2-1-cee6e5db7...@google.com Thanks Justin

Re: [PATCH v2] airo: replace deprecated strncpy with strscpy_pad

2023-10-26 Thread Jeff Johnson
On 10/26/2023 4:19 PM, Justin Stitt wrote: strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. `extra` is clearly supposed to be NUL-terminated which is evident by the manual NUL-byte assignment

Re: [PATCH v2] seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()

2023-10-26 Thread Christoph Hellwig
On Thu, Oct 26, 2023 at 12:40:37PM -0700, Kees Cook wrote: > Solve two ergonomic issues with struct seq_buf; > > 1) Too much boilerplate is required to initialize: > > struct seq_buf s; > char buf[32]; > > seq_buf_init(s, buf, sizeof(buf)); > > Instead, we can build this direc