Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp851700iog; Fri, 17 Jun 2022 15:30:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uyEPjLJ+ED51DSlY6UFxrJh7w0/gg2EPZbBL4ecJh4WBs3iqRWK579AnYljQbZ/ODiio9n X-Received: by 2002:a05:6402:ca2:b0:433:4a31:d0ee with SMTP id cn2-20020a0564020ca200b004334a31d0eemr15308902edb.288.1655505028982; Fri, 17 Jun 2022 15:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655505028; cv=none; d=google.com; s=arc-20160816; b=j4JGuhQMHwy5pzZkRFet9zcAKwbO7XxF3pEG5rphdLu4VaW85vmBUYk4ZVdgHWwP+N V2+1qh5yeI8BESGnhstwpwfVx5u61e/59bW4cL3YxtFDF/nVWxcWN4EYWNo+kD18mXF6 oMhqgF6jiEhz8qIIUDikFtfraFm6uwToVUpKuobGDdY22++fyiNuaTEIW7bwExRX0R8s FVLuoEcziYOJ358w0BiP2tu45KuNpdwlkwwUSNT9ymPviAMv4an8a8A6XlclFcenaSko sIqt7aj8zg3s0nAra85cg2+SvqGQTwCM+HFLsb2bHWy1gZTqWxe4+0GQlh21FINCg9Md iwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rHoG7dDbbfhrmS/H7yyWkxeJ8IoOLiAVzbc6Ovna8+k=; b=ZQD9eOcxx6fTow010ry62SHhMxnS3yr+w0abT3e4SyR6WkZ4Dwoo2m594z2pIZfvox ZVRr/h5T0b8gtPXkhlnLG6cxidoYACtB/ompfB1PfwwENZXHFx0z0XvKs9B3eVvO+MTq 1JupdJUdyOWBSP+n3URBW41rk9hKH6WFefSq6FeUjG34AV8WnjHwqS3XmZM8ACG/ddhJ kOrdEduteuI1FiiU40a+6AvgtbjuGITzsBHtmZlJ5qj6Sai3RhqNnzClNW5i5qV29rdk 24qdIO6gLxtE0zxkDDwmGQX4wwuXPX0G86zb3CwXo6YyD7x6fjHlvfAsEJWdaptn66lW wFjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=R6fJeeiG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a056402521100b004355a473970si2874865edd.96.2022.06.17.15.30.04; Fri, 17 Jun 2022 15:30:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=R6fJeeiG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353068AbiFQWFp (ORCPT + 99 others); Fri, 17 Jun 2022 18:05:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245202AbiFQWFo (ORCPT ); Fri, 17 Jun 2022 18:05:44 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31D47590BC for ; Fri, 17 Jun 2022 15:05:43 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id w2so9359124ybi.7 for ; Fri, 17 Jun 2022 15:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rHoG7dDbbfhrmS/H7yyWkxeJ8IoOLiAVzbc6Ovna8+k=; b=R6fJeeiGDlD/+1wHzUVq4ENJyd1RnOML0OI/ctbcTHyebaauRByqLOBT0DUIvMpHEC p+gjCqNGT1KuicvmkkPiQikpQJ7t31SNL3ISafSzGaoU74t6lHjq0QJB2NqnDadhFI22 C/3kvqRld8QD8XrcLlj0OHSEUOKviMJeE2FR5QhojpQJBb63FQSR7MZ/z9rot6kEkXwP 9HzP3v+4rTQr9G9p4/He/nV/643sWxqvFCz6pCoRGFc8wEE5+JKe8nZ+D6IyZN19s6wB pY6uESe2yb8Gr4zy8mw/XWK4O6YJ8HbrPXhwL+8ZrI3Fs0clbvvYeYMC7cpE/lFIZOfl i1Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rHoG7dDbbfhrmS/H7yyWkxeJ8IoOLiAVzbc6Ovna8+k=; b=FxFMTJ2sXyNStbRNlR5nVNHLSb7twL6t+k+59Z09M8SuDwkseFhfNdyWlDzpe7BLy8 miRYcIzhzQO9Jhc83sjVdZCDgowaT0iTSUBRN7cPxgjzDfW3HlvFVB3/lQwG6C/T2Nqh uWHk7Cjv2JNGuiTHOMMkgPxRJfDaFYgI6W9GDilgiAI15qTCEILO1eq8xTQ1WC9yIAwD LD5+lRnhtEsU6UM5V99t2Yl3DwhA2IjEQ24nuhsMKIUNfgrEFKYxyC4hZn+zqBdcXyF0 XzADTcrIbgnx8VDJq1X+gbwnhVsDAU4N1tYjqp2nxWbquKJGY23+8XlxQQvQ1leBeVI7 N4KQ== X-Gm-Message-State: AJIora9UAiJX85EXi0TS6AQbjgdsKhP0yzzzdENAYc8C+3JjxOR0ewUm Dholk5Fnx91k/eE4XgMq9raF3QG7bw72D6aqX2a5iQ== X-Received: by 2002:a25:c5c4:0:b0:664:8e1c:2fcf with SMTP id v187-20020a25c5c4000000b006648e1c2fcfmr13208362ybe.508.1655503542092; Fri, 17 Jun 2022 15:05:42 -0700 (PDT) MIME-Version: 1.0 References: <20220616211016.4037482-1-dylanbhatch@google.com> <941e0991-eb3e-f988-8262-3d51ff8badad@linuxfoundation.org> <47312e8a-87fe-c7dc-d354-74e81482bc1e@linuxfoundation.org> In-Reply-To: <47312e8a-87fe-c7dc-d354-74e81482bc1e@linuxfoundation.org> From: Dylan Hatch Date: Fri, 17 Jun 2022 15:05:30 -0700 Message-ID: Subject: Re: [PATCH] selftests/proc: Fix proc-pid-vm for vsyscall=xonly. To: Shuah Khan Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Fri, Jun 17, 2022 at 12:38 PM Shuah Khan wrote: > > On 6/17/22 12:45 PM, Dylan Hatch wrote: > > On Thu, Jun 16, 2022 at 4:01 PM Shuah Khan wrote: > >> > >> On 6/16/22 3:10 PM, Dylan Hatch wrote: > >>> This test would erroneously fail the /proc/$PID/maps case if > >>> vsyscall=xonly since the existing probe of the vsyscall page only > >>> succeeds if the process has read permissions. Fix this by checking for > >>> either no vsyscall mapping OR an execute-only vsyscall mapping in the > >>> case were probing the vsyscall page segfaults. > >>> > >> > >> Does this fix include skipping the test with a clear message that > >> says why test is skipped? > >> > >>> Signed-off-by: Dylan Hatch > >>> --- > >>> tools/testing/selftests/proc/proc-pid-vm.c | 20 +++++++++++++++----- > >>> 1 file changed, 15 insertions(+), 5 deletions(-) > >>> > >>> diff --git a/tools/testing/selftests/proc/proc-pid-vm.c b/tools/testing/selftests/proc/proc-pid-vm.c > >>> index 28604c9f805c..5ca85520131f 100644 > >>> --- a/tools/testing/selftests/proc/proc-pid-vm.c > >>> +++ b/tools/testing/selftests/proc/proc-pid-vm.c > >>> @@ -213,9 +213,12 @@ static int make_exe(const uint8_t *payload, size_t len) > >>> > >>> static bool g_vsyscall = false; > >>> > >>> -static const char str_vsyscall[] = > >>> +static const char str_vsyscall_rx[] = > >>> "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n"; > >>> > >>> +static const char str_vsyscall_x[] = > >>> +"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]\n"; > >>> + > >>> #ifdef __x86_64__ > >>> static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___) > >>> { > >>> @@ -261,6 +264,7 @@ int main(void) > >>> int exec_fd; > >>> > >>> vsyscall(); > >>> + const char *str_vsyscall = g_vsyscall ? str_vsyscall_rx : str_vsyscall_x; > >>> > >>> atexit(ate); > >>> > >>> @@ -314,7 +318,8 @@ int main(void) > >>> > >>> /* Test /proc/$PID/maps */ > >>> { > >>> - const size_t len = strlen(buf0) + (g_vsyscall ? strlen(str_vsyscall) : 0); > >>> + const size_t len_buf0 = strlen(buf0); > >>> + const size_t len_vsys = strlen(str_vsyscall); > >>> char buf[256]; > >>> ssize_t rv; > >>> int fd; > >>> @@ -325,11 +330,16 @@ int main(void) > >>> return 1; > >>> } > >>> rv = read(fd, buf, sizeof(buf)); > >>> - assert(rv == len); > >>> - assert(memcmp(buf, buf0, strlen(buf0)) == 0); > >>> if (g_vsyscall) { > >>> - assert(memcmp(buf + strlen(buf0), str_vsyscall, strlen(str_vsyscall)) == 0); > >>> + assert(rv == len_buf0 + len_vsys); > >>> + } else { > >>> + /* If vsyscall isn't readable, it's either x-only or not mapped at all */ > >>> + assert(rv == len_buf0 + len_vsys || rv == len_buf0); > >>> } > >>> + assert(memcmp(buf, buf0, len_buf0) == 0); > >>> + /* Check for vsyscall mapping if buf is long enough */ > >>> + if (rv == len_buf0 + len_vsys) > >>> + assert(memcmp(buf + len_buf0, str_vsyscall, len_vsys) == 0); > >>> } > >>> > >>> /* Test /proc/$PID/smaps */ > >>> > >> > >> The change looks good to me. Doesn't look like it skips the test though? > > > > Instead of skipping the test, it changes the passing condition to > > accept both cases of an unmapped vsyscall page and an x-only vsyscall > > page. Differentiating between these two cases without relying on > > /proc/$PID/maps would involve both checking the kernel command line > > for vsyscall=xonly and having a special ifdef block for > > CONFIG_VSYSCALL_XONLY, so accepting both as passing conditions seems > > like a simpler solution. > > > > It depends on the goal of the test. Is the test looking to see if the > probe fails with insufficient permissions, then you are changing the > test to not check for that condition. The goal of the test is to validate the output of /proc/$PID/maps, and the memory probe is only needed as setup to determine what the expected output should be. This used to be sufficient, but now it can no longer fully disambiguate it with the introduction of vsyscall=xonly. The solution proposed here is to disambiguate it by also checking the length read from /proc/$PID/maps. > > I would say in this case, the right approach would be to leave the test > as is and report expected fail and add other cases. > > The goal being adding more coverage and not necessarily opt for a simple > solution. What does it mean to report a test as expected fail? Is this a mechanism unique to kselftest? I agree adding another test case would work, but I'm unsure how to do it within the framework of kselftest. Ideally, there would be separate test cases for vsyscall=none, vsyscall=emulate, and vsyscall=xonly, but these options can be toggled both in the kernel config and on the kernel command line, meaning (to the best of my knowledge) these test cases would have to be built conditionally against the conflig options and also parse the command line for the 'vsyscall' option. Thanks, Dylan