From patchwork Wed Nov 27 17:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 13887257 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B6E4201028; Wed, 27 Nov 2024 17:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728962; cv=none; b=dJy5IP/Fg428vASROXaD4KTZn8az5JA2odMxFHkg48I0aPa7XoByu6CmSCkb20MdhdAaWp/4TeDFKZMp2TJO2TzMqyIPGCavc1ox7+w2WXb+qOS+USqpKFNWKImDmuQ0sqiwaDldq79lRMHVjO8Bb+u+B7+F4q+XKs+pIa2p4wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728962; c=relaxed/simple; bh=Sbl14Xzfp6nN0p/UKfe6EiU0QQWGiojbB1fSn6/9LWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fwTlmfhZCjrtPldRZdmMqmUqB1rx26drQI4eGlyKAlGo4+Brf/XzHVTIXZN5MGYUmsFy2D75PfgQR+++fkfaWQozhDJbtqhyGRIhfXH6Oqn0NLaxp8ah6pcfObN9Izk5W4VNeU9kJaM60Uy2YB1Bk9+gEmVNm/Xm//DQpT0f10s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Om+wtm7U; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Om+wtm7U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732728961; x=1764264961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sbl14Xzfp6nN0p/UKfe6EiU0QQWGiojbB1fSn6/9LWs=; b=Om+wtm7UsjdK8Bpc9NddPhTzPlZIXDgvkM30e85XTeMqofwwtosfWgCt KrL+Dq7bkM+XoKsCJdO91nWiQ1+QeNnn0VGLQsgdjFFW4FgvoowpOdTSo zf/oAKBshRdzFmyAMJLK7wno3FKhfufzsgA/Rwzqk3eLK80N974e8U1uE lw/suzdt1Dl9klZIP3QJle03I8+YFdn11SkZCH7lBGlgPDYDylQ+co3HS 2t9/7YoK1PdlqGYxfT5P6SzAvPop8eoKQFBZbSXPWAvfJYxv87/lk/qlj HJ7n4spO9I/fdhLKRqkaLt0jlfJQ6rNq39ZX0pdTAmKyRhUIq4p75kIY7 Q==; X-CSE-ConnectionGUID: 3eak5DefSoyzQWgjyvrsKg== X-CSE-MsgGUID: bZgGk8RuRQ+TnkUEgVArig== X-IronPort-AV: E=McAfee;i="6700,10204,11269"; a="43607496" X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="43607496" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:36:00 -0800 X-CSE-ConnectionGUID: Y1klalnhTLydkm4reomGLA== X-CSE-MsgGUID: /d3WfWRmTCqU6/Osh454iw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="91626331" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.245.244.193]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:35:57 -0800 From: Maciej Wieczor-Retman To: shuah@kernel.org, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.com, bp@alien8.de, mingo@redhat.com, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kirill@shutemov.name, maciej.wieczor-retman@intel.com, "Kirill A. Shutemov" , Shuah Khan Subject: [PATCH v5 1/3] selftests/lam: Move cpu_has_la57() to use cpuinfo flag Date: Wed, 27 Nov 2024 18:35:29 +0100 Message-ID: <63f8fa8ac016f9f294230657e9069a616bce6141.1732728879.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In current form cpu_has_la57() reports platform's support for LA57 through reading the output of cpuid. A much more useful information is whether 5-level paging is actually enabled on the running system. Presence of the la57 flag in /proc/cpuinfo signifies that 5-level paging was compiled into the kernel, is supported by the platform and wasn't disabled by kernel command line argument. Use system() with cat and grep to figure out if la57 is enabled on the running system. Signed-off-by: Maciej Wieczor-Retman Acked-by: Kirill A. Shutemov Acked-by: Shuah Khan --- Changelog v5: - Remove "cat" from system() call and use only "grep". Changelog v4: - Add this patch to the series. tools/testing/selftests/x86/lam.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c index 0ea4f6813930..93f2f762d6b5 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -124,14 +124,9 @@ static inline int cpu_has_lam(void) return (cpuinfo[0] & (1 << 26)); } -/* Check 5-level page table feature in CPUID.(EAX=07H, ECX=00H):ECX.[bit 16] */ static inline int cpu_has_la57(void) { - unsigned int cpuinfo[4]; - - __cpuid_count(0x7, 0, cpuinfo[0], cpuinfo[1], cpuinfo[2], cpuinfo[3]); - - return (cpuinfo[2] & (1 << 16)); + return !system("grep -wq la57 /proc/cpuinfo"); } /* From patchwork Wed Nov 27 17:35:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 13887258 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3A7E2010EC; Wed, 27 Nov 2024 17:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728965; cv=none; b=NPAp+JXwV6g6iPizb5CdJCh7C/x85o3a8dRtwqSPQSZ2PJ+l9VunZVWwwyD1Ev8WVXjSSQU/ww3/5J3C2PhTknvuqt7Du7P1lk9lLZtsIGYB5tSHSmwzJV2UAgfQxlSVBijo2lhwLqpuBkeI8PQtrSMBlWO1cLDAamfIxQHnfIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728965; c=relaxed/simple; bh=RF4rG7dZqGqAjCmjHOsGfY+CZsIm6V7+eg4OHintPpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NM+28MzC2N61lB3YqbDQqwU8QrMdRfYlP2fR58/BQgxqfQapwUUuGRhOqImCtrNmmtGYNt3em/54LH6V0Y849iL4jDfr4iO/3FNoNRFXI2N8H3KID6SksGUh0ku1qn0/shHLtp0Y4/gulnf0bUdu4M600NBydyiyBMq6DGBX+Gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UzbK3ut0; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UzbK3ut0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732728964; x=1764264964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RF4rG7dZqGqAjCmjHOsGfY+CZsIm6V7+eg4OHintPpk=; b=UzbK3ut03d+J7CArNZBuHyvQwxbvEyCF4s4ClWHVZ+bmio9gtI0c5KJd GTuWxVkhNWJtH7Nc7nNGOWoS8c+NiMY8Y3aruHkGCc1N5ts7LV33tgak5 QctmCgv6isJsxMnWeAD2ekXjwViPeF68matYBwRwF/qz36mvkksuJlaDn PZIe7UiAJS/0EYcWeCrEomJd9ZXCjwUDkdaEYamP/g/Gxtr6OXtjrvWuE w/+p9MltmSWJ0sUSHZyDDYyDHCKDumRR2AxCjDL54fytR+uxOZQtUtPGB FQgKYwq5IF+pI8HU6xx/EyBye/x61/v3uZYstMctOxCB87OyI1IVo+EGr g==; X-CSE-ConnectionGUID: 6MnxV0NpS6aDegdbOtCtzw== X-CSE-MsgGUID: f/w3AxoKSdCp3GJ1TN4NcQ== X-IronPort-AV: E=McAfee;i="6700,10204,11269"; a="43607515" X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="43607515" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:36:04 -0800 X-CSE-ConnectionGUID: 59gh4jNbTsinhWC6nKmM7A== X-CSE-MsgGUID: KULZOYFgThuRaUNs5a802Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="91626348" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.245.244.193]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:36:00 -0800 From: Maciej Wieczor-Retman To: shuah@kernel.org, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.com, bp@alien8.de, mingo@redhat.com, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kirill@shutemov.name, maciej.wieczor-retman@intel.com, "Kirill A. Shutemov" , Shuah Khan Subject: [PATCH v5 2/3] selftests/lam: Skip test if LAM is disabled Date: Wed, 27 Nov 2024 18:35:30 +0100 Message-ID: <09e6958c424a5da763f2331745cfe145962b0a83.1732728879.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Until LASS is merged into the kernel [1], LAM is left disabled in the config file. Running the LAM selftest with disabled LAM only results in unhelpful output. Use one of LAM syscalls() to determine whether the kernel was compiled with LAM support (CONFIG_ADDRESS_MASKING) or not. Skip running the tests in the latter case. [1] https://lore.kernel.org/all/20241028160917.1380714-1-alexander.shishkin@linux.intel.com/ Signed-off-by: Maciej Wieczor-Retman Acked-by: Kirill A. Shutemov Acked-by: Shuah Khan --- Changelog v4: - Add this patch to the series. tools/testing/selftests/x86/lam.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c index 93f2f762d6b5..4ec37a4be007 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -124,6 +124,14 @@ static inline int cpu_has_lam(void) return (cpuinfo[0] & (1 << 26)); } +static inline int kernel_has_lam(void) +{ + unsigned long bits; + + syscall(SYS_arch_prctl, ARCH_GET_MAX_TAG_BITS, &bits); + return !!bits; +} + static inline int cpu_has_la57(void) { return !system("grep -wq la57 /proc/cpuinfo"); @@ -1181,6 +1189,11 @@ int main(int argc, char **argv) return KSFT_SKIP; } + if (!kernel_has_lam()) { + ksft_print_msg("LAM is disabled in the kernel!\n"); + return KSFT_SKIP; + } + while ((c = getopt(argc, argv, "ht:")) != -1) { switch (c) { case 't': From patchwork Wed Nov 27 17:35:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 13887259 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 784D4201101; Wed, 27 Nov 2024 17:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728969; cv=none; b=htLE7QVkylzdWZOrwCQCXopdcas3YxUiiGUcRWWR7phw9n/R0DPCOTXN6a7Ai+sGbHBarVweFl9LrBnIsZdCqKCzTchdj+Gh6AKAFF+/EXBes3YTBE2J7sHxAjR3tFSDU3b17CLIIGMG0TUxfVVr55gKB4zLJYNH4CKoO9O7W+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732728969; c=relaxed/simple; bh=tNMPuF9n5H1gSULGpD5Nersb7zlDJF4+Kn0ZO5uEySo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EpsxzKfojhcIhllHFJmAZ8u5MpFjV38CDM0tqL8EiDx762AaHujQC6YD/B/BJkdCwP1F9SBo22SD8pKJ/i6p8u2rLsnP1P2ie40om5ohlCxPLldWE9NiZgJH34qz6GdvCLKn78IRhL3u7IeycHu/N+BhgEcoKdn0yHcY4gchsMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gC9hVAep; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gC9hVAep" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732728968; x=1764264968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tNMPuF9n5H1gSULGpD5Nersb7zlDJF4+Kn0ZO5uEySo=; b=gC9hVAepJHezkuCxrPVegmfFuoQqttnMu3I7nc+stnC1YiqwPVTnmlS3 E59iuBsWgmr0mc87UlvHLR2weGDaLstGFVjtvDk131FZMN8sqFGKiWnng 2qCEvjo+DlhJKzfe+azZoKbgPXF6g5RndcfPE4X+SruL0C0xGMZT6fg2O 9AQwCsrN1upyw2APolYa6IRT1M+CTlbr/JJxyAAHqhaUclLFrCHbPtTCB Ys/WqZ8wWNpWSxRjStA8BMZNz9DEXhxpD4FQ8uOGxnVJIVSzG2NV21jhW 4tIHKCcmlpsBMb06/mW2imSB4A2DUmUHGJCiuamJE86p5HZnw8SgQctGg Q==; X-CSE-ConnectionGUID: T3nttad7Rf2fL8ZtvThEIA== X-CSE-MsgGUID: Hly1Za2/QhW7bR5wvwXAKg== X-IronPort-AV: E=McAfee;i="6700,10204,11269"; a="43607529" X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="43607529" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:36:07 -0800 X-CSE-ConnectionGUID: IsgYw56XS8mDr1ohmmSkXw== X-CSE-MsgGUID: ZvhCikDwRjGFCCH0ZLETUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,189,1728975600"; d="scan'208";a="91626381" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.245.244.193]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2024 09:36:04 -0800 From: Maciej Wieczor-Retman To: shuah@kernel.org, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.com, bp@alien8.de, mingo@redhat.com, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kirill@shutemov.name, maciej.wieczor-retman@intel.com, "Kirill A. Shutemov" , Shuah Khan Subject: [PATCH v5 3/3] selftests/lam: Test get_user() LAM pointer handling Date: Wed, 27 Nov 2024 18:35:31 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Recent change in how get_user() handles pointers [1] has a specific case for LAM. It assigns a different bitmask that's later used to check whether a pointer comes from userland in get_user(). Add test case to LAM that utilizes a ioctl (FIOASYNC) syscall which uses get_user() in its implementation. Execute the syscall with differently tagged pointers to verify that valid user pointers are passing through and invalid kernel/non-canonical pointers are not. [1] https://lore.kernel.org/all/20241024013214.129639-1-torvalds@linux-foundation.org/ Signed-off-by: Maciej Wieczor-Retman Acked-by: Kirill A. Shutemov Acked-by: Shuah Khan --- Changelog v4: - Use the changed cpu_has_la57() instead of mmap() to figure out current paging level. - Apply Kirill's other comments: Remove redundant always true check, close the ioctl file before exiting, change mapping size to PAGE_SIZE so it looks less odd. - Turn this patch into a series and move some text to the cover letter. Changelog v3: - mmap the pointer passed to get_user to high address if 5 level paging is enabled and to low address if 4 level paging is enabled. Changelog v2: - Use mmap with HIGH_ADDR to check if we're in 5 or 4 level pagetables. tools/testing/selftests/x86/lam.c | 102 ++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c index 4ec37a4be007..b602541e7bdf 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,15 @@ #define FUNC_INHERITE 0x20 #define FUNC_PASID 0x40 +/* get_user() pointer test cases */ +#define GET_USER_USER 0 +#define GET_USER_KERNEL_TOP 1 +#define GET_USER_KERNEL_BOT 2 +#define GET_USER_KERNEL 3 + #define TEST_MASK 0x7f +#define L5_SIGN_EXT_MASK (0xFFUL << 56) +#define L4_SIGN_EXT_MASK (0x1FFFFUL << 47) #define LOW_ADDR (0x1UL << 30) #define HIGH_ADDR (0x3UL << 48) @@ -373,6 +382,72 @@ static int handle_syscall(struct testcases *test) return ret; } +static int get_user_syscall(struct testcases *test) +{ + uint64_t ptr_address, bitmask; + int fd, ret = 0; + void *ptr; + + if (cpu_has_la57()) { + bitmask = L5_SIGN_EXT_MASK; + ptr_address = HIGH_ADDR; + } else { + bitmask = L4_SIGN_EXT_MASK; + ptr_address = LOW_ADDR; + } + + ptr = mmap((void *)ptr_address, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + + if (ptr == MAP_FAILED) { + perror("failed to map byte to pass into get_user"); + return 1; + } + + if (set_lam(test->lam) != 0) { + ret = 2; + goto error; + } + + fd = memfd_create("lam_ioctl", 0); + if (fd == -1) { + munmap(ptr, PAGE_SIZE); + exit(EXIT_FAILURE); + } + + switch (test->later) { + case GET_USER_USER: + /* Control group - properly tagger user pointer */ + ptr = (void *)set_metadata((uint64_t)ptr, test->lam); + break; + case GET_USER_KERNEL_TOP: + /* Kernel address with top bit cleared */ + bitmask &= (bitmask >> 1); + ptr = (void *)((uint64_t)ptr | bitmask); + break; + case GET_USER_KERNEL_BOT: + /* Kernel address with bottom sign-extension bit cleared */ + bitmask &= (bitmask << 1); + ptr = (void *)((uint64_t)ptr | bitmask); + break; + case GET_USER_KERNEL: + /* Try to pass a kernel address */ + ptr = (void *)((uint64_t)ptr | bitmask); + break; + default: + printf("Invalid test case value passed!\n"); + break; + } + + if (ioctl(fd, FIOASYNC, ptr) != 0) + ret = 1; + + close(fd); +error: + munmap(ptr, PAGE_SIZE); + return ret; +} + int sys_uring_setup(unsigned int entries, struct io_uring_params *p) { return (int)syscall(__NR_io_uring_setup, entries, p); @@ -886,6 +961,33 @@ static struct testcases syscall_cases[] = { .test_func = handle_syscall, .msg = "SYSCALL:[Negative] Disable LAM. Dereferencing pointer with metadata.\n", }, + { + .later = GET_USER_USER, + .lam = LAM_U57_BITS, + .test_func = get_user_syscall, + .msg = "GET_USER: get_user() and pass a properly tagged user pointer.\n", + }, + { + .later = GET_USER_KERNEL_TOP, + .expected = 1, + .lam = LAM_U57_BITS, + .test_func = get_user_syscall, + .msg = "GET_USER:[Negative] get_user() with a kernel pointer and the top bit cleared.\n", + }, + { + .later = GET_USER_KERNEL_BOT, + .expected = 1, + .lam = LAM_U57_BITS, + .test_func = get_user_syscall, + .msg = "GET_USER:[Negative] get_user() with a kernel pointer and the bottom sign-extension bit cleared.\n", + }, + { + .later = GET_USER_KERNEL, + .expected = 1, + .lam = LAM_U57_BITS, + .test_func = get_user_syscall, + .msg = "GET_USER:[Negative] get_user() and pass a kernel pointer.\n", + }, }; static struct testcases mmap_cases[] = {