Skip to content

Commit

Permalink
s390/hmcdrv: Manual replacement of the deprecated strlcpy() with retu…
Browse files Browse the repository at this point in the history
…rn values

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>
  • Loading branch information
rperier authored and intel-lab-lkp committed Feb 22, 2021
1 parent 9b4448b commit df1bcb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions drivers/s390/char/diag_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ ssize_t diag_ftp_cmd(const struct hmcdrv_ftp_cmdspec *ftp, size_t *fsize)
goto out;
}

len = strlcpy(ldfpl->fident, ftp->fname, sizeof(ldfpl->fident));
if (len >= HMCDRV_FTP_FIDENT_MAX) {
len = strscpy(ldfpl->fident, ftp->fname, sizeof(ldfpl->fident));
if (len == -E2BIG) {
len = -EINVAL;
goto out_free;
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/s390/char/sclp_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static int sclp_ftp_et7(const struct hmcdrv_ftp_cmdspec *ftp)
struct completion completion;
struct sclp_diag_sccb *sccb;
struct sclp_req *req;
size_t len;
ssize_t len;
int rc;

req = kzalloc(sizeof(*req), GFP_KERNEL);
Expand All @@ -114,9 +114,9 @@ static int sclp_ftp_et7(const struct hmcdrv_ftp_cmdspec *ftp)
sccb->evbuf.mdd.ftp.length = ftp->len;
sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);

len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
len = strscpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
HMCDRV_FTP_FIDENT_MAX);
if (len >= HMCDRV_FTP_FIDENT_MAX) {
if (len == -E2BIG) {
rc = -EINVAL;
goto out_free;
}
Expand Down

0 comments on commit df1bcb6

Please sign in to comment.