Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2799048rda; Wed, 25 Oct 2023 12:36:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETEMdSN5yDCvHle2P8y3ou79OgF9ccHnr2oGqnP6wQ8FTzWH78fmCbwmWBQStHgARvwqQD X-Received: by 2002:a25:86d0:0:b0:da0:6933:d8d with SMTP id y16-20020a2586d0000000b00da069330d8dmr3524078ybm.63.1698262608570; Wed, 25 Oct 2023 12:36:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698262608; cv=none; d=google.com; s=arc-20160816; b=wnefPuR3CAIF1tJvdJIlwclgHAisrIbQ8HQaufbeDuPs7OLlMCOSX/s8fdnfHW0yoS PiXT1ELaVBtMsRDKq8u77GJomjfhbPuuOOhaSCEAecRgiuQGMAhjMgw7l4ZhEeam7Kbx XE6BE1b1Ye5TnbhdGrjeBrQYprZaUey9OQJDHF0tTq37THytyXa36Rn7eVPvwZTenGsK LFOYsbroXTDFFXKwl73dYyOTgll+rzhjwssEDT5pYtasCpaOle3S7bgz5BDXO2dH7xQD M4B8KoDN6X04fqmt9kMSoeW080tg6KcCLsR0jf8Wc3TFRPTF5AKHXnwgCSsvlHT6PXF8 9TQA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=26pJmtJb2RAX7qmuNdQwiZrEag4RUY/XohpxzktHJ4U=; fh=GtNM2lGLFf3pXoEYQMwt5tbPAD3CxzrC8r7SMmRZj9U=; b=Ou8igoJoHyHauXv/OU9jGFk8fvMGr9NZpkUf0UM6Xv3gO84hunaavPzrb9eCcGshib AuJD6Cb40BrPFnDUO3fczr5LBkBQRo+ABBO4qzk98zH85bpEAIXGpg4e251NrskrvN8y yoL8CBRvrN5hJWf1ttETaLM82obXvhO6MtgXbEhw+D9U1AU7xIaWQ0lfLaeMsS1CbwEL xY0kFJqtjDu9l8wyQNL+17p60v1gMNrRy2GzSS/kxq7k/FmIcAik3NpRacXI+X2eceaX XHgJVi14q4XpGZUy5cn4i8dP09lvu5kPCr6BmVSlr490T0aSJGWzOVHKSURBOovUSUQM Fnew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RvlezJOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h25-20020a25b199000000b00d9a6a0bf2c6si11116563ybj.475.2023.10.25.12.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 12:36:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RvlezJOy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 5702D817296E; Wed, 25 Oct 2023 12:36:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjJYTgj (ORCPT + 99 others); Wed, 25 Oct 2023 15:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjJYTgj (ORCPT ); Wed, 25 Oct 2023 15:36:39 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4976C137; Wed, 25 Oct 2023 12:36:37 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5aa7172bafdso141238a12.1; Wed, 25 Oct 2023 12:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698262597; x=1698867397; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=26pJmtJb2RAX7qmuNdQwiZrEag4RUY/XohpxzktHJ4U=; b=RvlezJOy2Lvesfxpl4dsR6OnAIyhMX1JOerDoq8/cibiC/hF+H+BQfbxpMxffRBTld KQDucZBy2SNZHEyL3GVm9CdXl5zoFX6ZZHFtj+350EjR+p+HAayBUtsSN8BhmqmCkgJw gpItznj8/bZf/Dj+KH7yx8WvWm1VJB+S8qBEfY2rdBio/4NFTQA7pSf55P4xpTaEJktu s/bk96DeAIlhHWf2Eb5QKwpMbBU9bXcCPmJRyCSG9BNeE1usE0UUQ6uF2N1ssW35S47W TcV2y4YpKF1EsQMmdE4gaDkdlt78WhUnMK6FjPDrUmwl/C6ncKAvTzXFxBAWSFaz/k3S SYJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698262597; x=1698867397; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=26pJmtJb2RAX7qmuNdQwiZrEag4RUY/XohpxzktHJ4U=; b=wL4cWPU0S4+FcnO6UKKkYlSV+Fgz0YZDMhAdim47OKDfVTfeeLk+IbYUE64qSbwy2J sZKPMlZE021hRv3iIujbn3QJ5z5mP+gPmMmQnGo0nj8fWP/pfCnyS27Admm2LVy/8odf moqImQ312qNCfYRwhjOqUyRjKbFGt135YNEVew8CshTZptKW95Op4Aa/nYjZ0EcuCq8U 3m0+DicU+inx0NZy9J+uidUfcVdQGM3OqCJpkJulWv0CBotoSja8WxlFC1qpHdKXFCKH f07R60BkJUJG/cF7SLglET2TjkOCPhyar5nUaYLL94VK9/jjcdrizQw+2HrekGR07sry Tjfw== X-Gm-Message-State: AOJu0YwnVWxpfcO2ITp048viDsmd8PN/pbVeHepAmqcCEJ9rSO+ZGB26 D57AtVlP+FDBIxdzS8PGi7M= X-Received: by 2002:a05:6a20:6a0b:b0:17b:129b:1817 with SMTP id p11-20020a056a206a0b00b0017b129b1817mr7106857pzk.45.1698262596525; Wed, 25 Oct 2023 12:36:36 -0700 (PDT) Received: from swarup-virtual-machine.localdomain ([171.76.80.48]) by smtp.gmail.com with ESMTPSA id g9-20020a635209000000b00565dd935938sm9217483pgb.85.2023.10.25.12.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 12:36:36 -0700 (PDT) From: Swarup Laxman Kotiaklapudi To: shuah@kernel.org, akpm@linux-foundation.org, adobriyan@gmail.com, hughd@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Cc: Swarup Laxman Kotiaklapudi Subject: [PATCH] selftests:proc ProtectionKey check in smpas test Date: Thu, 26 Oct 2023 01:06:27 +0530 Message-Id: <20231025193627.316508-1-swarupkotikalapudi@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 25 Oct 2023 12:36:45 -0700 (PDT) Check ProtectionKey field in /proc/*/smaps output, if system supports page-based memory permissions. Signed-off-by: Swarup Laxman Kotiaklapudi --- tools/testing/selftests/proc/proc-empty-vm.c | 38 ++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c index b16c13688b88..4842f923235c 100644 --- a/tools/testing/selftests/proc/proc-empty-vm.c +++ b/tools/testing/selftests/proc/proc-empty-vm.c @@ -37,6 +37,7 @@ #include #include #include +#include "../kselftest.h" #ifdef __amd64__ #define TEST_VSYSCALL @@ -83,10 +84,7 @@ static const char proc_pid_smaps_vsyscall_1[] = "SwapPss: 0 kB\n" "Locked: 0 kB\n" "THPeligible: 0\n" -/* - * "ProtectionKey:" field is conditional. It is possible to check it as well, - * but I don't have such machine. - */ +"ProtectionKey: 0\n" ; static const char proc_pid_smaps_vsyscall_2[] = @@ -113,10 +111,7 @@ static const char proc_pid_smaps_vsyscall_2[] = "SwapPss: 0 kB\n" "Locked: 0 kB\n" "THPeligible: 0\n" -/* - * "ProtectionKey:" field is conditional. It is possible to check it as well, - * but I'm too tired. - */ +"ProtectionKey: 0\n" ; static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___) @@ -241,13 +236,26 @@ static int test_proc_pid_smaps(pid_t pid) } else { ssize_t rv = read(fd, buf, sizeof(buf)); close(fd); - if (g_vsyscall == 0) { - assert(rv == 0); - } else { - size_t len = strlen(g_proc_pid_maps_vsyscall); - /* TODO "ProtectionKey:" */ - assert(rv > len); - assert(memcmp(buf, g_proc_pid_maps_vsyscall, len) == 0); + assert(rv >= 0); + assert(rv <= sizeof(buf)); + if (g_vsyscall != 0) { + int pkey = pkey_alloc(0, 0); + + if (pkey < 0) { + size_t len = strlen(g_proc_pid_maps_vsyscall); + + assert(rv > len); + assert(memcmp(buf, g_proc_pid_maps_vsyscall, len) == 0); + } else { + pkey_free(pkey); + static const char * const S[] = { + "ProtectionKey: 0\n" + }; + int i; + + for (i = 0; i < ARRAY_SIZE(S); i++) + assert(memmem(buf, rv, S[i], strlen(S[i]))); + } } return EXIT_SUCCESS; } -- 2.34.1