Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17967021ybl; Thu, 2 Jan 2020 15:50:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwpoZ4icYl3GdsPlDa2JU7HhVFVIHFMor04+QEkhJ8uR+wx/0hDHFxgYSgilXfVezR15HUS X-Received: by 2002:a05:6830:22e6:: with SMTP id t6mr99445611otc.244.1578009034095; Thu, 02 Jan 2020 15:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578009034; cv=none; d=google.com; s=arc-20160816; b=pyhlzBpWDjemiB28toQ3Ie9F6ZLzvdUeuAPkyZNbieMsfQSwyc7XF4U6IH3MsDzhXN Tgr8VPembshXjKy7Oei+mhzKUTFfo9AXwFAPIhbB8lrNc5j99rgrEEMclaa2gPYsBoOl JA+QnnsfKDx64jnBUcAI7kIlNhX6yh8jJ/cbwToWhU6t8VGxx+jZ1Jp1XTZ8NRL5amk9 FHaWI9YkSYPlYrmNCBrPOVfMtQgnwfHg5zmgk2ao/MWQvxgjfG1+xnz6TouAFFjQTGcm MI0zohAZEioPYaCvR/sA2Nu9LBSkQhkbhtLaQfidWZ+ozyTejnrV8uOUj85OHnZclVLZ Otnw== 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=vKUFgkAq6av3fCpY/y8sfQAdG6utgB0okP85MRpDaZQ=; b=yI7Sal4/ib7WZ36awilUrQT4C2LlQuoRAKrqzPygrb0fEQNLqoflMI+P5N9nJRCTIF QqGkXEBqUL2eBm/1+zfyuIafQpOQD/p3HRYI4tjzTtKV6ht1UWi8AAIKluogxpMvEp0p SO6cTyWYzZKZDB3y5+eDdcQuy5hE4jWXbPAriOybiUA1EGUuZyOiPi3s2xH1nN3ii8Sk yVLpambcs8uCams0kLaZRQ2uV6pgexshMOHxIAPg+QRx9dSdtcpM0tRe81B6n/NblRNh Ps6+jAjsX4YGoNUkkskhiMhKaDz4LbfgpW0EEm/cA/qnHmmfZh8qqR1LjlVsB6qkuKEJ ib7Q== 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 l12si24981528oib.254.2020.01.02.15.50.21; Thu, 02 Jan 2020 15:50:34 -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 S1727308AbgABXtV (ORCPT + 99 others); Thu, 2 Jan 2020 18:49:21 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37690 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgABXtV (ORCPT ); Thu, 2 Jan 2020 18:49:21 -0500 Received: by mail-lj1-f194.google.com with SMTP id o13so30873403ljg.4 for ; Thu, 02 Jan 2020 15:49:20 -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=vKUFgkAq6av3fCpY/y8sfQAdG6utgB0okP85MRpDaZQ=; b=mNbOkpq105ThOruUsD3+uNqFoSf1FpBRQOk9u0iVBPKJtrPdcQg+fwlvU5sXDxb4WD 7U3brSbJnwreY6yaZ1DIkoFINwlbZobof+HQm52lfjFcW8No1WcOzSwE6aCsHvNSf+VS h1aohpmloWMfdUZPmlJ5jPh43Q2i8ub04soBywnzVxv3IXiIaYOnnFDaWvSbSxGwLVp2 nDHiWWzKDreD7zvghdcojhkX5eCo8v3t/Xxp0iOQDGA9z1xqDjMdF4Wfe9TdWThk0/Vn mQuuyHqnwClNwijfdfpO9sDZ9YUdu79u5Uz1UIWtToy+Kt99txEdxqFMC1A8oV7uf8vS +G0g== X-Gm-Message-State: APjAAAVGCMXP9i9fDJ3fjfP9aqa4DZbVhYiEoAmjQmjwhLtRnNw4kTfn yI3s3bSjzs1HrpD8uEyWwCg= X-Received: by 2002:a05:651c:282:: with SMTP id b2mr49076441ljo.41.1578008959467; Thu, 02 Jan 2020 15:49:19 -0800 (PST) Received: from localhost.localdomain ([213.87.155.29]) by smtp.gmail.com with ESMTPSA id d24sm23451015lja.82.2020.01.02.15.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2020 15:49:18 -0800 (PST) From: Alexander Popov To: Kees Cook , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Alexander Popov Cc: notify@kernel.org Subject: [PATCH v2 1/1] lkdtm/stackleak: Make the test more verbose Date: Fri, 3 Jan 2020 02:49:07 +0300 Message-Id: <20200102234907.585508-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. 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..d1a5c0705be3 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"); + dump_stack(); + } else { + pr_info("OK: the rest of the thread stack is properly erased\n"); + } } -- 2.23.0