Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1636779 > unrolled thread

[PATCH] scsi: qedf: Avoid reading past end of buffer

Started byKees Cook <keescook@chromium.org>
First post2017-05-06 00:50 +0200
Last post2017-05-09 04:10 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] scsi: qedf: Avoid reading past end of buffer Kees Cook <keescook@chromium.org> - 2017-05-06 00:50 +0200
    Re: [PATCH] scsi: qedf: Avoid reading past end of buffer Bart Van Assche <Bart.VanAssche@sandisk.com> - 2017-05-06 01:10 +0200
      Re: [PATCH] scsi: qedf: Avoid reading past end of buffer Kees Cook <keescook@chromium.org> - 2017-05-06 01:20 +0200
    Re: [PATCH] scsi: qedf: Avoid reading past end of buffer "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-05-09 04:10 +0200

#1636779 — [PATCH] scsi: qedf: Avoid reading past end of buffer

FromKees Cook <keescook@chromium.org>
Date2017-05-06 00:50 +0200
Subject[PATCH] scsi: qedf: Avoid reading past end of buffer
Message-ID<tDUcV-80b-7@gated-at.bofh.it>
Using memcpy() from a string that is shorter than the length copied means
the destination buffer is being filled with arbitrary data from the kernel
rodata segment. Instead, use strncpy() which will fill the trailing bytes
with zeros.

This was found with the future CONFIG_FORTIFY_SOURCE feature.

Cc: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/scsi/qedf/qedf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index cceddd995a4b..a5c97342fd5d 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2895,7 +2895,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)
 	slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER;
 	slowpath_params.drv_rev = QEDF_DRIVER_REV_VER;
 	slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER;
-	memcpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
+	strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
 	rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params);
 	if (rc) {
 		QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");
-- 
2.7.4


-- 
Kees Cook
Pixel Security

[toc] | [next] | [standalone]


#1636783

FromBart Van Assche <Bart.VanAssche@sandisk.com>
Date2017-05-06 01:10 +0200
Message-ID<tDUwh-8nd-5@gated-at.bofh.it>
In reply to#1636779
On Fri, 2017-05-05 at 15:42 -0700, Kees Cook wrote:
> diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
> index cceddd995a4b..a5c97342fd5d 100644
> --- a/drivers/scsi/qedf/qedf_main.c
> +++ b/drivers/scsi/qedf/qedf_main.c
> @@ -2895,7 +2895,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)
>  	slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER;
>  	slowpath_params.drv_rev = QEDF_DRIVER_REV_VER;
>  	slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER;
> -	memcpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
> +	strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
>  	rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params);
>  	if (rc) {
>  		QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");

Hello Kees,

Although this patch looks fine to me, isn't strlcpy() preferred over strncpy()?

Bart.

[toc] | [prev] | [next] | [standalone]


#1636785

FromKees Cook <keescook@chromium.org>
Date2017-05-06 01:20 +0200
Message-ID<tDUFX-8qC-3@gated-at.bofh.it>
In reply to#1636783
On Fri, May 5, 2017 at 4:01 PM, Bart Van Assche
<Bart.VanAssche@sandisk.com> wrote:
> On Fri, 2017-05-05 at 15:42 -0700, Kees Cook wrote:
>> diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
>> index cceddd995a4b..a5c97342fd5d 100644
>> --- a/drivers/scsi/qedf/qedf_main.c
>> +++ b/drivers/scsi/qedf/qedf_main.c
>> @@ -2895,7 +2895,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)
>>       slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER;
>>       slowpath_params.drv_rev = QEDF_DRIVER_REV_VER;
>>       slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER;
>> -     memcpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
>> +     strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
>>       rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params);
>>       if (rc) {
>>               QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");
>
> Hello Kees,
>
> Although this patch looks fine to me, isn't strlcpy() preferred over strncpy()?

strlcpy doesn't zero-pad, so I think strncpy is preferred here,
otherwise we may risk leaving portions of the destination buffer
filled with uninitialized data, maybe leaking kernel memory contents.

-Kees

-- 
Kees Cook
Pixel Security

[toc] | [prev] | [next] | [standalone]


#1637826

From"Martin K. Petersen" <martin.petersen@oracle.com>
Date2017-05-09 04:10 +0200
Message-ID<tF2L8-3JE-1@gated-at.bofh.it>
In reply to#1636779
Kees,

> Using memcpy() from a string that is shorter than the length copied
> means the destination buffer is being filled with arbitrary data from
> the kernel rodata segment. Instead, use strncpy() which will fill the
> trailing bytes with zeros.

Applied to 4.12/scsi-fixes, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web