Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2029798ybl; Thu, 19 Dec 2019 07:00:09 -0800 (PST) X-Google-Smtp-Source: APXvYqx9VBCG6L9QGmP4iSs6KFnjvvxg06MVgUtrUiyw35bmIFOTKvFKHWa4/Yve33UTsM5pYbyd X-Received: by 2002:a9d:3425:: with SMTP id v34mr8896935otb.142.1576767609395; Thu, 19 Dec 2019 07:00:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576767609; cv=none; d=google.com; s=arc-20160816; b=pg06NcBUMCtBXmUvHutUPyvPAWe5ziETlzk9S90YE4zOUcea66tJOQ/vqdNBmYR7d6 Ai5Z21K5Y5HfoP/xLLQucO8L3AybZMWLIIm5IB/FawGiPR4//5dzbxXdUDAFWM2tD22A RWRCOHbP/pTiGETakxrRuAZBeT8hLvAgTRwTqcf1XJUvZmNx2qgAGAzD/8iuc3XEooLF wPmAC1syvoIv4WNpRlgLlT4y2KyLwAeKarCZ1W4peHDBEnrAF6zyCnPOCPO/DoT32KA3 6XDcvipy61H/ubzj/I36VsxSNKVweGdnVOL5s3VqzC8ybLR5S/gg0D997e7x7rsIkI9K 71bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=d1bqiGjtD7vGe+8mOC+Trksp96KVnU1v0dtDWNKVC7w=; b=QKXyT6iBoQ4q/ooB1tIjPul2OJL3Bi2JCsM5YTna1jga9HoaEWUC2vjrttiMpN1H8U wlzRFOC4ShIH3xDN5TiCpxscG4RUZNYnieYdSq+4bsrqK7pPsU/dAvvlfIfj9AJBb9du ILPHOnIHDOhVyZSFVHZ1I3Uw0CkHHwPpZ3WhEhJ49makvLVORukLRH6HyHdvPERenTsg gp/884jIqrHASrI1P50PNC3ql/1xDnxLNy2TEM1YoWzErwj2sJNv1hExHpdOzrKULpEB 1FPfZHXg9iZg0oywKq6KZRiRviAzAMCfOd6Pm9msQ2A1YkVjpUD/oSrOG1StPgQ0MCSE hvbw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si2732644oil.77.2019.12.19.06.59.56; Thu, 19 Dec 2019 07:00:09 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726817AbfLSO5y (ORCPT + 99 others); Thu, 19 Dec 2019 09:57:54 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:44591 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726701AbfLSO5y (ORCPT ); Thu, 19 Dec 2019 09:57:54 -0500 Received: by mail-lj1-f196.google.com with SMTP id u71so6557656lje.11 for ; Thu, 19 Dec 2019 06:57:53 -0800 (PST) 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-transfer-encoding; bh=d1bqiGjtD7vGe+8mOC+Trksp96KVnU1v0dtDWNKVC7w=; b=Y7VuAX4I/2cCNT1nhDnPEI1JBJgSKLe7Gt1xiYZ8cRpf8HxQhm1xRpomaKVgHb2Nqf HOWWMy9IU+YT5gcl3EiPVu5GUTqX1pAdlzNZMUxNbFjkBpXcVFdIAVi/X77YDmdk5EwW WFBOiIFKLztLtAfYSWwoqyan9FnFsMMecfu4Zg2K4yJ8cAOi6M5Ye7plXeacJLlWyuO/ qxeUpldQglM87VtOKi81/kI6jW0Bffpu8xlg+WzsstgI73HCLwc7qRvaGeeKstV6JmZM 0YmJF5cV0cRH0dLDaeBrzt3EoKPDz9BB08uj2+JTn9oVQYV77S5/pkpmYm37PDYX2xoT Ji/Q== X-Gm-Message-State: APjAAAUdr4YCF9RyS7DQAENwsQHyRJIDCS/+HJ3foRZq7IfieziwbbGq 4FYjzcF6JuL9ezBC/OaNhog= X-Received: by 2002:a2e:9587:: with SMTP id w7mr6037911ljh.42.1576767472374; Thu, 19 Dec 2019 06:57:52 -0800 (PST) Received: from localhost.localdomain ([213.87.152.106]) by smtp.gmail.com with ESMTPSA id y23sm3054591ljk.6.2019.12.19.06.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 06:57:51 -0800 (PST) From: Alexander Popov To: Kees Cook , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: notify@kernel.org Subject: [PATCH v1 1/1] lkdtm/stackleak: Make the stack erasing test more verbose Date: Thu, 19 Dec 2019 17:54:16 +0300 Message-Id: <20191219145416.435508-1-alex.popov@linux.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make the stack erasing test more verbose about the errors that it can detect. BUG() in case of test failure is useful when the test is running in a loop. Signed-off-by: Alexander Popov --- drivers/misc/lkdtm/stackleak.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/misc/lkdtm/stackleak.c b/drivers/misc/lkdtm/stackleak.c index d5a084475abc..d198de4d4c7e 100644 --- a/drivers/misc/lkdtm/stackleak.c +++ b/drivers/misc/lkdtm/stackleak.c @@ -16,6 +16,7 @@ void lkdtm_STACKLEAK_ERASING(void) unsigned long *sp, left, found, i; const unsigned long check_depth = STACKLEAK_SEARCH_DEPTH / sizeof(unsigned long); + bool test_failed = false; /* * For the details about the alignment of the poison values, see @@ -34,7 +35,8 @@ void lkdtm_STACKLEAK_ERASING(void) left--; } else { pr_err("FAIL: not enough stack space for the test\n"); - return; + test_failed = true; + goto end; } pr_info("checking unused part of the thread stack (%lu bytes)...\n", @@ -52,22 +54,29 @@ void lkdtm_STACKLEAK_ERASING(void) } if (found <= check_depth) { - pr_err("FAIL: thread stack is not erased (checked %lu bytes)\n", + pr_err("FAIL: the erased part is not found (checked %lu bytes)\n", i * sizeof(unsigned long)); - return; + test_failed = true; + goto end; } - pr_info("first %lu bytes are unpoisoned\n", + pr_info("the erased part begins after %lu not poisoned bytes\n", (i - found) * sizeof(unsigned long)); /* The rest of thread stack should be erased */ for (; i < left; i++) { if (*(sp - i) != STACKLEAK_POISON) { - pr_err("FAIL: thread stack is NOT properly erased\n"); - return; + pr_err("FAIL: bad value number %lu in the erased part: 0x%lx\n", + i, *(sp - i)); + test_failed = true; } } - pr_info("OK: the rest of the thread stack is properly erased\n"); - return; +end: + if (test_failed) { + pr_err("FAIL: the thread stack is NOT properly erased\n"); + BUG(); + } else { + pr_info("OK: the rest of the thread stack is properly erased\n"); + } } -- 2.23.0