From patchwork Tue Jul 23 06:49:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuan-Ying Lee X-Patchwork-Id: 13739591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AE66C3DA63 for ; Tue, 23 Jul 2024 06:49:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D4666B00C7; Tue, 23 Jul 2024 02:49:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 881EB6B00C8; Tue, 23 Jul 2024 02:49:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 684706B00C9; Tue, 23 Jul 2024 02:49:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4697A6B00C7 for ; Tue, 23 Jul 2024 02:49:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F3BF0161D58 for ; Tue, 23 Jul 2024 06:49:47 +0000 (UTC) X-FDA: 82370092056.18.35B53AB Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by imf16.hostedemail.com (Postfix) with ESMTP id DD7AD180004 for ; Tue, 23 Jul 2024 06:49:45 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=FwKl7jyR; spf=pass (imf16.hostedemail.com: domain of kuan-ying.lee@canonical.com designates 185.125.188.123 as permitted sender) smtp.mailfrom=kuan-ying.lee@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721717350; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wYKfkQhlmAQpjsnay3TVuvCtalPKMOXrFYtZFkyFmGI=; b=PA30tkdzvqygaqimLYGUz+q3NvoDcz5MHhXZ7XJJ+uK7BWo2fH3vuEcC95IQpWTDmeD7Ww 6r3ulzbHiKFPkUIHGtVuvaoPhYrce5xDfkPb/7pMtmticePukIpVH9EsoIUXK8s4r2WFxv OzbQhTa4DHPU0VpwBU1pUx06Ad2tdEI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=FwKl7jyR; spf=pass (imf16.hostedemail.com: domain of kuan-ying.lee@canonical.com designates 185.125.188.123 as permitted sender) smtp.mailfrom=kuan-ying.lee@canonical.com; dmarc=pass (policy=none) header.from=canonical.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721717350; a=rsa-sha256; cv=none; b=5ulAO5afqENv/Ez5wxPlJFsiK9Jb5Y54szQmbMo5PK9UEOwVPF6ogUWxYAlD04WKVe1sSY Nlnddg8JcScIpn1+F2ynVK+5U9hn3xhETBLXHiFWwjOgGH2b1eDrMszWDD8N3uABvmUjyd ob5nipGX8uvDzeC2lPJOAro3SSNyruY= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 94D443F187 for ; Tue, 23 Jul 2024 06:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1721717384; bh=wYKfkQhlmAQpjsnay3TVuvCtalPKMOXrFYtZFkyFmGI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FwKl7jyRzm7UKftIBxpkcHEbgYH80l0/JvuQYFQsn3Xw5nrvfTFaKEk1xz4vrZnUX CqhjnzQ4kXWzm+3KqyyuwASP9n0D24CdzLN2CmmyD8zSSijl4RkBo4rUocuOU9/VIs 6xuLLR1yV21JmO3ag6E6sBQZnCuwohzk9dcos16w55op6SD/7kT1Kye/omiU0GTuUC XDXco/Zn5W4hseK4hsOOfrUsRyR8GGW4vFFGQX5lcRHk1pXmWKtziUW4/Q24HhW8mi RraxdFzKSUZ5LiK0e8ZrYvREKa2io7CovGzA7YlDw2A2A610ZCc/gdn/giafiIpqjl vXxtssL2WiMCA== Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2cb575938f1so4679472a91.2 for ; Mon, 22 Jul 2024 23:49:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721717383; x=1722322183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wYKfkQhlmAQpjsnay3TVuvCtalPKMOXrFYtZFkyFmGI=; b=J7UgJc24wv9v639ji9EEDTYiOa7YUfpA2lY0gpDLMlJkv5RYbUUXSMt845WAEURdMJ IL2yvLhRuX/IIOvavZ8/YzlHxwh0U3BfMoA5X2Rpn24hNgdCrGxLT4qVjmv0ALIxbXNZ 41mBlMWZgGU1G5B2bgCHwQ3ozsi/srBOB2u6i9u0+8NmGrCQmfcrFjdqs8MqBYUfS/2U 1xptXscitT/f68t9K7rkpvllb0upNZ/NOdGxtU/caNn/eb76qffl+UkcHkuQOFkxG1yh wK27oC116O21K/U+KQ4lctoJZSrkEP+LrIasIIXPudBBOoh6RfTpzi/KHU9RYdXaIHVH N8ZQ== X-Gm-Message-State: AOJu0Yx5u4FkCwZKX/vNXXv2OfTkyQMek7IjPkQVzlLC+oyJc8/wvdgb mUy5LrHR+dOrRIg80OHPYplp6T9v85Mj3UreUyvFsJmWeONrN7TUmrnwSmT1Kgd5OVe6ZORlRY9 hjIVV5GaZmpodYjv83vA2ELsiZTl+asrZ9x31WbbwXkWWGkiXG/VOp8sXjQQE6Xs/ X-Received: by 2002:a17:90a:e501:b0:2cd:1e60:9c31 with SMTP id 98e67ed59e1d1-2cd1e609c71mr5483420a91.30.1721717383186; Mon, 22 Jul 2024 23:49:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFl31sX6VxPv7cHZhXyRmzKNIeGHs2Q9sPpSI1pZKYGAWsC+89F8KKIt8KWDuUcYG9dGvD/Q== X-Received: by 2002:a17:90a:e501:b0:2cd:1e60:9c31 with SMTP id 98e67ed59e1d1-2cd1e609c71mr5483405a91.30.1721717382832; Mon, 22 Jul 2024 23:49:42 -0700 (PDT) Received: from kylee-ThinkPad-E16-Gen-1.. ([122.147.171.160]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ccf7c5391bsm8354749a91.24.2024.07.22.23.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 23:49:42 -0700 (PDT) From: Kuan-Ying Lee To: kuan-ying.lee@canonical.com, Andrew Morton , Jan Kiszka , Kieran Bingham Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] scripts/gdb: Add 'lx-kasan_mem_to_shadow' command Date: Tue, 23 Jul 2024 14:49:01 +0800 Message-Id: <20240723064902.124154-6-kuan-ying.lee@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723064902.124154-1-kuan-ying.lee@canonical.com> References: <20240723064902.124154-1-kuan-ying.lee@canonical.com> MIME-Version: 1.0 X-Stat-Signature: r89aerux34et6eaehm8x5564m4ziipzy X-Rspam-User: X-Rspamd-Queue-Id: DD7AD180004 X-Rspamd-Server: rspam02 X-HE-Tag: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N8qkyM73qEla9T8Mb0/+GaGgJc38P38luRQTwAMK3iOs0dxiOCu6bWBDumnF2Pr6txz2gUEEXAjvRqXwUtv/pjQ/PhuZVXrj2Oc7g/dyrcSZmQWj7n2u6k9v6eeyUqWlAVOegqQWTs0fBW1Uz8Un1kO0B/6Gn/fU8H+U0ugPrqcXGj23svx4CSccZWwcNvUsvUOvEI87ZDJcbW/SV/54cTIDN03zX+TtsnIyrPOZxL8QRjX61qCixZoLuEWOSV37Uys7ok4Am+gyN4zWUTGTxYuA5hKFraeNl65QM8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This command allows users to quickly translate memory address to the kasan shadow memory address. Example output: (gdb) lx-kasan_mem_to_shadow 0xffff000019acc008 shadow addr: 0xffff600003359801 Signed-off-by: Kuan-Ying Lee --- scripts/gdb/linux/kasan.py | 44 ++++++++++++++++++++++++++++++++++++++ scripts/gdb/vmlinux-gdb.py | 1 + 2 files changed, 45 insertions(+) create mode 100644 scripts/gdb/linux/kasan.py diff --git a/scripts/gdb/linux/kasan.py b/scripts/gdb/linux/kasan.py new file mode 100644 index 000000000000..56730b3fde0b --- /dev/null +++ b/scripts/gdb/linux/kasan.py @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright 2024 Canonical Ltd. +# +# Authors: +# Kuan-Ying Lee +# + +import gdb +from linux import constants, mm + +def help(): + t = """Usage: lx-kasan_mem_to_shadow [Hex memory addr] + Example: + lx-kasan_mem_to_shadow 0xffff000008eca008\n""" + gdb.write("Unrecognized command\n") + raise gdb.GdbError(t) + +class KasanMemToShadow(gdb.Command): + """Translate memory address to kasan shadow address""" + + p_ops = None + + def __init__(self): + if constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS: + super(KasanMemToShadow, self).__init__("lx-kasan_mem_to_shadow", gdb.COMMAND_SUPPORT) + + def invoke(self, args, from_tty): + if not constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS: + raise gdb.GdbError('CONFIG_KASAN_GENERIC or CONFIG_KASAN_SW_TAGS is not set') + + argv = gdb.string_to_argv(args) + if len(argv) == 1: + if self.p_ops is None: + self.p_ops = mm.page_ops().ops + addr = int(argv[0], 16) + shadow_addr = self.kasan_mem_to_shadow(addr) + gdb.write('shadow addr: 0x%x\n' % shadow_addr) + else: + help() + def kasan_mem_to_shadow(self, addr): + return (addr >> self.p_ops.KASAN_SHADOW_SCALE_SHIFT) + self.p_ops.KASAN_SHADOW_OFFSET + +KasanMemToShadow() diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py index fc53cdf286f1..d4eeed4506fd 100644 --- a/scripts/gdb/vmlinux-gdb.py +++ b/scripts/gdb/vmlinux-gdb.py @@ -49,3 +49,4 @@ else: import linux.page_owner import linux.slab import linux.vmalloc + import linux.kasan