Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp414717imm; Wed, 13 Jun 2018 02:30:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIjvSavozsEFLNtubW4gealpX0Yy/a53AF9OMHcgz/odadSljr5/kv8AJOEH5gQ6umq+RVR X-Received: by 2002:a62:e903:: with SMTP id j3-v6mr4149630pfh.228.1528882211519; Wed, 13 Jun 2018 02:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528882211; cv=none; d=google.com; s=arc-20160816; b=QRBqVFYYPLalT9ll6N0uXw6+ZC7iOsE8GeXb8f69oh8HZkKSgK6+YtRDxxmkmuRxRD U0iH5OpQemmaOLCuoKG2JTH2tXDyexZdNRLWH2QQ5W1CsGDRL2RYnPFwPVp+QjMyRTbk /MmbIE3u1qLZkcCVHZKnW+ORtAFBpHYzNLsyxo7rmdxKbe5zIZWSC4+DR45dVCaN+bHR A/Y7Ua6SdAWTSN3F3a15crs+WD5sqEm9/ChWfZaXKZg6CL9b9y1yHWJEZDtRUd2fBPMC z095TIeEvxe6prHSILGByvVUdJwU4fgwEjrZJG3qtyEsGKLi88ip70apJiVrVDjo0b43 5V1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfert-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=G+u3FEX3sVcxDQLvHTX1yrnc4HzdxVX9v3vb88Fav4Q=; b=eFHgTOBlpHGr3+EtumGs0qgFW00McTQUQdwhHWKJHicj7Zca2tD3FbUnhwNV8tClJ8 BtMIwTOFwwx8gIQWfNSvhNEdWTnPpN3Plsuil3+nZ8Ld2cJNuwzY2aBx7vdl9WGfOFHl xn0ZKDgCNf0ocXH0moX+uOk8HHT7wPpF+fWyjvgwPy0dJhQThnnQbQs+WBjtEgi/Jh72 ANuKP13DKBMTQxYG+A1H46q6dZ21u+S42uL9L+3ND7maLftCQkNxt51A+tssa3XZBN2i JPOeyPuNknJR08g0TuJgesrNORgBgDPwZx+YXISmXi8fRS57hK9UgLH/5yvTCikWUsBM kOgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ecOMwxPV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t194-v6si1928072pgc.327.2018.06.13.02.29.56; Wed, 13 Jun 2018 02:30:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ecOMwxPV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934640AbeFMJ3a (ORCPT + 99 others); Wed, 13 Jun 2018 05:29:30 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:34635 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933498AbeFMJ33 (ORCPT ); Wed, 13 Jun 2018 05:29:29 -0400 Received: by mail-wm0-f50.google.com with SMTP id l15-v6so17945299wmc.1 for ; Wed, 13 Jun 2018 02:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfert-encoding; bh=G+u3FEX3sVcxDQLvHTX1yrnc4HzdxVX9v3vb88Fav4Q=; b=ecOMwxPV/8v1UVE24c6MiN19qFKIAnAn7SUZdOglBH55EGQC9WKHTaU3zdxS3x1t8w o+ey25OPxUh2uC1Set7TE2JL2MVmLE8/ZcZs0LKtpfvOsK95eJkyi1pgpugb+ElpL4AQ M6N1W2vv+T6MeRqvHMh+QR+Qp42bkbhuUB8Ho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfert-encoding; bh=G+u3FEX3sVcxDQLvHTX1yrnc4HzdxVX9v3vb88Fav4Q=; b=Jb8LNEqDh67snuiK5aIRONo8e2XjEFjVn6ztp2zLLEFtLACxHoYzYxHaFRDC1p1KO+ 4kRFqB5U27qz9jWyYCax6ooJdu4hzEUbeFhTAtwUGHJLJdmfNc5ZQ8rHwWzpSaMJR9D8 KzhNpo6pnHdJ4NihS/BUxZCgiARQGWF9JaKoTN4bzeVHfUPOqFj/gr+pxJubBc0qdlmA c5IIiWE6IqLKwxLFMruayotjfymVq7HWs9xqsMmKGerinkOm+PVxFdQpreuqBwXucQZf XuYINnDQoTlh7xrP+/Bw8x5axS8TOqx9WmgqhKoJQWy47unD4G1viikCFND8onzEO5fq gCmA== X-Gm-Message-State: APt69E2LiH/a0SWKjk90AVpNj+ySkZ03rxsLyQoD5ADguKkiJAXrzFPU l9o6mM/5WDO2ayS2ZCz5gKLBjA== X-Received: by 2002:a1c:124f:: with SMTP id 76-v6mr3011270wms.29.1528882168120; Wed, 13 Jun 2018 02:29:28 -0700 (PDT) Received: from localhost.localdomain (aig34-1-88-167-228-121.fbx.proxad.net. [88.167.228.121]) by smtp.gmail.com with ESMTPSA id v2-v6sm1514392wmh.41.2018.06.13.02.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 02:29:27 -0700 (PDT) From: Thierry Escande To: Andrew Morton , David Miller , Andy Shevchenko , Petr Mladek Cc: Rasmus Villemoes , "Tobin C . Harding" , linux-kernel@vger.kernel.org Subject: [PATCH v2] lib/test_printf.c: call wait_for_random_bytes() before plain %p tests Date: Wed, 13 Jun 2018 11:29:19 +0200 Message-Id: <20180613092919.24075-1-thierry.escande@linaro.org> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset = "utf-8" Content-Transfert-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the test_printf module is loaded before the crng is initialized, the plain 'p' tests will fail because the printed address will not be hashed and the buffer will contain "(ptrval)" instead. Since we cannot wait for the crng to be initialized for an undefined time, both plain 'p' tests now accept the string "(ptrval)" as a valid result and print a warning message. Signed-off-by: Thierry Escande --- Change in v2: - Remove wait_for_random_bytes() usage - Removed Acked-by from Tobin as the proposed solution is not the same anymore. lib/test_printf.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/test_printf.c b/lib/test_printf.c index 71ebfa43ad05..a625e3749566 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -206,6 +206,7 @@ test_string(void) #define PTR_WIDTH 16 #define PTR ((void *)0xffff0123456789ab) #define PTR_STR "ffff0123456789ab" +#define PTR_VAL_NO_CRNG " (ptrval)" #define ZEROS "00000000" /* hex 32 zero bits */ static int __init @@ -216,7 +217,16 @@ plain_format(void) nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR); - if (nchars != PTR_WIDTH || strncmp(buf, ZEROS, strlen(ZEROS)) != 0) + if (nchars != PTR_WIDTH) + return -1; + + if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) { + pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"", + PTR_VAL_NO_CRNG); + return 0; + } + + if (strncmp(buf, ZEROS, strlen(ZEROS)) != 0) return -1; return 0; @@ -227,6 +237,7 @@ plain_format(void) #define PTR_WIDTH 8 #define PTR ((void *)0x456789ab) #define PTR_STR "456789ab" +#define PTR_VAL_NO_CRNG "(ptrval)" static int __init plain_format(void) @@ -245,7 +256,16 @@ plain_hash(void) nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR); - if (nchars != PTR_WIDTH || strncmp(buf, PTR_STR, PTR_WIDTH) == 0) + if (nchars != PTR_WIDTH) + return -1; + + if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) { + pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"", + PTR_VAL_NO_CRNG); + return 0; + } + + if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0) return -1; return 0; -- 2.14.1