Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2337268imm; Thu, 11 Oct 2018 08:43:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV630cXdB5/CkXxm9kZlrDoQBN2dYtG8pwGgPuKoMsNzS4uA0Z/j+gOMREKeRv8tqSlGgkEc+ X-Received: by 2002:a17:902:8609:: with SMTP id f9-v6mr2083368plo.134.1539272620742; Thu, 11 Oct 2018 08:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539272620; cv=none; d=google.com; s=arc-20160816; b=IhY3ea2s4dD3Pos6tUvxqJQkFPlgKRm/E1a8fRNmqQUV2T7e2PZA9Jy2hnrt7MUHoG yPEJYDGM2l9/mLgQVnJhTiIoywr/81+mMmGLGxGa1IjGI+Mw2TvElbOOw1Qsj/pwoIib CdQpK/WSZXzXmp2Hx0lWQ+4op2S7gLm3ZpaJLU15OzAs141+0V/qSCeogN9RzDun7mfh J+eMJfiBey4IEjTbvoayVFjZFOwc196uwjmsnzbN3hmBZIY+yavtdF/b3+LwwHUQ08ly vZ+w671YiHmFlL4WhGZiOAmEhM+XgFcsgDzAfyEhlYowg8SiQ0aUYswKarhLrxPCAhWK 9XOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ahNovvjlcsSPWQUooTCqgTz/VDEcreWxoBpVkmRAGG8=; b=o1VwLWZVvmrH9I1lcFsvxJ6WQHT4tCJwzS3jSns+m/JJiOTjGRr188+fIB54cdw2Lk 0hyPJtt2jFHleq3jfyeO2n9msofkr/jvujhtTpV0YzdYp2J9j9dhgsMD0Y2ZMIFy4A3V D9GdRXJDsRzxymGLBR1DeX98NSrnHly1151yqyx9j3AyguXtt4tULGpU4QF8PBw1yf+L 3rxaffX3m7mSvZGJ7DOVHRwu/lE/XIVJbBBpBuIzQAXFYZt4tp43qTGLxXm3yi8a5Hit 5y+u3obvnXxh0VwuvOigTMS6ikATao2hdCrDADQIy6JQ8AvbfPQp+Rd7veF04qag9nKt itdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a5Lt89G2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c31-v6si27426506pgb.348.2018.10.11.08.43.26; Thu, 11 Oct 2018 08:43:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a5Lt89G2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730717AbeJKXKO (ORCPT + 99 others); Thu, 11 Oct 2018 19:10:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbeJKXKO (ORCPT ); Thu, 11 Oct 2018 19:10:14 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5AA50213A2; Thu, 11 Oct 2018 15:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539272549; bh=1FZE+VPbiWcKRzmU4rUdBxi2ACF0yPoCU5tIsY2WDAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5Lt89G24AYdCgqMCJKOESa6a+lzwMSQTr5p6bZ21F8abYlupGnT64N1oefdnyKYx 0apsaM2t2qiN/d/o98R3Hmvyqtvg4Z0vVwFcZicTO9vxbSUn1ftmuzEHaZWIdOvZly cx6lOsBS95z0tqkDlqJrSELF4dkaGJVMw37ic81w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Thomas Gleixner Subject: [PATCH 4.4 03/27] x86/vdso: Fix asm constraints on vDSO syscall fallbacks Date: Thu, 11 Oct 2018 17:34:50 +0200 Message-Id: <20181011152534.181196336@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181011152534.014964888@linuxfoundation.org> References: <20181011152534.014964888@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit 715bd9d12f84d8f5cc8ad21d888f9bc304a8eb0b upstream. The syscall fallbacks in the vDSO have incorrect asm constraints. They are not marked as writing to their outputs -- instead, they are marked as clobbering "memory", which is useless. In particular, gcc is smart enough to know that the timespec parameter hasn't escaped, so a memory clobber doesn't clobber it. And passing a pointer as an asm *input* does not tell gcc that the pointed-to value is changed. Add in the fact that the asm instructions weren't volatile, and gcc was free to omit them entirely unless their sole output (the return value) is used. Which it is (phew!), but that stops happening with some upcoming patches. As a trivial example, the following code: void test_fallback(struct timespec *ts) { vdso_fallback_gettime(CLOCK_MONOTONIC, ts); } compiles to: 00000000000000c0 : c0: c3 retq To add insult to injury, the RCX and R11 clobbers on 64-bit builds were missing. The "memory" clobber is also unnecessary -- no ordering with respect to other memory operations is needed, but that's going to be fixed in a separate not-for-stable patch. Fixes: 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu") Signed-off-by: Andy Lutomirski Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/2c0231690551989d2fafa60ed0e7b5cc8b403908.1538422295.git.luto@kernel.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/vdso/vclock_gettime.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -51,8 +51,9 @@ extern u8 pvclock_page notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) { long ret; - asm("syscall" : "=a" (ret) : - "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : "memory"); + asm ("syscall" : "=a" (ret), "=m" (*ts) : + "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : + "memory", "rcx", "r11"); return ret; } @@ -60,8 +61,9 @@ notrace static long vdso_fallback_gtod(s { long ret; - asm("syscall" : "=a" (ret) : - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory"); + asm ("syscall" : "=a" (ret), "=m" (*tv), "=m" (*tz) : + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : + "memory", "rcx", "r11"); return ret; } @@ -143,12 +145,12 @@ notrace static long vdso_fallback_gettim { long ret; - asm( + asm ( "mov %%ebx, %%edx \n" "mov %2, %%ebx \n" "call __kernel_vsyscall \n" "mov %%edx, %%ebx \n" - : "=a" (ret) + : "=a" (ret), "=m" (*ts) : "0" (__NR_clock_gettime), "g" (clock), "c" (ts) : "memory", "edx"); return ret; @@ -158,12 +160,12 @@ notrace static long vdso_fallback_gtod(s { long ret; - asm( + asm ( "mov %%ebx, %%edx \n" "mov %2, %%ebx \n" "call __kernel_vsyscall \n" "mov %%edx, %%ebx \n" - : "=a" (ret) + : "=a" (ret), "=m" (*tv), "=m" (*tz) : "0" (__NR_gettimeofday), "g" (tv), "c" (tz) : "memory", "edx"); return ret;