From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0670FC433E1 for ; Tue, 26 May 2020 12:35:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0AEC2073B for ; Tue, 26 May 2020 12:35:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="SLiZEO0T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0AEC2073B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 08AE9800A7; Tue, 26 May 2020 08:35:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03BC680061; Tue, 26 May 2020 08:35:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9519800A7; Tue, 26 May 2020 08:35:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id CED4A80061 for ; Tue, 26 May 2020 08:35:02 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7A954181AC9C6 for ; Tue, 26 May 2020 12:35:02 +0000 (UTC) X-FDA: 76858814844.20.sand38_490386981852b X-HE-Tag: sand38_490386981852b X-Filterd-Recvd-Size: 4581 Received: from ozlabs.org (ozlabs.org [203.11.71.1]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 May 2020 12:35:01 +0000 (UTC) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49WYM431Ncz9sRW; Tue, 26 May 2020 22:34:56 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1590496496; bh=nlmuxPZ4OAcgaEOWJJyC/a4yX3EnNdlg306uXa5AWVM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=SLiZEO0TBai5zo5oWN8HDSJWMY3gH6u9hDSsLJe/HYYSSDwWXTIpffodrGTTWNSMx DlmC+YpjK7Cn65T3Z8GSUEx/S6IDg5fMyRS3RR1/sneUpU/VwN7yn6s2NEBC/Zk6LK F8EGeCL6HP2BBqsR3Q9i6L6qfV3RpFso/Tzt9MRpd4xwSHNSIXv48ZuF8z7rek2hk/ vfzL4hjxoOU+SgbfD77T9OItD0rTosQ3mJbem2OFroxzwymuLF2m5UlOZE3FXavmLU oTfeMlLogZrs5xYwG2c0Hm4EjcK1t1br7r63h9hjZYsfqL5/hYCxhSNkUC1LuOLqSP 0t+bF8m0jC20g== From: Michael Ellerman To: Sandipan Das Cc: linux-kselftest@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linuxram@us.ibm.com, aneesh.kumar@linux.ibm.com, bauerman@linux.ibm.com, fweimer@redhat.com, ruscur@russell.cc Subject: Re: [PATCH] selftests: powerpc: Add test for execute-disabled pkeys In-Reply-To: <20200508162332.65316-1-sandipan@linux.ibm.com> References: <20200508162332.65316-1-sandipan@linux.ibm.com> Date: Tue, 26 May 2020 22:35:19 +1000 Message-ID: <87367mg9h4.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain 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: Hi Sandipan, Sandipan Das writes: > diff --git a/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c b/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c > new file mode 100644 > index 000000000000..b346ad205e68 > --- /dev/null > +++ b/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c > @@ -0,0 +1,326 @@ > +// SPDX-License-Identifier: GPL-2.0+ > + > +/* > + * Copyright 2020, Sandipan Das, IBM Corp. > + * > + * Test if applying execute protection on pages using memory > + * protection keys works as expected. > + */ > + > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "utils.h" > + > +/* Override definitions as they might be inconsistent */ > +#undef PKEY_DISABLE_ACCESS > +#define PKEY_DISABLE_ACCESS 0x3 Why would they be inconsistent? > +/* Older distros might not define this */ > +#ifndef SEGV_PKUERR > +#define SEGV_PKUERR 4 > +#endif ... > + > + /* Restore permissions in order to continue */ > + switch (fcode) { > + case SEGV_ACCERR: > + if (mprotect(insns, pgsize, PROT_READ | PROT_WRITE)) { > + perror("mprotect"); > + goto fail; > + } > + break; > + case SEGV_PKUERR: > + if (sinfo->si_pkey != fpkey) > + goto fail; This doesn't compile on older distros, eg Ubuntu 16.04: pkey_exec_prot.c: In function 'segv_handler': pkey_exec_prot.c:121:12: error: 'siginfo_t {aka struct }' has no member named 'si_pkey' if (sinfo->si_pkey != fpkey) ^ pkey_exec_prot.c:151:24: error: 'siginfo_t {aka struct }' has no member named 'si_pkey' pkey_set_rights(sinfo->si_pkey, 0); ^ ../../lib.mk:142: recipe for target '/output/kselftest/powerpc/mm/pkey_exec_prot' failed I think a reasonable solution is to use the absence of SEGV_PKUERR to basically turn the whole test into a nop at build time, eg: diff --git a/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c b/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c index b346ad205e68..218257b89fbb 100644 --- a/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c +++ b/tools/testing/selftests/powerpc/mm/pkey_exec_prot.c @@ -30,9 +30,7 @@ #define PKEY_DISABLE_EXECUTE 0x4 /* Older distros might not define this */ -#ifndef SEGV_PKUERR -#define SEGV_PKUERR 4 -#endif +#ifdef SEGV_PKUERR #define SYS_pkey_mprotect 386 #define SYS_pkey_alloc 384 @@ -319,6 +317,13 @@ static int test(void) return 0; } +#else +static int test(void) +{ + printf("Test built with old libc lacking pkey support.\n"); + SKIP_IF(true); +} +#endif /* SEGV_PKUERR */ int main(void) { cheers