Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6014019ybc; Wed, 27 Nov 2019 13:24:34 -0800 (PST) X-Google-Smtp-Source: APXvYqyOETEFhHOeWHcReJRxrHhz4KwknaUECLXP9qlPU/8sx0UyYAXqajtfdifuMbK4cO/Gq46/ X-Received: by 2002:a17:906:edc4:: with SMTP id sb4mr3094819ejb.113.1574889874098; Wed, 27 Nov 2019 13:24:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889874; cv=none; d=google.com; s=arc-20160816; b=TLcsVO11Sw3SzSBHsf4dGErKrsmGBsuAqiTUsWsRlQ4YOVMeYlE4bVn/fgucp6uPSp FcmpwjxuhQ+Tn2f5eFHWgT0Uej2Cj6raC/xN0mtz4F5x8R9pxhuc3cFT+1dkW1PDRAmO dhRzz5m409DGH7wnCf9oxgJlpKqA3lJWMCniI4stwP66N0qmxPUWzP7xNRJMR0W80Ym8 QQUrnGgHhDiirm7hQG8oHu1Z5/G8Bha0vr7AtyWWWpwCt70VisGwAPvVKl3Q625fs++M T//RidbbVuBxH01TcBbfuhlq4XDzaEwP+VXn60gtp4/MZb9f3opxeymWgx3iR3FsX1ON tHNQ== 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=PQ1BsodEop4STPa5mpYMNlyamOgX+76IyJ6dZ6nef1k=; b=QbUwxUUVRyQkkMMm2/+5JCmF8G9U4eGMAWV4j4R09Rm2B13ZlUuJ5hqLa5GxON31sT DS6OS+9iR1OtqI+R2+xrdpUjxt6aylT/NaUC9MO8P0v08kunEDYBTFYWsGAuaSqgbfFk x8v53sEoThLkz3wAoD0vtl4fSfl7X8zC47HFLwouk++l0FCgWUUrSpFlTqpql5sqmBAI fAmdT8tXRnERKbfnI5L6hUeZulXjvxGOKmV7UEnB1V+iDTPQik91dzAHMeTGQXzowHdT NIXtR7+dq/Sj1jdU4CN5A6Wk17PL8KTw7CMFx8TfUESpVA8hYRFlZ53t+6w0Pf2VfliE IkyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rC+FIWeM; 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 e22si9702325ejj.234.2019.11.27.13.24.10; Wed, 27 Nov 2019 13:24:34 -0800 (PST) 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=rC+FIWeM; 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 S1732507AbfK0VGw (ORCPT + 99 others); Wed, 27 Nov 2019 16:06:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:32774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731541AbfK0VGr (ORCPT ); Wed, 27 Nov 2019 16:06:47 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C4D742086A; Wed, 27 Nov 2019 21:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888807; bh=r7xPYCGuPsGo1R+yB7dlU0oOx4E2V9pZb45mLGsJmn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rC+FIWeMdBKzQsPUFIoP5DUn0iSBufKTI1yYEd4J+Glxzic+k2DAIvcuWhwxcgcyl TLQaPOff58I8aSqqFBULJrTk4OZwccHh0TrvxlIQ8mFKcyZUQHna/kv8bWlfuWuKfq KaEQI9fIJd8T5BlttQ6Y7KOfrEEmpJArBprZfrqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , "Peter Zijlstra (Intel)" , stable@kernel.org Subject: [PATCH 4.19 275/306] selftests/x86/sigreturn/32: Invalidate DS and ES when abusing the kernel Date: Wed, 27 Nov 2019 21:32:05 +0100 Message-Id: <20191127203134.896461776@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Andy Lutomirski commit 4d2fa82d98d2d296043a04eb517d7dbade5b13b8 upstream. If the kernel accidentally uses DS or ES while the user values are loaded, it will work fine for sane userspace. In the interest of simulating maximally insane userspace, make sigreturn_32 zero out DS and ES for the nasty parts so that inadvertent use of these segments will crash. Signed-off-by: Andy Lutomirski Signed-off-by: Peter Zijlstra (Intel) Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/sigreturn.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/tools/testing/selftests/x86/sigreturn.c +++ b/tools/testing/selftests/x86/sigreturn.c @@ -459,6 +459,19 @@ static void sigusr1(int sig, siginfo_t * ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL; ctx->uc_mcontext.gregs[REG_CX] = 0; +#ifdef __i386__ + /* + * Make sure the kernel doesn't inadvertently use DS or ES-relative + * accesses in a region where user DS or ES is loaded. + * + * Skip this for 64-bit builds because long mode doesn't care about + * DS and ES and skipping it increases test coverage a little bit, + * since 64-bit kernels can still run the 32-bit build. + */ + ctx->uc_mcontext.gregs[REG_DS] = 0; + ctx->uc_mcontext.gregs[REG_ES] = 0; +#endif + memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t)); requested_regs[REG_CX] = *ssptr(ctx); /* The asm code does this. */