Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2015829ybb; Thu, 26 Mar 2020 19:39:03 -0700 (PDT) X-Received: by 2002:a4a:9451:: with SMTP id j17mr7521419ooi.30.1585276502291; Thu, 26 Mar 2020 19:35:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuF4gM8gMZR3VFNNnPSvjBf9wRFG15IzgYH36+gtxCoSCUON7atPVcimE71t8a70mxuNvEb X-Received: by 2002:a4a:9451:: with SMTP id j17mr7521392ooi.30.1585276501629; Thu, 26 Mar 2020 19:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585276501; cv=none; d=google.com; s=arc-20160816; b=k9eBrOmjA4BKRCzOBFcn+khp3nHEhK/zQa3bQekAAPKFPJcwirM04OolNPrY9NFG8A lUVo4vBhrVNezoS+V22Hk+pBSYFc3sMtz86Onwd8x1ulCXXR5oFVXS31vwLbBVjAtx3s GuEgRgqw4iDQ0GTSAptGzEM+BEnEzbaCl2eWDkJE+5lePRciWiAwMYLxALr/fux+Rpk7 r6muKug3reYcZrrFQMw5pbuDu0Jk6pSMCC/CdyzbEnctTRb/B4j3E+EzP46oOEHjIpwP qQ5/KaGxPbwlqZ+mlIsa1vQmfODdodyN8GvRdY5FxjBz+yhGssDhslsywjZ5HqMbTD76 7lCg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RM4taE6LyHEXRZ4d5Fp/KcO0U+HS/xwaugmbJX4Q4KE=; b=tAwGZMGS1J3Y4UFYt42u+AztEw1RQDiJ7dx2JIBSLsaXOUdmQi2mqyae9EczY69oj/ F2UsKLMtaJjTsb95zlRBTHCAVKV71SHRszbVz3lUGSgMoibiFsyLIEHoIitj+ltWpbN9 l/38EydmFN0LuwzK1ADfccNJtCvfHnntzGrwmMkvHRbyA/EBOnEofL49nOxp81ByVj48 XXOETIh6DjU2fj+EgdLPg0uzqftM7y+QuBB2bfwrWX1IkqVZ0zV2HagLqWdVsZsY46m3 MmL+yNej8QTgwdFhNjIk/8OH+teQOXxxLIuVuylqph1UmfhPRohphTpyUSCJecT9Wu1Q qUrA== ARC-Authentication-Results: i=1; mx.google.com; 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 z23si1862907oih.275.2020.03.26.19.34.49; Thu, 26 Mar 2020 19:35:01 -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; 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 S1728056AbgC0CdF (ORCPT + 99 others); Thu, 26 Mar 2020 22:33:05 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:48034 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgC0CcK (ORCPT ); Thu, 26 Mar 2020 22:32:10 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jHen0-003hRX-BS; Fri, 27 Mar 2020 02:32:06 +0000 From: Al Viro To: Linus Torvalds Cc: Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC][PATCH v2 09/22] x86: switch save_v86_state() to unsafe_put_user() Date: Fri, 27 Mar 2020 02:31:52 +0000 Message-Id: <20200327023205.881896-9-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200327023205.881896-1-viro@ZenIV.linux.org.uk> References: <20200327023007.GS23230@ZenIV.linux.org.uk> <20200327023205.881896-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro Signed-off-by: Al Viro --- arch/x86/kernel/vm86_32.c | 61 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c index 49b37eb01e99..47a8676c7395 100644 --- a/arch/x86/kernel/vm86_32.c +++ b/arch/x86/kernel/vm86_32.c @@ -98,7 +98,6 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval) struct task_struct *tsk = current; struct vm86plus_struct __user *user; struct vm86 *vm86 = current->thread.vm86; - long err = 0; /* * This gets called from entry.S with interrupts disabled, but @@ -114,37 +113,30 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval) set_flags(regs->pt.flags, VEFLAGS, X86_EFLAGS_VIF | vm86->veflags_mask); user = vm86->user_vm86; - if (!access_ok(user, vm86->vm86plus.is_vm86pus ? + if (!user_access_begin(user, vm86->vm86plus.is_vm86pus ? sizeof(struct vm86plus_struct) : - sizeof(struct vm86_struct))) { - pr_alert("could not access userspace vm86 info\n"); - do_exit(SIGSEGV); - } - - put_user_try { - put_user_ex(regs->pt.bx, &user->regs.ebx); - put_user_ex(regs->pt.cx, &user->regs.ecx); - put_user_ex(regs->pt.dx, &user->regs.edx); - put_user_ex(regs->pt.si, &user->regs.esi); - put_user_ex(regs->pt.di, &user->regs.edi); - put_user_ex(regs->pt.bp, &user->regs.ebp); - put_user_ex(regs->pt.ax, &user->regs.eax); - put_user_ex(regs->pt.ip, &user->regs.eip); - put_user_ex(regs->pt.cs, &user->regs.cs); - put_user_ex(regs->pt.flags, &user->regs.eflags); - put_user_ex(regs->pt.sp, &user->regs.esp); - put_user_ex(regs->pt.ss, &user->regs.ss); - put_user_ex(regs->es, &user->regs.es); - put_user_ex(regs->ds, &user->regs.ds); - put_user_ex(regs->fs, &user->regs.fs); - put_user_ex(regs->gs, &user->regs.gs); - - put_user_ex(vm86->screen_bitmap, &user->screen_bitmap); - } put_user_catch(err); - if (err) { - pr_alert("could not access userspace vm86 info\n"); - do_exit(SIGSEGV); - } + sizeof(struct vm86_struct))) + goto Efault; + + unsafe_put_user(regs->pt.bx, &user->regs.ebx, Efault_end); + unsafe_put_user(regs->pt.cx, &user->regs.ecx, Efault_end); + unsafe_put_user(regs->pt.dx, &user->regs.edx, Efault_end); + unsafe_put_user(regs->pt.si, &user->regs.esi, Efault_end); + unsafe_put_user(regs->pt.di, &user->regs.edi, Efault_end); + unsafe_put_user(regs->pt.bp, &user->regs.ebp, Efault_end); + unsafe_put_user(regs->pt.ax, &user->regs.eax, Efault_end); + unsafe_put_user(regs->pt.ip, &user->regs.eip, Efault_end); + unsafe_put_user(regs->pt.cs, &user->regs.cs, Efault_end); + unsafe_put_user(regs->pt.flags, &user->regs.eflags, Efault_end); + unsafe_put_user(regs->pt.sp, &user->regs.esp, Efault_end); + unsafe_put_user(regs->pt.ss, &user->regs.ss, Efault_end); + unsafe_put_user(regs->es, &user->regs.es, Efault_end); + unsafe_put_user(regs->ds, &user->regs.ds, Efault_end); + unsafe_put_user(regs->fs, &user->regs.fs, Efault_end); + unsafe_put_user(regs->gs, &user->regs.gs, Efault_end); + unsafe_put_user(vm86->screen_bitmap, &user->screen_bitmap, Efault_end); + + user_access_end(); preempt_disable(); tsk->thread.sp0 = vm86->saved_sp0; @@ -159,6 +151,13 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval) lazy_load_gs(vm86->regs32.gs); regs->pt.ax = retval; + return; + +Efault_end: + user_access_end(); +Efault: + pr_alert("could not access userspace vm86 info\n"); + do_exit(SIGSEGV); } static void mark_screen_rdonly(struct mm_struct *mm) -- 2.11.0