From patchwork Fri Sep 18 12:45:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11784809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9A0E14F6 for ; Fri, 18 Sep 2020 12:46:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD6652376F for ; Fri, 18 Sep 2020 12:46:01 +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="s9ZOEgea" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD6652376F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE949900005; Fri, 18 Sep 2020 08:45:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C9896900003; Fri, 18 Sep 2020 08:45:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 966CB900003; Fri, 18 Sep 2020 08:45:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 4E8B96B0055 for ; Fri, 18 Sep 2020 08:45:55 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0EA5B362C for ; Fri, 18 Sep 2020 12:45:55 +0000 (UTC) X-FDA: 77276154270.28.wish20_0714afb2712b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id D9CFE6C0B; Fri, 18 Sep 2020 12:45:54 +0000 (UTC) X-Spam-Summary: 1,0,0,23cc538c8127fd52,d41d8cd98f00b204,batv+1a7941a35ce833a0e493+6235+infradead.org+hch@casper.srs.infradead.org,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:1981:2194:2199:2376:2393:2559:2562:3138:3139:3140:3141:3142:3354:3865:3866:3867:3871:3874:4250:4321:4605:5007:6119:6261:6653:6742:6743:7652:7903:8660:10004:11026:11473:11657:11658:11914:12043:12160:12296:12297:12438:12517:12519:12555:12663:12895:12986:13141:13148:13230:13894:14096:14181:14394:14721:21080:21451:21611:21627:21740:21939:21990:30051:30054,0,RBL:90.155.50.34:@casper.srs.infradead.org:.lbl8.mailshell.net-62.8.15.100 64.201.201.201;04yr47kto8a8rezayiza7w7nihojfyp9fwo6kqf5yq6ib5x5r3437xkbxmcdizh.p4fs9xu7a1r3r68mjbi6zriiqum1owurqcsz1n7mbyghg5ktf5bzhgciwk3gp3j.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,L UA_SUMMA X-HE-Tag: wish20_0714afb2712b X-Filterd-Recvd-Size: 5992 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf31.hostedemail.com (Postfix) with ESMTP; Fri, 18 Sep 2020 12:45:54 +0000 (UTC) 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=9yRRDQwct1JF6ZjH1ZNHGCkZ32QJgvqPcvKB0dar+RA=; b=s9ZOEgeausCRzTAIKECqvkUxtU mBy6UNf6RRm6AlyFjmIkQ3cVDdDYzfwSdhLijuDrQUI+A78+ZqGwh62ALTJTxP+Hb8b83fxY6Qyi6 isvS5QdYE1J4kBdCQWs+MMQ4aSFmky4TbtL3CMmkNu1/mGKdA0TuWf6yx7Uk0Ps1g7r1gKN2xuwhK HRHNr25lHpABcK0AvSVrpaODyp1+JRO4exW0ZmPuLFmNoS3AjrOgbDe3M4ZooZEY0dg3iws/po7YP mnoC1b0zsP8OSDeJX3yk3JwikUwzt2CQzpFw1N1+BKD+glSDIGYYTqxd9FdthshAjsDRO8EDuc8gB 68Zuo9Zg==; Received: from [80.122.85.238] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJFlh-0008Sq-JK; Fri, 18 Sep 2020 12:45:37 +0000 From: Christoph Hellwig To: Alexander Viro Cc: Andrew Morton , Jens Axboe , Arnd Bergmann , David Howells , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, io-uring@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag Date: Fri, 18 Sep 2020 14:45:25 +0200 Message-Id: <20200918124533.3487701-2-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918124533.3487701-1-hch@lst.de> References: <20200918124533.3487701-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a flag to force processing a syscall as a compat syscall. This is required so that in_compat_syscall() works for I/O submitted by io_uring helper threads on behalf of compat syscalls. Signed-off-by: Christoph Hellwig --- arch/sparc/include/asm/compat.h | 3 ++- arch/x86/include/asm/compat.h | 2 +- fs/io_uring.c | 9 +++++++++ include/linux/compat.h | 5 ++++- include/linux/sched.h | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h index 40a267b3bd5208..fee6c51d36e869 100644 --- a/arch/sparc/include/asm/compat.h +++ b/arch/sparc/include/asm/compat.h @@ -211,7 +211,8 @@ static inline int is_compat_task(void) static inline bool in_compat_syscall(void) { /* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ - return pt_regs_trap_type(current_pt_regs()) == 0x110; + return pt_regs_trap_type(current_pt_regs()) == 0x110 || + (current->flags & PF_FORCE_COMPAT); } #define in_compat_syscall in_compat_syscall #endif diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h index d4edf281fff49d..fbab072d4e5b31 100644 --- a/arch/x86/include/asm/compat.h +++ b/arch/x86/include/asm/compat.h @@ -208,7 +208,7 @@ static inline bool in_32bit_syscall(void) #ifdef CONFIG_COMPAT static inline bool in_compat_syscall(void) { - return in_32bit_syscall(); + return in_32bit_syscall() || (current->flags & PF_FORCE_COMPAT); } #define in_compat_syscall in_compat_syscall /* override the generic impl */ #endif diff --git a/fs/io_uring.c b/fs/io_uring.c index 3790c7fe9fee22..5755d557c3f7bc 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5449,6 +5449,9 @@ static int io_req_defer_prep(struct io_kiocb *req, if (unlikely(ret)) return ret; + if (req->ctx->compat) + current->flags |= PF_FORCE_COMPAT; + switch (req->opcode) { case IORING_OP_NOP: break; @@ -5546,6 +5549,7 @@ static int io_req_defer_prep(struct io_kiocb *req, break; } + current->flags &= ~PF_FORCE_COMPAT; return ret; } @@ -5669,6 +5673,9 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, struct io_ring_ctx *ctx = req->ctx; int ret; + if (ctx->compat) + current->flags |= PF_FORCE_COMPAT; + switch (req->opcode) { case IORING_OP_NOP: ret = io_nop(req, cs); @@ -5898,6 +5905,8 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, break; } + current->flags &= ~PF_FORCE_COMPAT; + if (ret) return ret; diff --git a/include/linux/compat.h b/include/linux/compat.h index b354ce58966e2d..685066f7ad325f 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -891,7 +891,10 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args); */ #ifndef in_compat_syscall -static inline bool in_compat_syscall(void) { return is_compat_task(); } +static inline bool in_compat_syscall(void) +{ + return is_compat_task() || (current->flags & PF_FORCE_COMPAT); +} #endif /** diff --git a/include/linux/sched.h b/include/linux/sched.h index afe01e232935fa..c8b183b5655a1e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1491,6 +1491,7 @@ extern struct pid *cad_pid; */ #define PF_IDLE 0x00000002 /* I am an IDLE thread */ #define PF_EXITING 0x00000004 /* Getting shut down */ +#define PF_FORCE_COMPAT 0x00000008 /* acting as compat task */ #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ #define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */ #define PF_FORKNOEXEC 0x00000040 /* Forked but didn't exec */