Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp768898iog; Fri, 17 Jun 2022 13:14:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uOOwxKr5W/Rhxy2LgrVWxlxyM6DyZAaysv2rP74UlgiN5P3mOQLGbmnHu1P+12F3N4Pckw X-Received: by 2002:a17:90a:f288:b0:1ec:7f71:b05f with SMTP id fs8-20020a17090af28800b001ec7f71b05fmr3041851pjb.184.1655496859076; Fri, 17 Jun 2022 13:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655496859; cv=none; d=google.com; s=arc-20160816; b=eRaCjpEP7xNiRgNH7YSAat/uv016J6bETm2f3CW0FN5E/0PZc1PAUtN/JCazjB2L5W BT9vgEsZNnPYuEEuiqoPSTO/mhimlUHSnK3atSUYOB5qRzK7fF9yObbwlvkpUKdTbU2w A+vA2nYG+UuvaNk2YVXOW5sep/eWXJn2ptAzQDgS3vTtMW8R0f73EBK2dDmg7Ns2YGtB zmh6w9PF1G/wo7A+nf7U4v2VMYstzRqOPMetiunBeW9KRsts4UcaaRn/9hPtm5dN0BPr xm12yJ83FxDyCzyeWP1GTVoqEqS+08hTe032y3HvdQ7EXBVM0rYoo+N8LAqn+YCLRG+0 f4kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=wmbuV7JBORPXXzvNtfIZq/lTzS3aE7SHxRte41av5uM=; b=AOJbn4XHOsDlUgEmwONI62u9o49N8pzC+BQMIfvHTVLKIF+WrcTPklThuqQhchiTmE 5qE0+Haw5fZt4eEYWWl5WgqP8BgaXy2q+XRUcwGYOmL2eXuEkB9sIV9EznKsjwfZQls0 ZljtFqxBCw1Z9PLRQTNEzsrQ68xcfWTV7W9TqeCKytJT4//oXz+gp1fn1vqtV0yyUtzr Qho+7w+oSRy3BuzvRT26/YSLNSial7Oa1N+NWhEJ4wWeAFtEVfF3C0qVcQPrk5fl7XP9 WTu8tHmqQikObTy9PbCeM3HP11Hn5k1ljWexwtVgWV4TrGutIzWiohNZwPpFte5gCycD gPQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=E0B1WMNG; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a170902700100b001586fbb2b6dsi3423775plk.566.2022.06.17.13.14.07; Fri, 17 Jun 2022 13:14:19 -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=@linuxfoundation.org header.s=google header.b=E0B1WMNG; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238497AbiFQTin (ORCPT + 99 others); Fri, 17 Jun 2022 15:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242248AbiFQTiX (ORCPT ); Fri, 17 Jun 2022 15:38:23 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A2032F028 for ; Fri, 17 Jun 2022 12:38:21 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id h7so3612068ila.10 for ; Fri, 17 Jun 2022 12:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wmbuV7JBORPXXzvNtfIZq/lTzS3aE7SHxRte41av5uM=; b=E0B1WMNGy43PvdJGAw2GYGQ5aKuCRPlGDVLSnor2QZJNSRe5zTPsqxbwe6DludNLxs R4wYYbLa/fc/Ecl0bf0NnRRH8HbpYCn+8yNpx2sS/CcpcFAfgg29nSpNUvdaE7ZyKLUe X2pIoc6EroL/LYddX/FkGtSPgP77qKkI6tr/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wmbuV7JBORPXXzvNtfIZq/lTzS3aE7SHxRte41av5uM=; b=rAYkW/YLjZX3TiY8Pp5DfozEIDR6TuhSnZPZ6LITMd7pYmV4S8xovwTTXdgz3vneLS GEt07MOphfQSJNNdJcjiWixenbM2Ma58ECuiOW2nWK4vzT51Ira/nF/OiTkvtL1//k5R GEy0P5FdyEEqjijC8w96OpdhBvLbZibbqVSis0e/kYnSLr4IpPb4KoeWlbbCGPTHyqxG BzHqXFJWnd0tg6K4oM61DdFTn6Xrs5X8LBrBRajkKd39MceAY7+ms280sKKLZlLObHx7 IWc4qOCafy2JIt0O1EZw2wa6UQoyeeoY+3XR68IxM71eN1PT29Oq3B5TqbwQh42PLm9A DiRg== X-Gm-Message-State: AJIora/PJ313Z2wbfx25xT7+AFq/deIsyZvT2NhehX+3xzl/neTau2Oi Y3liJ72Wx/sJSzhq9LbAGG/NZA== X-Received: by 2002:a05:6e02:1a23:b0:2d3:82bb:4dae with SMTP id g3-20020a056e021a2300b002d382bb4daemr6485677ile.62.1655494700776; Fri, 17 Jun 2022 12:38:20 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id m2-20020a6bbc02000000b006656f9eefa3sm2917727iof.18.2022.06.17.12.38.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jun 2022 12:38:20 -0700 (PDT) Subject: Re: [PATCH] selftests/proc: Fix proc-pid-vm for vsyscall=xonly. To: Dylan Hatch Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan References: <20220616211016.4037482-1-dylanbhatch@google.com> <941e0991-eb3e-f988-8262-3d51ff8badad@linuxfoundation.org> From: Shuah Khan Message-ID: <47312e8a-87fe-c7dc-d354-74e81482bc1e@linuxfoundation.org> Date: Fri, 17 Jun 2022 13:38:19 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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. 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. thanks, -- Shuah