Commit Graph

2 Commits

Author SHA1 Message Date
Ivan Vecera 5de487609e fortify: Short-circuit known-safe calls to strscpy()
JIRA: https://issues.redhat.com/browse/RHEL-40250

commit 62e1cbfc5d795381a0f237ae7ee229a92d51cf9e
Author: Kees Cook <keescook@chromium.org>
Date:   Sun Oct 2 09:17:03 2022 -0700

    fortify: Short-circuit known-safe calls to strscpy()

    Replacing compile-time safe calls of strcpy()-related functions with
    strscpy() was always calling the full strscpy() logic when a builtin
    would be better. For example:

            char buf[16];
            strcpy(buf, "yes");

    would reduce to __builtin_memcpy(buf, "yes", 4), but not if it was:

            strscpy(buf, yes, sizeof(buf));

    Fix this by checking if all sizes are known at compile-time.

    Cc: linux-hardening@vger.kernel.org
    Tested-by: Nathan Chancellor <nathan@kernel.org>
    Signed-off-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
2024-06-10 19:14:58 +02:00
Nico Pache 2d2dee5670 string: Convert strscpy() self-test to KUnit
Conflicts:
       lib/Kconfig.debug unexpected neighboring config

commit 41eefc46a3a4682976afb5f8c4b9734ed6bfd406
Author: Kees Cook <keescook@chromium.org>
Date:   Sun Oct 2 09:51:46 2022 -0700

    string: Convert strscpy() self-test to KUnit

    Convert the strscpy() self-test to a KUnit test.

    Cc: David Gow <davidgow@google.com>
    Cc: Tobin C. Harding <tobin@kernel.org>
    Tested-by: Nathan Chancellor <nathan@kernel.org>
    Link: https://lore.kernel.org/lkml/Y072ZMk/hNkfwqMv@dev-arch.thelio-3990X
    Signed-off-by: Kees Cook <keescook@chromium.org>

JIRA: https://issues.redhat.com/browse/RHEL-5618
Signed-off-by: Nico Pache <npache@redhat.com>
2023-11-02 15:26:54 -06:00