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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 21E09C11F65 for ; Wed, 30 Jun 2021 21:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F147061474 for ; Wed, 30 Jun 2021 21:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232397AbhF3VrY (ORCPT ); Wed, 30 Jun 2021 17:47:24 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:46890 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbhF3VrX (ORCPT ); Wed, 30 Jun 2021 17:47:23 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lyi0o-00C7rX-Pk; Wed, 30 Jun 2021 15:44:50 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:45966 helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lyi0n-007gGb-GG; Wed, 30 Jun 2021 15:44:50 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Gabriel Krisman Bertazi Cc: luto@kernel.org, tglx@linutronix.de, keescook@chromium.org, gofmanp@gmail.com, christian.brauner@ubuntu.com, peterz@infradead.org, willy@infradead.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, kernel@collabora.com References: <20201127193238.821364-1-krisman@collabora.com> <20201127193238.821364-4-krisman@collabora.com> Date: Wed, 30 Jun 2021 16:44:41 -0500 In-Reply-To: <20201127193238.821364-4-krisman@collabora.com> (Gabriel Krisman Bertazi's message of "Fri, 27 Nov 2020 14:32:34 -0500") Message-ID: <8735szowmu.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1lyi0n-007gGb-GG;;;mid=<8735szowmu.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19aQL09HEdJngXqT3ixbdywo5veaWkBBOQ= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v8 3/7] kernel: Implement selective syscall userspace redirection X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Why does do_syscal_user_dispatch call do_exit(SIGSEGV) and do_exit(SIGSYS) instead of force_sig(SIGSEGV) and force_sig(SIGSYS)? Looking at the code these cases are not expected to happen, so I would be surprised if userspace depends on any particular behaviour on the failure path so I think we can change this. Is using do_exit in this way something you copied from seccomp? The reason I am asking is that by using do_exit you deprive userspace of the change to catch the signal handler and try and fix things. Also by using do_exit only a single thread of a multi-thread application is terminated which seems wrong. I am asking because I am going through the callers of do_exit so I can refactor things and clean things up and this use just looks wrong. Gabriel Krisman Bertazi writes: > +bool do_syscall_user_dispatch(struct pt_regs *regs) > +{ > + struct syscall_user_dispatch *sd = ¤t->syscall_dispatch; > + char state; > + > + if (likely(instruction_pointer(regs) - sd->offset < sd->len)) > + return false; > + > + if (unlikely(arch_syscall_is_vdso_sigreturn(regs))) > + return false; > + > + if (likely(sd->selector)) { > + /* > + * access_ok() is performed once, at prctl time, when > + * the selector is loaded by userspace. > + */ > + if (unlikely(__get_user(state, sd->selector))) > + do_exit(SIGSEGV); ^^^^^^^^^^^^^^^^ I think it makes more sense if the code does: if (unlikely(__get_user(state, sd->selector))) { force_sig(SIGSEGV); return true; } > + > + if (likely(state == PR_SYS_DISPATCH_OFF)) > + return false; > + > + if (state != PR_SYS_DISPATCH_ON) > + do_exit(SIGSYS); ^^^^^^^^^^^^^^^ > + } > + > + sd->on_dispatch = true; > + syscall_rollback(current, regs); > + trigger_sigsys(regs); > + > + return true; > +} Eric