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 X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 654E4C433F1 for ; Fri, 10 Jul 2020 13:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44091207BB for ; Fri, 10 Jul 2020 13:57:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="J8rLfCX1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgGJN5b (ORCPT ); Fri, 10 Jul 2020 09:57:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727820AbgGJN5U (ORCPT ); Fri, 10 Jul 2020 09:57:20 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 013EBC08C5CE; Fri, 10 Jul 2020 06:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=aA679qIodiBpC5vbULiwbVKx3fOumlOYyYuEKhecoTI=; b=J8rLfCX1rWf4qIqs7Fehj0+jKo yFGyNk3e2uoFfcZNf1M3QeOGq9VbqUAG1y/PYra5V0SIxrUWAwCu3uW+BJaS/Pwv3/8olCOUwaISR IzGHg2ZiC44cAjsnSoeRLVXSMLQl5JmaLOP3499goZFgz41YKHPUQeT39S+sSuaRHO3bsRu1NLGXG uSojzqVKeQZM3R7LwQUsgnW8GLAnNu7ji/KAnFGWmGbnav9Xt6xkmih3kL2vhPbPf2/nPbbdeIrJF K+1WaWDgCw8lmWG0M+4MbXaq2f53/gz7dYZ+z068PuxxTULd6ySpB8UbVjA8oK+jDsYm3hDSvxzZz IcdeQBCQ==; Received: from [2001:4bb8:188:5f50:c70:4a89:bc61:2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jttWd-0004hr-1S; Fri, 10 Jul 2020 13:57:15 +0000 From: Christoph Hellwig To: Nick Hu , Greentime Hu , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Andrew Morton , Linus Torvalds Cc: linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] exec: use force_uaccess_begin during exec and exit Date: Fri, 10 Jul 2020 15:57:06 +0200 Message-Id: <20200710135706.537715-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200710135706.537715-1-hch@lst.de> References: <20200710135706.537715-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both exec and exit want to ensure that the uaccess routines actually do access user pointers. Use the newly added force_uaccess_begin helper instead of an open coded set_fs for that to prepare for kernel builds where set_fs() does not exist. Signed-off-by: Christoph Hellwig --- fs/exec.c | 7 ++++++- kernel/exit.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index e6e8a9a7032784..769af470b69124 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1380,7 +1380,12 @@ int begin_new_exec(struct linux_binprm * bprm) if (retval) goto out_unlock; - set_fs(USER_DS); + /* + * Ensure that the uaccess routines can actually operate on userspace + * pointers: + */ + force_uaccess_begin(); + me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD | PF_NOFREEZE | PF_NO_SETAFFINITY); flush_thread(); diff --git a/kernel/exit.c b/kernel/exit.c index 727150f2810338..17d486a20f0dc6 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -731,7 +731,7 @@ void __noreturn do_exit(long code) * mm_release()->clear_child_tid() from writing to a user-controlled * kernel address. */ - set_fs(USER_DS); + force_uaccess_begin(); if (unlikely(in_atomic())) { pr_info("note: %s[%d] exited with preempt_count %d\n", -- 2.26.2