Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -Wstringop-overflow warning in drivers/scsi/lpfc/lpfc_debugfs.c #305

Closed
GustavoARSilva opened this issue May 30, 2023 · 1 comment
Closed
Assignees
Labels
-Wstringop-overflow Emits warnings under -Wstringop-overflow

Comments

@GustavoARSilva
Copy link
Collaborator

In functionlpfc_debugfs_ras_log_data’,
    inlined fromlpfc_debugfs_ras_log_openat drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpyspecified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2210 |                         memcpy(buffer + copied, dmabuf->virt,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2211 |                                size - copied - 1);
      |                                ~~~~~~~~~~~~~~~~~~
```c
@GustavoARSilva GustavoARSilva added the [Feature] FORTIFY_SOURCE Involves buffer overflow detection label May 30, 2023
@GustavoARSilva GustavoARSilva self-assigned this May 30, 2023
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue May 30, 2023
Avoid confusing the compiler about possible negative sizes.
Use size_t instead of int for variables size and copied.

Address the following warning found with GCC-13:
In function ‘lpfc_debugfs_ras_log_data’,
    inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2210 |                         memcpy(buffer + copied, dmabuf->virt,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2211 |                                size - copied - 1);
      |                                ~~~~~~~~~~~~~~~~~~

Link: KSPP#305
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
@GustavoARSilva GustavoARSilva removed the [Feature] FORTIFY_SOURCE Involves buffer overflow detection label May 30, 2023
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Jun 1, 2023
Avoid confusing the compiler about possible negative sizes.
Use size_t instead of int for variables size and copied.

Address the following warning found with GCC-13:
In function ‘lpfc_debugfs_ras_log_data’,
    inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2210 |                         memcpy(buffer + copied, dmabuf->virt,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2211 |                                size - copied - 1);
      |                                ~~~~~~~~~~~~~~~~~~

Link: KSPP#305
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Jun 1, 2023
Prevent any potential integer wrapping issue, and avoid a
-Wstringop-overflow warning by using the check_mul_overflow() helper.

drivers/scsi/lpfc/lpfc.h:
837:#define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024)

drivers/scsi/lpfc/lpfc_debugfs.c:
2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;

this can wrap to negative if cfg_ras_fwlog_buffsize is large
enough. And even when in practice this is not possible (due to
phba->cfg_ras_fwlog_buffsize never being larger than 4[1]), the
compiler is legitimately warning us about potentially buggy code.

Fix the following warning seen under GCC-13:
In function ‘lpfc_debugfs_ras_log_data’,
    inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2210 |                         memcpy(buffer + copied, dmabuf->virt,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2211 |                                size - copied - 1);
      |                                ~~~~~~~~~~~~~~~~~~

Link: KSPP#305
Link: https://lore.kernel.org/linux-hardening/CABPRKS8zyzrbsWt4B5fp7kMowAZFiMLKg5kW26uELpg1cDKY3A@mail.gmail.com/ [1]
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
akiyks pushed a commit to akiyks/linux that referenced this issue Jun 8, 2023
Prevent any potential integer wrapping issue, and avoid a
-Wstringop-overflow warning by using the check_mul_overflow() helper.

drivers/scsi/lpfc/lpfc.h:
837:#define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024)

drivers/scsi/lpfc/lpfc_debugfs.c:
2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;

this can wrap to negative if cfg_ras_fwlog_buffsize is large
enough. And even when in practice this is not possible (due to
phba->cfg_ras_fwlog_buffsize never being larger than 4[1]), the
compiler is legitimately warning us about potentially buggy code.

Fix the following warning seen under GCC-13:
In function ‘lpfc_debugfs_ras_log_data’,
    inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
 2210 |                         memcpy(buffer + copied, dmabuf->virt,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2211 |                                size - copied - 1);
      |                                ~~~~~~~~~~~~~~~~~~

Link: KSPP#305
Link: https://lore.kernel.org/linux-hardening/CABPRKS8zyzrbsWt4B5fp7kMowAZFiMLKg5kW26uELpg1cDKY3A@mail.gmail.com/ [1]
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/ZHkseX6TiFahvxJA@work
Reviewed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
@kees kees added the -Wstringop-overflow Emits warnings under -Wstringop-overflow label Jun 14, 2023
@GustavoARSilva
Copy link
Collaborator Author

fixed in commit a48e2c3

bella485 pushed a commit to bella485/centos-stream-9 that referenced this issue May 1, 2024
JIRA: https://issues.redhat.com/browse/RHEL-24508

commit a48e2c328c6505d356c90ef51a2052d1d27f9bef
Author: Gustavo A. R. Silva <gustavoars@kernel.org>
Date:   Thu Jun 1 17:40:41 2023 -0600

    scsi: lpfc: Avoid -Wstringop-overflow warning

    Prevent any potential integer wrapping issue, and avoid a
    -Wstringop-overflow warning by using the check_mul_overflow() helper.

    drivers/scsi/lpfc/lpfc.h:
    837:#define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024)

    drivers/scsi/lpfc/lpfc_debugfs.c:
    2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;

    this can wrap to negative if cfg_ras_fwlog_buffsize is large
    enough. And even when in practice this is not possible (due to
    phba->cfg_ras_fwlog_buffsize never being larger than 4[1]), the
    compiler is legitimately warning us about potentially buggy code.

    Fix the following warning seen under GCC-13:
    In function ‘lpfc_debugfs_ras_log_data’,
        inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
    drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
     2210 |                         memcpy(buffer + copied, dmabuf->virt,
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     2211 |                                size - copied - 1);
          |                                ~~~~~~~~~~~~~~~~~~

    Link: KSPP/linux#305
    Link: https://lore.kernel.org/linux-hardening/CABPRKS8zyzrbsWt4B5fp7kMowAZFiMLKg5kW26uELpg1cDKY3A@mail.gmail.com/ [1]
    Co-developed-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    Link: https://lore.kernel.org/r/ZHkseX6TiFahvxJA@work
    Reviewed-by: Justin Tee <justin.tee@broadcom.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Signed-off-by: Dick Kennedy <dkennedy@redhat.com>
bella485 pushed a commit to bella485/centos-stream-9 that referenced this issue May 1, 2024
JIRA: https://issues.redhat.com/browse/RHEL-24508
Added cast for compile warning.
commit a48e2c328c6505d356c90ef51a2052d1d27f9bef
Author: Gustavo A. R. Silva <gustavoars@kernel.org>
Date:   Thu Jun 1 17:40:41 2023 -0600

    scsi: lpfc: Avoid -Wstringop-overflow warning

    Prevent any potential integer wrapping issue, and avoid a
    -Wstringop-overflow warning by using the check_mul_overflow() helper.

    drivers/scsi/lpfc/lpfc.h:
    837:#define LPFC_RAS_MIN_BUFF_POST_SIZE (256 * 1024)

    drivers/scsi/lpfc/lpfc_debugfs.c:
    2266 size = LPFC_RAS_MIN_BUFF_POST_SIZE * phba->cfg_ras_fwlog_buffsize;

    this can wrap to negative if cfg_ras_fwlog_buffsize is large
    enough. And even when in practice this is not possible (due to
    phba->cfg_ras_fwlog_buffsize never being larger than 4[1]), the
    compiler is legitimately warning us about potentially buggy code.

    Fix the following warning seen under GCC-13:
    In function ‘lpfc_debugfs_ras_log_data’,
        inlined from ‘lpfc_debugfs_ras_log_open’ at drivers/scsi/lpfc/lpfc_debugfs.c:2271:15:
    drivers/scsi/lpfc/lpfc_debugfs.c:2210:25: warning: ‘memcpy’ specified bound between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
     2210 |                         memcpy(buffer + copied, dmabuf->virt,
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     2211 |                                size - copied - 1);
          |                                ~~~~~~~~~~~~~~~~~~

    Link: KSPP/linux#305
    Link: https://lore.kernel.org/linux-hardening/CABPRKS8zyzrbsWt4B5fp7kMowAZFiMLKg5kW26uELpg1cDKY3A@mail.gmail.com/ [1]
    Co-developed-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    Link: https://lore.kernel.org/r/ZHkseX6TiFahvxJA@work
    Reviewed-by: Justin Tee <justin.tee@broadcom.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Signed-off-by: Dick Kennedy <dkennedy@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Wstringop-overflow Emits warnings under -Wstringop-overflow
Projects
None yet
Development

No branches or pull requests

2 participants