Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9656797ybi; Wed, 24 Jul 2019 07:48:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJQskwL1hZvLEVUDvErt2w0N7ljeGlJ4/Se/DkTq7yVZxCJ5D344RxcfRY6MNinIgSonbl X-Received: by 2002:aa7:87d5:: with SMTP id i21mr11658285pfo.70.1563979707723; Wed, 24 Jul 2019 07:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563979707; cv=none; d=google.com; s=arc-20160816; b=DVS6pTzAdGxV5lpPX3qmScMnKIlE0jJA7gp/a0VCnCWcq6ADIdxtfMJKikZN9YH76n JvC8lV2c9cn1O22Hbw6F+lmyq+RzeiJ+rca585+u+q0ktKVgh6+3L4ppqtsHLYMDaw1n E8L3UyK6jM2JuotRpM19LPsNh1XmepZw8eHwHHOQcuaOefGbeCeFY6ddE9ZxmXpxXLDy Goxd+OdUWGp/bZpD8T4HSignLdjf24+pAa22OXMfoYSJ0kMRfBTG0IcNFASWZAtQjmUW kdryZ/QNaoJIYCZ6quqJVuyJ8FPcYJxFtQ70wQItCj0qldgi5T5x064Fz102zgE3RD5p tGfw== 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 :dkim-signature; bh=7LF+TqzkdoxFIHCg2CjCscZk8IRSrnPu55eYCvRE1cQ=; b=Yj14wdCsXtYJzFegCpc2F0yQ8gv2YOnuq8PeBVGVoCLS+ycbSKnol92DaCRRwMBloU lTzdYiuAhgy6kjYYzRSLEL12UGMyorRN2UNXBnuq0jQZW5NPYwmugyjb7fQtOUwa9B0u mdnFzNpgsb0omaGUyFUGsNE/w4nqwoxB5wWZ1eUQob4+o5Xb2CUaboV+adWVx7/wqx+N tqzv44nKkJnitpskDaQ+/VjigFi3z+T9C7ng/Gk5zGnxdOycf5LRq/rDwGr4Z5SMldIz CZNkOZUtmQKA1Mu6o8coBilnChBwNzkbkkeA5CxvnK2a7cSSP0WTq7nxjvItjmZ6pJrA yoVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=IvGNtpiP; 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 b23si12984336pjp.62.2019.07.24.07.48.13; Wed, 24 Jul 2019 07:48:27 -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; dkim=pass header.i=@brauner.io header.s=google header.b=IvGNtpiP; 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 S2387497AbfGXOrc (ORCPT + 99 others); Wed, 24 Jul 2019 10:47:32 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42488 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726470AbfGXOrb (ORCPT ); Wed, 24 Jul 2019 10:47:31 -0400 Received: by mail-pg1-f193.google.com with SMTP id t132so21343664pgb.9 for ; Wed, 24 Jul 2019 07:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7LF+TqzkdoxFIHCg2CjCscZk8IRSrnPu55eYCvRE1cQ=; b=IvGNtpiPO2xFlc/FmS9S7JdQgiQ5G1DB59NGUpzkzKAeFLhZkrnn4Wd33J1CvB2tpV x6SXtnpWu0iSjXvaBdDBEt6W2IMwmxk3pxkAkZCc7JGkgSBbKAu3T6alPEXj2h51dG1Z ELhU6hbNC2u2S47JY2pCwLxrnVOy5g4ApQZFe+tVedVWBr6yw2nlgaTz1SrHbOYN5m4F zEckuImuxPEG6bpRsRg37nCPlsqmO0BHRLMbazrPhPJeOvNB+kYFhYmNTcBkqhVgEaeR 75BX/gU7xsSljULk1wvC8S60hWNxxYGzK095ctAhvEyodxgl3o18YKCMVES6rcRDzG9n oZkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7LF+TqzkdoxFIHCg2CjCscZk8IRSrnPu55eYCvRE1cQ=; b=bqoa9WUXgoLfKaJo7gkyfpKJkZCijeqpFR/s2PwRZb68dDzEk6rj34D/UpCfWAvTki 8yvn+xgxLs23y/kpZmtTA0Z05i2hCNE4wkMRv6kL8OpWqcuclHPKNXZda2IEPMWDV5sZ Iu324D2cpvqLLr8LZQG03BaKjziTrCv8vstlA9EZ1Yd7Oi0C4ONAH/PaWUuPcK0+U+OS ePmpcoSCJYJ/231BQAW/iJgkwhwzfb7U4qHzz19noUyd8uUedG7tu5uA73mIr8mku9k6 1VyaGYdEleJg7PeQWp68lreto4w+SqPdweiGP0ODG82p10EV+t1rbbycJ/54lxY78loJ Rryw== X-Gm-Message-State: APjAAAXAFh5DM1LAkIklmlvh6JHV83jGH7vDNssbg3XaGZrymFClWrzZ 1PzX3jtaK1MWr6O6ze3XATEurywwU2U= X-Received: by 2002:a17:90a:3225:: with SMTP id k34mr86837702pjb.31.1563979650539; Wed, 24 Jul 2019 07:47:30 -0700 (PDT) Received: from localhost.localdomain ([172.58.27.54]) by smtp.gmail.com with ESMTPSA id g6sm41125644pgh.64.2019.07.24.07.47.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 07:47:29 -0700 (PDT) From: Christian Brauner To: linux-kernel@vger.kernel.org, oleg@redhat.com Cc: arnd@arndb.de, ebiederm@xmission.com, keescook@chromium.org, joel@joelfernandes.org, tglx@linutronix.de, tj@kernel.org, dhowells@redhat.com, jannh@google.com, luto@kernel.org, akpm@linux-foundation.org, cyphar@cyphar.com, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, kernel-team@android.com, Christian Brauner Subject: [RFC][PATCH 1/5] exit: kill struct waitid_info Date: Wed, 24 Jul 2019 16:46:47 +0200 Message-Id: <20190724144651.28272-2-christian@brauner.io> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724144651.28272-1-christian@brauner.io> References: <20190724144651.28272-1-christian@brauner.io> 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 The code here uses a struct waitid_info to catch basic information about process exit including the pid, uid, status, and signal that caused the process to exit. This information is then stuffed into a struct siginfo for the waitid() syscall. That seems like an odd thing to do. We can just pass down a siginfo_t struct directly which let's us cleanup and simplify the whole code quite a bit. This patch also simplifies the following implementation of pidfd_wait(). Note that this changes how struct siginfo is filled in for users of waitid. POSIX doesn't mandate anything else other than si_pid, si_uid, si_code, and si_signo. So it seems up to the implementation. In case anyone relies on the old behavior we can just revert but I highly doubt that users fill in siginfo_t before a call to waitid and expect all fields other then the ones mention above to be untouched. Signed-off-by: Christian Brauner Cc: Arnd Bergmann Cc: "Eric W. Biederman" Cc: Kees Cook Cc: Joel Fernandes (Google) Cc: Thomas Gleixner Cc: Tejun Heo Cc: David Howells Cc: Jann Horn Cc: Andy Lutomirsky Cc: Andrew Morton Cc: Oleg Nesterov Cc: Aleksa Sarai Cc: Linus Torvalds Cc: Al Viro --- kernel/exit.c | 101 ++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 65 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index a75b6a7f458a..73392a455b72 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -994,19 +994,12 @@ SYSCALL_DEFINE1(exit_group, int, error_code) return 0; } -struct waitid_info { - pid_t pid; - uid_t uid; - int status; - int cause; -}; - struct wait_opts { enum pid_type wo_type; int wo_flags; struct pid *wo_pid; - struct waitid_info *wo_info; + kernel_siginfo_t *wo_info; int wo_stat; struct rusage *wo_rusage; @@ -1058,7 +1051,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) int state, status; pid_t pid = task_pid_vnr(p); uid_t uid = from_kuid_munged(current_user_ns(), task_uid(p)); - struct waitid_info *infop; + kernel_siginfo_t *infop; if (!likely(wo->wo_flags & WEXITED)) return 0; @@ -1169,14 +1162,14 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) infop = wo->wo_info; if (infop) { if ((status & 0x7f) == 0) { - infop->cause = CLD_EXITED; - infop->status = status >> 8; + infop->si_code = CLD_EXITED; + infop->si_status = status >> 8; } else { - infop->cause = (status & 0x80) ? CLD_DUMPED : CLD_KILLED; - infop->status = status & 0x7f; + infop->si_code = (status & 0x80) ? CLD_DUMPED : CLD_KILLED; + infop->si_status = status & 0x7f; } - infop->pid = pid; - infop->uid = uid; + infop->si_pid = pid; + infop->si_uid = uid; } return pid; @@ -1215,7 +1208,7 @@ static int *task_stopped_code(struct task_struct *p, bool ptrace) static int wait_task_stopped(struct wait_opts *wo, int ptrace, struct task_struct *p) { - struct waitid_info *infop; + kernel_siginfo_t *infop; int exit_code, *p_code, why; uid_t uid = 0; /* unneeded, required by compiler */ pid_t pid; @@ -1270,10 +1263,10 @@ static int wait_task_stopped(struct wait_opts *wo, infop = wo->wo_info; if (infop) { - infop->cause = why; - infop->status = exit_code; - infop->pid = pid; - infop->uid = uid; + infop->si_code = why; + infop->si_status = exit_code; + infop->si_pid = pid; + infop->si_uid = uid; } return pid; } @@ -1286,7 +1279,7 @@ static int wait_task_stopped(struct wait_opts *wo, */ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p) { - struct waitid_info *infop; + kernel_siginfo_t *infop; pid_t pid; uid_t uid; @@ -1316,13 +1309,13 @@ static int wait_task_continued(struct wait_opts *wo, struct task_struct *p) put_task_struct(p); infop = wo->wo_info; - if (!infop) { - wo->wo_stat = 0xffff; + if (infop) { + infop->si_code = CLD_CONTINUED; + infop->si_status = SIGCONT; + infop->si_pid = pid; + infop->si_uid = uid; } else { - infop->cause = CLD_CONTINUED; - infop->pid = pid; - infop->uid = uid; - infop->status = SIGCONT; + wo->wo_stat = 0xffff; } return pid; } @@ -1552,7 +1545,7 @@ static long do_wait(struct wait_opts *wo) return retval; } -static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, +static long kernel_waitid(int which, pid_t upid, kernel_siginfo_t *infop, int options, struct rusage *ru) { struct wait_opts wo; @@ -1602,33 +1595,22 @@ SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *, infop, int, options, struct rusage __user *, ru) { struct rusage r; - struct waitid_info info = {.status = 0}; - long err = kernel_waitid(which, upid, &info, options, ru ? &r : NULL); - int signo = 0; - + kernel_siginfo_t kinfo = { + .si_signo = 0, + }; + long err = kernel_waitid(which, upid, infop ? &kinfo : NULL, options, + ru ? &r : NULL); if (err > 0) { - signo = SIGCHLD; + kinfo.si_signo = SIGCHLD; err = 0; if (ru && copy_to_user(ru, &r, sizeof(struct rusage))) return -EFAULT; } - if (!infop) - return err; - if (!user_access_begin(infop, sizeof(*infop))) + if (infop && copy_siginfo_to_user(infop, &kinfo)) return -EFAULT; - unsafe_put_user(signo, &infop->si_signo, Efault); - unsafe_put_user(0, &infop->si_errno, Efault); - unsafe_put_user(info.cause, &infop->si_code, Efault); - unsafe_put_user(info.pid, &infop->si_pid, Efault); - unsafe_put_user(info.uid, &infop->si_uid, Efault); - unsafe_put_user(info.status, &infop->si_status, Efault); - user_access_end(); - return err; -Efault: - user_access_end(); - return -EFAULT; + return err ; } long kernel_wait4(pid_t upid, int __user *stat_addr, int options, @@ -1722,11 +1704,13 @@ COMPAT_SYSCALL_DEFINE5(waitid, struct compat_rusage __user *, uru) { struct rusage ru; - struct waitid_info info = {.status = 0}; - long err = kernel_waitid(which, pid, &info, options, uru ? &ru : NULL); - int signo = 0; + kernel_siginfo_t kinfo = { + .si_signo = 0, + }; + long err = kernel_waitid(which, pid, infop ? &kinfo : NULL, options, + uru ? &ru : NULL); if (err > 0) { - signo = SIGCHLD; + kinfo.si_signo = SIGCHLD; err = 0; if (uru) { /* kernel_waitid() overwrites everything in ru */ @@ -1739,23 +1723,10 @@ COMPAT_SYSCALL_DEFINE5(waitid, } } - if (!infop) - return err; - - if (!user_access_begin(infop, sizeof(*infop))) + if (infop && copy_siginfo_to_user32(infop, &kinfo)) return -EFAULT; - unsafe_put_user(signo, &infop->si_signo, Efault); - unsafe_put_user(0, &infop->si_errno, Efault); - unsafe_put_user(info.cause, &infop->si_code, Efault); - unsafe_put_user(info.pid, &infop->si_pid, Efault); - unsafe_put_user(info.uid, &infop->si_uid, Efault); - unsafe_put_user(info.status, &infop->si_status, Efault); - user_access_end(); return err; -Efault: - user_access_end(); - return -EFAULT; } #endif -- 2.22.0