From patchwork Mon Feb 27 15:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 65690 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26B2C3858416 for ; Mon, 27 Feb 2023 15:38:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26B2C3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677512282; bh=PuB/iODYr+2hS/fvKd0upoIBxQA70zrpjKIlLfsOOYY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WFtIm1GjedpL2ZpH1MqwuADefhpM9N4IPSouB+VghH/7QGb+x7MWpNubxV2QA1Wds UUWoy+lz+SvB/5ntn8XnFQABrV/h0z57wKv1FdLHV5G0kIA6OoK8CL2fBOcuGPimUf aNktZXmvThQ3BQVF2MApyDTEDyU1bn+AuuWDcAeA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id 506DD3858D32 for ; Mon, 27 Feb 2023 15:37:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 506DD3858D32 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-17264e9b575so7745240fac.9 for ; Mon, 27 Feb 2023 07:37:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677512258; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PuB/iODYr+2hS/fvKd0upoIBxQA70zrpjKIlLfsOOYY=; b=kNdWhZK3c/sEeZdnOk511WyVjE1k5gJIhmObwTtIah1MIcRbABMElRC2uGMzd2oHnr uqa4ETe0vRfTRjLb6tHArAXnyNAnlA4FkOBgjr2ewSGGsc1wZt+tUQhTwqxJaCaPWbIx pHbpL+ulozImLgqEuQLQYJrlrx5zB+zDZJ6rslwxWvlrewkL+ScQTZ0+p8cuQfEhP6yg sD2Oh5FTX0lXsxbV73zGpg1CtoBvfEYQDwmXTSFvIRfvx/M7BfaT4+VPp5ZOtRTTHRzV pJpQbl2iOOsUwojkVeoMq9F0S9F2H0O+jPrBuELzKwWmrsfU0xp8xH6JlRsZFUmRZCql NTSQ== X-Gm-Message-State: AO0yUKVV3Iqpx/S80GyxOfdpSwjouEHaOI7gTdcjdTjul7pjsYdAWCqH B3p9c7X6QPD/RdhHIFeL0ONxhCLqCorQVAafTYw= X-Google-Smtp-Source: AK7set/XgSRL9wOKoTqU5mFfR1LnqgyRAwN4moA8VFBVtBFoYy60pI3RR5Ainyx9f+hM+RccM/ewtA== X-Received: by 2002:a05:6870:6123:b0:172:79f0:e81d with SMTP id s35-20020a056870612300b0017279f0e81dmr4956241oae.8.1677512257714; Mon, 27 Feb 2023 07:37:37 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:4306:c797:b634:35c2]) by smtp.gmail.com with ESMTPSA id 26-20020a056870111a00b0017243edbe5bsm2333424oaf.58.2023.02.27.07.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 07:37:36 -0800 (PST) To: libc-alpha@sourceware.org, Wilco Dijkstra , Szabolcs Nagy , Florian Weimer Subject: [PATCH v2] crypt: Remove invalid end of page test badsalttest Date: Mon, 27 Feb 2023 12:37:32 -0300 Message-Id: <20230227153732.123634-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The input argument passes an invalid string without a NUL terminator on crypt settings inputs, which might lead to invalid OOB on strncmp. Implementations only assume there is a NUL terminator if the string is shorter than the specified size, so strings don't need to always be NUL terminated (stratcliff.c has tests for this). Also adapt the code to use libsupport. Checked on arm-linux-gnuabihf. Reviewed-by: Szabolcs Nagy --- crypt/badsalttest.c | 52 ++++++++------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/crypt/badsalttest.c b/crypt/badsalttest.c index bc1e5c1442..b8239a695b 100644 --- a/crypt/badsalttest.c +++ b/crypt/badsalttest.c @@ -16,11 +16,12 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include +#include +#include #include +#include + static const char *tests[][2] = { { "no salt", "" }, @@ -30,59 +31,24 @@ static const char *tests[][2] = { "both chars bad", ":@" }, { "un$upported algorithm", "$2$" }, { "unsupported_algorithm", "_1" }, - { "end of page", NULL } }; static int do_test (void) { - int result = 0; struct crypt_data cd; - size_t n = sizeof (tests) / sizeof (*tests); - size_t pagesize = (size_t) sysconf (_SC_PAGESIZE); - char *page; - - /* Check that crypt won't look at the second character if the first - one is invalid. */ - page = mmap (NULL, pagesize * 2, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, -1, 0); - if (page == MAP_FAILED) - { - perror ("mmap"); - n--; - } - else - { - if (mmap (page + pagesize, pagesize, 0, - MAP_PRIVATE | MAP_ANON | MAP_FIXED, - -1, 0) != page + pagesize) - perror ("mmap 2"); - page[pagesize - 1] = '*'; - tests[n - 1][1] = &page[pagesize - 1]; - } /* Mark cd as initialized before first call to crypt_r. */ cd.initialized = 0; - for (size_t i = 0; i < n; i++) + for (size_t i = 0; i < array_length (tests); i++) { - if (crypt (tests[i][0], tests[i][1])) - { - result++; - printf ("%s: crypt returned non-NULL with salt \"%s\"\n", - tests[i][0], tests[i][1]); - } + TEST_VERIFY (crypt (tests[i][0], tests[i][1]) == NULL); - if (crypt_r (tests[i][0], tests[i][1], &cd)) - { - result++; - printf ("%s: crypt_r returned non-NULL with salt \"%s\"\n", - tests[i][0], tests[i][1]); - } + TEST_VERIFY (crypt_r (tests[i][0], tests[i][1], &cd) == NULL); } - return result; + return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include