linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: clkdev: Replace strlcpy with strscpy
@ 2019-11-15 10:17 Peng Fan
  2019-11-15 17:00 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Fan @ 2019-11-15 10:17 UTC (permalink / raw)
  To: sboyd, linux
  Cc: dl-linux-imx, linux-clk, linux-arm-kernel, linux-kernel,
	Alice Guo, Peng Fan, Kees Cook

From: Peng Fan <peng.fan@nxp.com>

The implementation of strscpy() is more robust and safer.

The strscpy was introduced to fix some API problems around strlcpy.
strscpy is preferred to strlcpy() since the API doesn't require
reading memory from the src string beyond the specified "count" bytes,
and since the return value is easier to error-check than strlcpy()'s.
In addition, the implementation is robust to the string changing out
from underneath it, unlike the current strlcpy() implementation.

Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/clkdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 0f2e3fcf0f19..ee56109bc0b4 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -165,7 +165,7 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
 
 	cla->cl.clk_hw = hw;
 	if (con_id) {
-		strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
+		strscpy(cla->con_id, con_id, sizeof(cla->con_id));
 		cla->cl.con_id = cla->con_id;
 	}
 
-- 
2.16.4


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

* Re: [PATCH] clk: clkdev: Replace strlcpy with strscpy
  2019-11-15 10:17 [PATCH] clk: clkdev: Replace strlcpy with strscpy Peng Fan
@ 2019-11-15 17:00 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2019-11-15 17:00 UTC (permalink / raw)
  To: Peng Fan
  Cc: sboyd, linux, dl-linux-imx, linux-clk, linux-arm-kernel,
	linux-kernel, Alice Guo

On Fri, Nov 15, 2019 at 10:17:53AM +0000, Peng Fan wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> The implementation of strscpy() is more robust and safer.
> 
> The strscpy was introduced to fix some API problems around strlcpy.
> strscpy is preferred to strlcpy() since the API doesn't require
> reading memory from the src string beyond the specified "count" bytes,
> and since the return value is easier to error-check than strlcpy()'s.
> In addition, the implementation is robust to the string changing out
> from underneath it, unlike the current strlcpy() implementation.
> 
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  drivers/clk/clkdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index 0f2e3fcf0f19..ee56109bc0b4 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
> @@ -165,7 +165,7 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
>  
>  	cla->cl.clk_hw = hw;
>  	if (con_id) {
> -		strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
> +		strscpy(cla->con_id, con_id, sizeof(cla->con_id));
>  		cla->cl.con_id = cla->con_id;
>  	}
>  
> -- 
> 2.16.4
> 

-- 
Kees Cook

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

end of thread, other threads:[~2019-11-15 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-15 10:17 [PATCH] clk: clkdev: Replace strlcpy with strscpy Peng Fan
2019-11-15 17:00 ` Kees Cook

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).