From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F3C9C433FE for ; Thu, 21 Oct 2021 16:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E928F61359 for ; Thu, 21 Oct 2021 16:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231877AbhJUQSV (ORCPT ); Thu, 21 Oct 2021 12:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbhJUQST (ORCPT ); Thu, 21 Oct 2021 12:18:19 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA16C0613B9 for ; Thu, 21 Oct 2021 09:16:03 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id f5so736715pgc.12 for ; Thu, 21 Oct 2021 09:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vP39j9ADitfQOHN+zI1j9ZwqqZWQBsDUBPCRK2KL/kw=; b=BxznGOQ/wzmBK7sBg1f0kltBGxiqMcUJY96yfRg5sDBfwda0Au3MEYhLIQYXBrAh29 w8M8sjJCfbHisxxMGjvz0gTJArsePF8uLuWr80z78Ls2wpZtyTrzCUlOiB//HsTEHfGh Ji05YrCVxt9dwaOXBMkJofvsNIs4FxFgTspLU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vP39j9ADitfQOHN+zI1j9ZwqqZWQBsDUBPCRK2KL/kw=; b=3iX68S21a0HEFMyfoZKEwzPGA+VGCMSN6k+LohKTrLdnjFzhj3V9ZoNmoiP+9Df1nZ uUWYvizOFvnUad1IcOFkO1/opg7Vw4gHWcbvZhLZRfL3oK9ua/Iaj5lSDn9wWWNRreQp Jrpy6eXiFkTt/tpPVvv41Y0Q/SkEqb+gdm4H4RBMlHEZ8djyUTqZnLyFI9A5wWzi5aag /tkCPXhn9HH4FFuA4z1Jz9Q2n5dbmfcyaEz88Ql8g53C8zrqvJyCk7+DVd6PNciri2IK Ou2DAHJJm4wSKYp+EEP+y6FFUYXEeH4Rtd1XNHwIP4S2R7KgsxhrVOL1FYLNMw5xkYa+ BLmw== X-Gm-Message-State: AOAM530F7uoWtcIq33Z1Qnd27II6z+KPpQryX4oRbRYjTR2sNCgUCGpl 7q/GjAAgBDObQNyKKIgusF/TjA== X-Google-Smtp-Source: ABdhPJy70NkI/iYHxiXKXmeWuvWywNZofk1XVFZpw6KXyv0Q/EsYUPnI6CkUR0hARZPpFGr3tLAeRA== X-Received: by 2002:a62:188c:0:b0:44d:6660:212b with SMTP id 134-20020a62188c000000b0044d6660212bmr6691706pfy.8.1634832963309; Thu, 21 Oct 2021 09:16:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s62sm6005310pgc.5.2021.10.21.09.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 09:16:03 -0700 (PDT) Date: Thu, 21 Oct 2021 09:16:02 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Al Viro , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, H Peter Anvin Subject: Re: [PATCH 10/20] signal/vm86_32: Properly send SIGSEGV when the vm86 state cannot be saved. Message-ID: <202110210915.BF17C14980@keescook> References: <87y26nmwkb.fsf@disp2133> <20211020174406.17889-10-ebiederm@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211020174406.17889-10-ebiederm@xmission.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 20, 2021 at 12:43:56PM -0500, Eric W. Biederman wrote: > Instead of pretending to send SIGSEGV by calling do_exit(SIGSEGV) > call force_sigsegv(SIGSEGV) to force the process to take a SIGSEGV > and terminate. > > Update handle_signal to return immediately when save_v86_state fails > and kills the process. Returning immediately without doing anything > except killing the process with SIGSEGV is also what signal_setup_done > does when setup_rt_frame fails. Plus it is always ok to return > immediately without delivering a signal to a userspace handler when a > fatal signal has killed the current process. Do the tools/testing/selftests/x86 tests all pass after these changes? I know Andy has a bunch of weird corner cases in there. Reviewed-by: Kees Cook > > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: x86@kernel.org > Cc: H Peter Anvin > Signed-off-by: "Eric W. Biederman" > --- > arch/x86/kernel/signal.c | 6 +++++- > arch/x86/kernel/vm86_32.c | 2 +- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c > index f4d21e470083..25a230f705c1 100644 > --- a/arch/x86/kernel/signal.c > +++ b/arch/x86/kernel/signal.c > @@ -785,8 +785,12 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs) > bool stepping, failed; > struct fpu *fpu = ¤t->thread.fpu; > > - if (v8086_mode(regs)) > + if (v8086_mode(regs)) { > save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL); > + /* Has save_v86_state failed and killed the process? */ > + if (fatal_signal_pending(current)) > + return; > + } > > /* Are we from a system call? */ > if (syscall_get_nr(current, regs) != -1) { > diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c > index 63486da77272..040fd01be8b3 100644 > --- a/arch/x86/kernel/vm86_32.c > +++ b/arch/x86/kernel/vm86_32.c > @@ -159,7 +159,7 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval) > user_access_end(); > Efault: > pr_alert("could not access userspace vm86 info\n"); > - do_exit(SIGSEGV); > + force_sigsegv(SIGSEGV); > } > > static int do_vm86_irq_handling(int subfunction, int irqnumber); > -- > 2.20.1 > -- Kees Cook