From patchwork Fri Mar 1 00:18:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 10834311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A09E51399 for ; Fri, 1 Mar 2019 00:18:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 929EC2F8F3 for ; Fri, 1 Mar 2019 00:18:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85FE12F8FE; Fri, 1 Mar 2019 00:18:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A67C2F8F3 for ; Fri, 1 Mar 2019 00:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732086AbfCAASU (ORCPT ); Thu, 28 Feb 2019 19:18:20 -0500 Received: from mail-it1-f202.google.com ([209.85.166.202]:55957 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731073AbfCAASU (ORCPT ); Thu, 28 Feb 2019 19:18:20 -0500 Received: by mail-it1-f202.google.com with SMTP id y70so9516096itc.5 for ; Thu, 28 Feb 2019 16:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=ckaseLFdofbQ5QZGTQteyCQVA192m0GtDd/BtCB/7D4=; b=vbm/nZVubPtmg2BCqxYAN+ZpNkTWhTl31PuCtOuoVDZKdslFL395h39/guMHtQmavQ krNkaIHMKUT7NvlnpbhrT49dLMXc15A6+P35+ZF67pOTGHuETKo9awfgo/lAj+CUvG6k jFI0CLCk5juCpWnDhGzP5FytWJh0JII/+2SK36jl7PPUz/1Q3ouLH1+1w0XzspczArAb /7xf05DR1E/i7MaxSNxpVKRW7r2g3uvVtSRrGg6+vLh9Kx/v/nBwOBz7/pF4Bl4kgwnu R0q6J+/IaG3XjyN9sF+aCIEU/EC8xk5ymt8BMQcEawBwE6ODD/HgQmesbGkiSHEOhD5R Vqmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=ckaseLFdofbQ5QZGTQteyCQVA192m0GtDd/BtCB/7D4=; b=NihpKvS3hMSLa4P46OIK0fZrA5OTt+pu27xNcVMKVuN84kQy9yO8Rs8yUprh+KepaW ytBz+hvbPaCwLKvLoUG1K8nexXPcB4M/eK/XwjmcoS/UqBac3FKhylZi4W0h+H5LSeDC sP7E7Mwu5si2iFAEETU3GdQA/W0hTACTZlDzQ9Ibpi3xewfSsSnAbua1y91+6sGub6ER wwIC5W4t84ovWXOlzevfNMlU5DgGTIAtO9iJC8Ie5hX/99GF6wvyzKFcjiLw2OlLUP9G FQL9sYvVYEGxYs2R8pjvUH748Nm7V7TAiTXA6gUj1hSbRg0gWP4e0YehCm9vL/FGS1NN 2Lbw== X-Gm-Message-State: APjAAAXL3oO/Jn6RB6gHY/jcJX6hqSwBG/xSKGOy5JxgaKNe2uRo5Tlf TbeugVZKgyHSdmY6MSVlZcoYPVNQKtl/ X-Google-Smtp-Source: APXvYqyhgNWVYVeh8ZMWn1SkZbUx5UDVRrta3X2Kyv0Wl9pfvDFEbTP/ZgOOtb1Yq3v00891XFx4va5aW16T X-Received: by 2002:a24:6f55:: with SMTP id x82mr1632135itb.13.1551399499719; Thu, 28 Feb 2019 16:18:19 -0800 (PST) Date: Thu, 28 Feb 2019 16:18:06 -0800 Message-Id: <20190301001806.154271-1-smuckle@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog Subject: [PATCH] selftests: x86: add version check in test_syscall_vdso From: Steve Muckle To: Shuah Khan , Andy Lutomirski , Thomas Gleixner , linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Steve Muckle Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since 4.17 registers r8-r11 are not clobbered/zeroed by a 64-bit kernel handling a 32-bit syscall and this behavior is enforced by the test_syscall_vdso testcase. See commit 8bb2610bc496 ("x86/entry/64/compat: Preserve r8-r11 in int $0x80"). Permit the old behavior in the testcase for kernels prior to 4.17. Signed-off-by: Steve Muckle --- .../testing/selftests/x86/test_syscall_vdso.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c b/tools/testing/selftests/x86/test_syscall_vdso.c index c9c3281077bc..f7284dc4c32b 100644 --- a/tools/testing/selftests/x86/test_syscall_vdso.c +++ b/tools/testing/selftests/x86/test_syscall_vdso.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #if !defined(__i386__) @@ -71,6 +72,7 @@ struct regs64 { }; struct regs64 regs64; int kernel_is_64bit; +int clobber_ok; asm ( " .pushsection .text\n" @@ -130,6 +132,28 @@ void print_regs64(void) printf("12:%016llx 13:%016llx 14:%016llx 15:%016llx\n", regs64.r12, regs64.r13, regs64.r14, regs64.r15); } +static void get_kernel_version(int *version, int *patchlevel) +{ + int ret, sublevel; + struct utsname utsname; + + ret = uname(&utsname); + if (ret) { + perror("uname"); + exit(1); + } + + ret = sscanf(utsname.release, "%d.%d.%d", version, patchlevel, + &sublevel); + if (ret < 0) { + perror("sscanf"); + exit(1); + } else if (ret != 3) { + printf("Malformed kernel version %s\n", &utsname.release); + exit(1); + } +} + int check_regs64(void) { int err = 0; @@ -166,6 +190,8 @@ int check_regs64(void) * Historically (and probably unintentionally), they * were clobbered or zeroed. */ + if (clobber_ok && *r64 == 0 && num <= 11) + continue; } printf("[FAIL]\tR%d has changed:%016llx\n", num, *r64); err++; @@ -385,6 +411,7 @@ int main(int argc, char **argv, char **envp) { int exitcode = 0; int cs; + int version, patchlevel; asm("\n" " movl %%cs, %%eax\n" @@ -394,6 +421,9 @@ int main(int argc, char **argv, char **envp) if (!kernel_is_64bit) printf("[NOTE]\tNot a 64-bit kernel, won't test R8..R15 leaks\n"); + get_kernel_version(&version, &patchlevel); + clobber_ok = version < 4 || (version == 4 && patchlevel < 17); + /* This only works for non-static builds: * syscall_addr = dlsym(dlopen("linux-gate.so.1", RTLD_NOW), "__kernel_vsyscall"); */