Message ID | 20210222151231.22572-8-romain.perier@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Manual replacement of all strlcpy in favor of strscpy | expand |
> On Feb 22, 2021, at 10:12 AM, Romain Perier <romain.perier@gmail.com> wrote: > > The strlcpy() reads the entire source buffer first, it is dangerous if > the source buffer lenght is unbounded or possibility non NULL-terminated. > It can lead to linear read overflows, crashes, etc... > > As recommended in the deprecated interfaces [1], it should be replaced > by strscpy. > > This commit replaces all calls to strlcpy that handle the return values > by the corresponding strscpy calls with new handling of the return > values (as it is quite different between the two functions). > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > > Signed-off-by: Romain Perier <romain.perier@gmail.com> Hi Romain- I assume you are waiting for a maintainer's Ack? IMHO Trond or Anna should provide it for changes to this particular source file. > --- > net/sunrpc/clnt.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c > index 612f0a641f4c..3c5c4ad8a808 100644 > --- a/net/sunrpc/clnt.c > +++ b/net/sunrpc/clnt.c > @@ -282,7 +282,7 @@ static struct rpc_xprt *rpc_clnt_set_transport(struct rpc_clnt *clnt, > > static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename) > { > - clnt->cl_nodelen = strlcpy(clnt->cl_nodename, > + clnt->cl_nodelen = strscpy(clnt->cl_nodename, > nodename, sizeof(clnt->cl_nodename)); > } > > @@ -422,6 +422,10 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, > nodename = utsname()->nodename; > /* save the nodename */ > rpc_clnt_set_nodename(clnt, nodename); > + if (clnt->cl_nodelen == -E2BIG) { > + err = -ENOMEM; > + goto out_no_path; > + } > > err = rpc_client_register(clnt, args->authflavor, args->client_name); > if (err) > -- Chuck Lever
Hey, Yeah, but I think it can wait for v2, I am preparing a v2 series with a better explanation in the commit message and few improvements. Thanks, Romain Le lun. 1 mars 2021 à 19:25, Chuck Lever <chuck.lever@oracle.com> a écrit : > > > > On Feb 22, 2021, at 10:12 AM, Romain Perier <romain.perier@gmail.com> > wrote: > > > > The strlcpy() reads the entire source buffer first, it is dangerous if > > the source buffer lenght is unbounded or possibility non NULL-terminated. > > It can lead to linear read overflows, crashes, etc... > > > > As recommended in the deprecated interfaces [1], it should be replaced > > by strscpy. > > > > This commit replaces all calls to strlcpy that handle the return values > > by the corresponding strscpy calls with new handling of the return > > values (as it is quite different between the two functions). > > > > [1] > https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy > > > > Signed-off-by: Romain Perier <romain.perier@gmail.com> > > Hi Romain- > > I assume you are waiting for a maintainer's Ack? IMHO Trond or Anna > should provide it for changes to this particular source file. > > > > --- > > net/sunrpc/clnt.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c > > index 612f0a641f4c..3c5c4ad8a808 100644 > > --- a/net/sunrpc/clnt.c > > +++ b/net/sunrpc/clnt.c > > @@ -282,7 +282,7 @@ static struct rpc_xprt > *rpc_clnt_set_transport(struct rpc_clnt *clnt, > > > > static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char > *nodename) > > { > > - clnt->cl_nodelen = strlcpy(clnt->cl_nodename, > > + clnt->cl_nodelen = strscpy(clnt->cl_nodename, > > nodename, sizeof(clnt->cl_nodename)); > > } > > > > @@ -422,6 +422,10 @@ static struct rpc_clnt * rpc_new_client(const > struct rpc_create_args *args, > > nodename = utsname()->nodename; > > /* save the nodename */ > > rpc_clnt_set_nodename(clnt, nodename); > > + if (clnt->cl_nodelen == -E2BIG) { > > + err = -ENOMEM; > > + goto out_no_path; > > + } > > > > err = rpc_client_register(clnt, args->authflavor, > args->client_name); > > if (err) > > > > -- > Chuck Lever > > > >
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 612f0a641f4c..3c5c4ad8a808 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -282,7 +282,7 @@ static struct rpc_xprt *rpc_clnt_set_transport(struct rpc_clnt *clnt, static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename) { - clnt->cl_nodelen = strlcpy(clnt->cl_nodename, + clnt->cl_nodelen = strscpy(clnt->cl_nodename, nodename, sizeof(clnt->cl_nodename)); } @@ -422,6 +422,10 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, nodename = utsname()->nodename; /* save the nodename */ rpc_clnt_set_nodename(clnt, nodename); + if (clnt->cl_nodelen == -E2BIG) { + err = -ENOMEM; + goto out_no_path; + } err = rpc_client_register(clnt, args->authflavor, args->client_name); if (err)
The strlcpy() reads the entire source buffer first, it is dangerous if the source buffer lenght is unbounded or possibility non NULL-terminated. It can lead to linear read overflows, crashes, etc... As recommended in the deprecated interfaces [1], it should be replaced by strscpy. This commit replaces all calls to strlcpy that handle the return values by the corresponding strscpy calls with new handling of the return values (as it is quite different between the two functions). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy Signed-off-by: Romain Perier <romain.perier@gmail.com> --- net/sunrpc/clnt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)