Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4780806ioa; Wed, 27 Apr 2022 10:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLOZsmSp8zlQ3CSEzSlpcCHzut9xeLplpF/XEByYFxIboiMSou8XPPvJi+4nOIr3gBloKa X-Received: by 2002:a17:90b:110a:b0:1d2:bde4:e277 with SMTP id gi10-20020a17090b110a00b001d2bde4e277mr33721505pjb.188.1651082308360; Wed, 27 Apr 2022 10:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651082308; cv=none; d=google.com; s=arc-20160816; b=ctz6b/aFGXlZ20Wf4mv504P8GzW9KjWyN3lDT1YjS3SF8THOPnlsxsoY++x7Ro+b50 Lchq4YBD56o+vV2MB/mgLabr3syfvKospYDKqBF4Do3hosDRucqPeRExeM8F19NDJ4Cc vP+UKzslbCxTrE+hsJyFoAqemKXC4rrl+mgeb+h1/1PpX4BsD1EzWw49lltiCLGkthBK rtQmCuAlyHdn962kqHVIuDUg49o+cMCFIw0A3vqG9NXN7RmOTZ256Ck5TomQgg+YoX6p OS20/npK2yZ7nAcs7ULPf76qjt+fZkUWImLss0Uk4ByWGUPBat/YuYgyk2PST3ziP0QO lc7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xkKyNyc7pPSTnxGoYhdXY1dgCqT2jkO2u+swooejPZs=; b=z8Ugb4VOoJtFKMp2l1DcS8CFdbjrwz5GRvpxR37ye093f8NTVMTclRtz1kFlfekh6z 5IplRyE+q/HgjVFvJF2hydFTP35c+pBzv88EwUU0CQmS2k78HOdF6cN9SOF4/CDZG9j7 wSWFhP6og+phjh+qqex+6UDKVNAdctAUo1/ZCne0O0mVZRqw7YVn1280885o/vEpdLyk u9z6Cec+g8kidFODOIrP9LoRkSy/l3QozP6W7h4vXdJZuBFXF67Ufyi0/kFPGcE9v7uW c8YOHcjUcnpt56NZYZFurstB86D3NB8+cap0efuCFYCE+h8Uq5QeM0Ccqx0ZY2vMVLQV UQqw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b10-20020a056a000a8a00b004fa3a8dff5dsi2270817pfl.20.2022.04.27.10.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 10:58:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2FEE625C67E; Wed, 27 Apr 2022 10:32:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244340AbiD0RfX (ORCPT + 99 others); Wed, 27 Apr 2022 13:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244246AbiD0Re7 (ORCPT ); Wed, 27 Apr 2022 13:34:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 08FD51FC0D5 for ; Wed, 27 Apr 2022 10:31:45 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDAF7143D; Wed, 27 Apr 2022 10:31:44 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 89A483F73B; Wed, 27 Apr 2022 10:31:43 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akpm@linux-foundation.org, alex.popov@linux.com, catalin.marinas@arm.com, keescook@chromium.org, linux-kernel@vger.kernel.org, luto@kernel.org, mark.rutland@arm.com, will@kernel.org Subject: [PATCH v2 05/13] stackleak: clarify variable names Date: Wed, 27 Apr 2022 18:31:20 +0100 Message-Id: <20220427173128.2603085-6-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220427173128.2603085-1-mark.rutland@arm.com> References: <20220427173128.2603085-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The logic within __stackleak_erase() can be a little hard to follow, as `boundary` switches from being the low bound to the high bound mid way through the function, and `kstack_ptr` is used to represent the start of the region to erase while `boundary` represents the end of the region to erase. Make this a little clearer by consistently using clearer variable names. The `boundary` variable is removed, the bounds of the region to erase are described by `erase_low` and `erase_high`, and bounds of the task stack are described by `task_stack_low` and `task_stck_high`. As the same time, remove the comment above the variables, since it is unclear whether it's intended as rationale, a complaint, or a TODO, and is more confusing than helpful. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Alexander Popov Cc: Andrew Morton Cc: Andy Lutomirski Cc: Kees Cook --- kernel/stackleak.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/kernel/stackleak.c b/kernel/stackleak.c index 24b7cf01b2972..d5f684dc0a2d9 100644 --- a/kernel/stackleak.c +++ b/kernel/stackleak.c @@ -73,40 +73,38 @@ late_initcall(stackleak_sysctls_init); static __always_inline void __stackleak_erase(void) { const unsigned long task_stack_low = stackleak_task_low_bound(current); - - /* It would be nice not to have 'kstack_ptr' and 'boundary' on stack */ - unsigned long kstack_ptr = current->lowest_stack; - unsigned long boundary = task_stack_low; + unsigned long erase_low = current->lowest_stack; + unsigned long erase_high; unsigned int poison_count = 0; const unsigned int depth = STACKLEAK_SEARCH_DEPTH / sizeof(unsigned long); /* Search for the poison value in the kernel stack */ - while (kstack_ptr > boundary && poison_count <= depth) { - if (*(unsigned long *)kstack_ptr == STACKLEAK_POISON) + while (erase_low > task_stack_low && poison_count <= depth) { + if (*(unsigned long *)erase_low == STACKLEAK_POISON) poison_count++; else poison_count = 0; - kstack_ptr -= sizeof(unsigned long); + erase_low -= sizeof(unsigned long); } #ifdef CONFIG_STACKLEAK_METRICS - current->prev_lowest_stack = kstack_ptr; + current->prev_lowest_stack = erase_low; #endif /* - * Now write the poison value to the kernel stack. Start from - * 'kstack_ptr' and move up till the new 'boundary'. We assume that - * the stack pointer doesn't change when we write poison. + * Now write the poison value to the kernel stack between 'erase_low' + * and 'erase_high'. We assume that the stack pointer doesn't change + * when we write poison. */ if (on_thread_stack()) - boundary = current_stack_pointer; + erase_high = current_stack_pointer; else - boundary = current_top_of_stack(); + erase_high = current_top_of_stack(); - while (kstack_ptr < boundary) { - *(unsigned long *)kstack_ptr = STACKLEAK_POISON; - kstack_ptr += sizeof(unsigned long); + while (erase_low < erase_high) { + *(unsigned long *)erase_low = STACKLEAK_POISON; + erase_low += sizeof(unsigned long); } /* Reset the 'lowest_stack' value for the next syscall */ -- 2.30.2