linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy()
@ 2025-08-15 21:37 Thorsten Blum
  2025-08-18 18:26 ` Justin Stitt
  2025-08-19 19:00 ` Marco Elver
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-08-15 21:37 UTC (permalink / raw)
  To: Marco Elver, Dmitry Vyukov
  Cc: linux-hardening, Thorsten Blum, kasan-dev, linux-kernel

strcpy() is deprecated; use strscpy() instead.

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 kernel/kcsan/kcsan_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
index 49ab81faaed9..ea1cb4c8a894 100644
--- a/kernel/kcsan/kcsan_test.c
+++ b/kernel/kcsan/kcsan_test.c
@@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
 				goto out;
 
 			/* No second line of interest. */
-			strcpy(observed.lines[nlines++], "<none>");
+			strscpy(observed.lines[nlines++], "<none>");
 		}
 	}
 
@@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
 
 			if (!r->access[1].fn) {
 				/* Dummy string if no second access is available. */
-				strcpy(cur, "<none>");
+				strscpy(expect[2], "<none>");
 				break;
 			}
 		}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy()
  2025-08-15 21:37 [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy() Thorsten Blum
@ 2025-08-18 18:26 ` Justin Stitt
  2025-08-18 19:32   ` Thorsten Blum
  2025-08-19 19:00 ` Marco Elver
  1 sibling, 1 reply; 4+ messages in thread
From: Justin Stitt @ 2025-08-18 18:26 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Marco Elver, Dmitry Vyukov, linux-hardening, kasan-dev,
	linux-kernel

Hi,

On Fri, Aug 15, 2025 at 11:37:44PM +0200, Thorsten Blum wrote:
> strcpy() is deprecated; use strscpy() instead.
> 
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  kernel/kcsan/kcsan_test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
> index 49ab81faaed9..ea1cb4c8a894 100644
> --- a/kernel/kcsan/kcsan_test.c
> +++ b/kernel/kcsan/kcsan_test.c
> @@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
>  				goto out;
>  
>  			/* No second line of interest. */
> -			strcpy(observed.lines[nlines++], "<none>");
> +			strscpy(observed.lines[nlines++], "<none>");

Looks good.

Here's my checklist:
1) strcpy() and strscpy() have differing return values, but we aren't using
it.
2) strscpy() can fail with -E2BIG if source is too big, but it isn't in
this case.
3) two-arg version of strscpy() is OK to use here as the source has a known
size at compile time.

Reviewed-by: Justin Stitt <justinstitt@google.com>

>  		}
>  	}
>  
> @@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
>  
>  			if (!r->access[1].fn) {
>  				/* Dummy string if no second access is available. */
> -				strcpy(cur, "<none>");
> +				strscpy(expect[2], "<none>");
>  				break;
>  			}
>  		}
> -- 
> 2.50.1
> 
>

Thanks
Justin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy()
  2025-08-18 18:26 ` Justin Stitt
@ 2025-08-18 19:32   ` Thorsten Blum
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-08-18 19:32 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Marco Elver, Dmitry Vyukov, linux-hardening, kasan-dev,
	linux-kernel

On 18. Aug 2025, at 20:26, Justin Stitt wrote:
> Looks good.
> 
> Here's my checklist:
> 1) strcpy() and strscpy() have differing return values, but we aren't using
> it.
> 2) strscpy() can fail with -E2BIG if source is too big, but it isn't in
> this case.
> 3) two-arg version of strscpy() is OK to use here as the source has a known
> size at compile time.
> 
> Reviewed-by: Justin Stitt <justinstitt@google.com>

Thanks for your thorough review.

Thorsten


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy()
  2025-08-15 21:37 [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy() Thorsten Blum
  2025-08-18 18:26 ` Justin Stitt
@ 2025-08-19 19:00 ` Marco Elver
  1 sibling, 0 replies; 4+ messages in thread
From: Marco Elver @ 2025-08-19 19:00 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: Dmitry Vyukov, linux-hardening, kasan-dev, linux-kernel

On Fri, 15 Aug 2025 at 23:38, Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> strcpy() is deprecated; use strscpy() instead.
>
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Marco Elver <elver@google.com>

Taking this into the -kcsan tree, but might be a while until it hits mainline.

> ---
>  kernel/kcsan/kcsan_test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
> index 49ab81faaed9..ea1cb4c8a894 100644
> --- a/kernel/kcsan/kcsan_test.c
> +++ b/kernel/kcsan/kcsan_test.c
> @@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
>                                 goto out;
>
>                         /* No second line of interest. */
> -                       strcpy(observed.lines[nlines++], "<none>");
> +                       strscpy(observed.lines[nlines++], "<none>");
>                 }
>         }
>
> @@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
>
>                         if (!r->access[1].fn) {
>                                 /* Dummy string if no second access is available. */
> -                               strcpy(cur, "<none>");
> +                               strscpy(expect[2], "<none>");
>                                 break;
>                         }
>                 }
> --
> 2.50.1
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20250815213742.321911-3-thorsten.blum%40linux.dev.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-19 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 21:37 [PATCH] kcsan: test: Replace deprecated strcpy() with strscpy() Thorsten Blum
2025-08-18 18:26 ` Justin Stitt
2025-08-18 19:32   ` Thorsten Blum
2025-08-19 19:00 ` Marco Elver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).