Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1753053pxv; Fri, 25 Jun 2021 22:58:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf4WL6K48TTVsz1sjnDLwNufpnVaISdVAxhdFUZ9A/2RLsn2BDOXySLqU2+AW0UvmRu+B+ X-Received: by 2002:a17:907:1107:: with SMTP id qu7mr14555131ejb.40.1624687134234; Fri, 25 Jun 2021 22:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624687134; cv=none; d=google.com; s=arc-20160816; b=TMDFh0STzbHHpLvBLCoIN54sJ4Sg8oMzdDXkPE93orCglv+6ZKpvNlxsi034MEjW3s zpzYznSbxWlyUMzA85i4rViyTloUtjB5N85iN7hhT2BViYqIs3jLQ6i4c9lExCXrIbn5 Aq5QbHXpkCJehRaSMKI4uaqVaR2VmVQnv8hG7kpZvNo/FhB3NqhIWfnP3dPCwo3Q2fvW aXY4mbzwdc4X0oopPItfrpYoA9p062oiB4Gh98tL26SN/H7nG5iLz6t/vpif0ZxNZnWh mLLQHqklzGGrKDw3iqCFi3qTvtgnv1IigWgAuLLn8vz/NF5RaRj8upxuTY7Rj3Bk4Ndj zx3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PnTryFwi50YPbqJtIMnYSzHf4Qnr9714ggy6hZgJqDU=; b=xtRfL7qatuc+aw98dtwwA1B9Dt2+VigA9fp/VjpjHuoDuFVBUTcydvypzyzomihC6s 3SV1d3xQFare/SFJ0GDx51uIWFH7CT1MI8tPT9dbrEbpOc2M2L7S1CGytYmV8JLSCEIa 9COJwrjeRILTl8RbZQ3dDXM05OhI3l+3wLgdbFxIbOGRy+2aBM5CTONzmkfnDjZoKU/f xWe0WMhQYYg6JiLKRJFRwc9560jq4p9hF6AsNjGA8Jz2FRqCfq5OQC9vu8SO9JG96xFT 2QLuNH7oVpcW3eSC/xeXWxcoi1L68V7CE9tZmjIRDyUhThI3tNTbISuoCLp/bo4Z3aq3 TX+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A0yt7bNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m15si8535713edr.362.2021.06.25.22.58.30; Fri, 25 Jun 2021 22:58:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A0yt7bNf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbhFZF6s (ORCPT + 99 others); Sat, 26 Jun 2021 01:58:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbhFZF6q (ORCPT ); Sat, 26 Jun 2021 01:58:46 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE7EC061767 for ; Fri, 25 Jun 2021 22:56:23 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id q192so9192938pfc.7 for ; Fri, 25 Jun 2021 22:56:23 -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=PnTryFwi50YPbqJtIMnYSzHf4Qnr9714ggy6hZgJqDU=; b=A0yt7bNf9bzrq08PyG2aWZjlGPFVe0ZpT3tW8adQohWogD9fk2WCcLhhkas3T6XpYM 5zw7na5G33E3mATJXbN88ODE3XlfK/wvPQPp30QBD0XIcitdPyC4az4AnuLWNRZwkDCb rIXHvb2WHF2H5nrZiw0p4AH0mwXyLrBfZw8ek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PnTryFwi50YPbqJtIMnYSzHf4Qnr9714ggy6hZgJqDU=; b=kGl9/Dd3wX2hiye3jyCd3GgjVhDnG1zH1tFMufsOO97AbGL9+oJFjGlDwk+K1qMlKE /R2Yv9x6OP4b/lw6U0d268m9KomRXUj7p68yGDTSKS11TF8XvfjEGCu7dhYmX7EXvJsW By/YCxwTxlPPNJeWSrEjCHJA+0Yx3FGlPFPQfKPSrk7epVTAH6EVSSS/YF04PtmLC/Y4 shwERS9lTfIHmi2Ihdfi0EHq0/4o0lEpOZosCKDtdBZuyWzTx7DagVY/0xn5PGXIR4Vv n5QaEkGlkYrMwMivvQPR+5XS4/gz3DWcAirgENhfjyVbZw5+uI4iK/dx4d/73xdNKAHt 4PJA== X-Gm-Message-State: AOAM533+x5cu3PxiEa/MeStluf3r7LjPCEQ2yiMznL510dNcIllhKxFO iqw66vanDgCg6uPxV4SdOTtezQ== X-Received: by 2002:a63:f20a:: with SMTP id v10mr647186pgh.415.1624686982817; Fri, 25 Jun 2021 22:56:22 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v129sm7662740pfc.31.2021.06.25.22.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 22:56:22 -0700 (PDT) Date: Fri, 25 Jun 2021 22:56:21 -0700 From: Kees Cook To: "Eric W. Biederman" Cc: Linus Torvalds , Al Viro , Michael Schmitz , linux-arch , Jens Axboe , Oleg Nesterov , Linux Kernel Mailing List , Richard Henderson , Ivan Kokshaysky , Matt Turner , alpha , Geert Uytterhoeven , linux-m68k , Arnd Bergmann , Tejun Heo Subject: Re: [PATCH 8/9] signal/task_exit: Use start_task_exit in place of do_exit Message-ID: <202106252255.32CE2711@keescook> References: <87a6njf0ia.fsf@disp2133> <87tulpbp19.fsf@disp2133> <87zgvgabw1.fsf@disp2133> <875yy3850g.fsf_-_@disp2133> <87pmwb5blu.fsf_-_@disp2133> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pmwb5blu.fsf_-_@disp2133> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 24, 2021 at 02:03:25PM -0500, Eric W. Biederman wrote: > > Reuse start_task_exit_locked to implement start_task_exit. > > Simplify the exit logic by having all exits go through get_signal. > This simplifies the analysis of syncrhonization during exit and > gurantees a full set of registers will be available for ptrace to > examine at PTRACE_EVENT_EXIT. > > Signed-off-by: "Eric W. Biederman" > --- > include/linux/sched/signal.h | 1 + > kernel/exit.c | 4 +++- > kernel/seccomp.c | 2 +- > kernel/signal.c | 12 ++++++++++++ > 4 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h > index a958381ba4a9..3f4e69c019b7 100644 > --- a/include/linux/sched/signal.h > +++ b/include/linux/sched/signal.h > @@ -430,6 +430,7 @@ static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume) > > void start_group_exit(int exit_code); > void start_task_exit_locked(struct task_struct *task, int exit_code); > +void start_task_exit(int exit_code); > > void task_join_group_stop(struct task_struct *task); > > diff --git a/kernel/exit.c b/kernel/exit.c > index 635f434122b7..51e0c82b3f7d 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -889,7 +889,9 @@ EXPORT_SYMBOL(complete_and_exit); > > SYSCALL_DEFINE1(exit, int, error_code) > { > - do_exit((error_code&0xff)<<8); > + start_task_exit((error_code&0xff)<<8); > + /* get_signal will call do_exit */ > + return 0; > } > > > diff --git a/kernel/seccomp.c b/kernel/seccomp.c > index b1c06fd1b205..e0c4c123a8bf 100644 > --- a/kernel/seccomp.c > +++ b/kernel/seccomp.c > @@ -1248,7 +1248,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, > force_sig_seccomp(this_syscall, data, true); > } else { > if (action == SECCOMP_RET_KILL_THREAD) > - do_exit(SIGSYS); > + start_task_exit(SIGSYS); > else > start_group_exit(SIGSYS); > } Looks good, yeah. > diff --git a/kernel/signal.c b/kernel/signal.c > index afbc001220dd..63fda9b6bbf9 100644 > --- a/kernel/signal.c > +++ b/kernel/signal.c > @@ -1424,6 +1424,18 @@ void start_task_exit_locked(struct task_struct *task, int exit_code) > } > } > > +void start_task_exit(int exit_code) > +{ > + struct task_struct *task = current; > + if (!fatal_signal_pending(task)) { > + struct sighand_struct *const sighand = task->sighand; > + spin_lock_irq(&sighand->siglock); > + if (!fatal_signal_pending(current)) efficiency nit: "task" instead of "current" here, yes? > + start_task_exit_locked(task, exit_code); > + spin_unlock_irq(&sighand->siglock); > + } > +} > + > struct sighand_struct *__lock_task_sighand(struct task_struct *tsk, > unsigned long *flags) > { > -- > 2.20.1 > -- Kees Cook