Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4303341imm; Mon, 15 Oct 2018 12:24:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV638lqGV4GtmfsVknq/UNbaxO0FI4RmUqqJqsNi2zDTscQcPEnsddtNjEigHeMp3GuF/Jg2T X-Received: by 2002:a63:f005:: with SMTP id k5-v6mr17353505pgh.259.1539631482242; Mon, 15 Oct 2018 12:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539631482; cv=none; d=google.com; s=arc-20160816; b=ypLUF09EaW17kt2fYTwwRVWSghtqmyYJ7S2aAoPe305Q2Ztpf/6LIbqQWTyq7REcCJ HK8CP3+nhP5T6hxj8kLep9nlwq9eKOYvBHwjcIfyR+UafIO089BF4i7Sn63dnlPbKK+q Lj12d5xrWOI08tC6zXfEHhqmSE3Y3yHE+aGcyCNYkzpF0KPna7oUBYGivt8Q310tGozF zWzGGfVU+K7sdRM8PmnxddBL0INMaLRM8u0JEsUgggtNzK6KXpHxMMKMzARNKQga4id9 3t2C8N9pnmjq06d0AQsz/KxL1DnFnx0/PNjY8T/PDQJHRFqdhqsEQpxCK/aOXyDunY7+ eT4A== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=0TgknSPdSpuXTgkWM/HmzaUWZUSo+Cu0YrS7JdR4JWw=; b=OBMtmJ3alEr6yJlgKZUjNdvsqA8PG6MHdlnfvBfYoz4M+/oIoAi7bnayFcrGsaxxkN ewj2QU3SdQC4KjTCxEAKBc0dAnzAu/4yqsq865t9xuuM4XnfkVsVzrpFeEX8uZHW9L8u Z6IXo8jmdxUXGYnFaO9kpKsNXD+nbG0MpynTk1UKxiwQjvuFNWMhhUIen/Vy0RLf3H8+ PewqP/3bDADFN52GpmcGKprdre+5pxU6U+WVh3oFwlmjvZ/GKkcwdB63Swe7nzFVVHY+ I148RJ8o/Od15VTcdJOxOmBXJBFGtJegh/rxqR40cqX3DaCVInpduVL2A8WbiY9208wx ajsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=ASx5B3MF; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si10969206plr.267.2018.10.15.12.24.26; Mon, 15 Oct 2018 12:24:42 -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=@cisco.com header.s=iport header.b=ASx5B3MF; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbeJPDKk (ORCPT + 99 others); Mon, 15 Oct 2018 23:10:40 -0400 Received: from alln-iport-6.cisco.com ([173.37.142.93]:52546 "EHLO alln-iport-6.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbeJPDKk (ORCPT ); Mon, 15 Oct 2018 23:10:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=4080; q=dns/txt; s=iport; t=1539631442; x=1540841042; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=w9uNVnQfhuvnwKyGdheHU9+n3ba4ZUiSWgBBSFho/Sg=; b=ASx5B3MFwlweW4Y7exB/guwBAWKHwgWECY3xb95aymR26kyurupPtVuj /DHQEamKsIefeJuAn4KbQ7suLRkP5cnc42XHbBsYSKouiPaWfgLwYvTHv ff5etRCT369/ZbzMXoKoYBVX3EEI0nuVEacvf/a97xYJb0D5dFzpPKYX4 c=; X-IronPort-AV: E=Sophos;i="5.54,385,1534809600"; d="scan'208";a="185767457" Received: from alln-core-7.cisco.com ([173.36.13.140]) by alln-iport-6.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Oct 2018 19:24:01 +0000 Received: from [10.154.208.167] ([10.154.208.167]) by alln-core-7.cisco.com (8.15.2/8.15.2) with ESMTP id w9FJNjYQ011677; Mon, 15 Oct 2018 19:23:47 GMT Subject: Re: [PATCH] kernel/signal: Signal-based pre-coredump notification To: Jann Horn Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , the arch/x86 maintainers , Peter Zijlstra , Arnd Bergmann , "Eric W. Biederman" , Khalid Aziz , Kate Stewart , deller@gmx.de, Greg Kroah-Hartman , Al Viro , Andrew Morton , christian@brauner.io, Catalin Marinas , Will Deacon , Dave.Martin@arm.com, mchehab+samsung@kernel.org, Michal Hocko , Rik van Riel , "Kirill A . Shutemov" , guro@fb.com, Marcos Souza , Oleg Nesterov , linux@dominikbrodowski.net, Cyrill Gorcunov , yang.shi@linux.alibaba.com, Kees Cook , kernel list , linux-arch , Victor Kamensky , xe-linux-external@cisco.com, sstrogin@cisco.com, Enke Chen References: From: Enke Chen Message-ID: Date: Mon, 15 Oct 2018 12:23:45 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.154.208.167, [10.154.208.167] X-Outbound-Node: alln-core-7.cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Jann: Thanks for your detail explanation. Will take care of it. -- Enke On 10/15/18 11:54 AM, Jann Horn wrote: > On Mon, Oct 15, 2018 at 8:36 PM Enke Chen wrote: >> On 10/13/18 11:27 AM, Jann Horn wrote: >>> On Sat, Oct 13, 2018 at 2:33 AM Enke Chen wrote: >>>> For simplicity and consistency, this patch provides an implementation >>>> for signal-based fault notification prior to the coredump of a child >>>> process. A new prctl command, PR_SET_PREDUMP_SIG, is defined that can >>>> be used by an application to express its interest and to specify the >>>> signal (SIGCHLD or SIGUSR1 or SIGUSR2) for such a notification. A new >>>> signal code (si_code), CLD_PREDUMP, is also defined for SIGCHLD. >>> >>> Your suggested API looks vaguely similar to PR_SET_PDEATHSIG, but with >>> some important differences: >>> >>> - You don't reset the signal on setuid execution. > [...] >>> >>> For both of these: Are these differences actually necessary, and if >>> so, can you provide a specific rationale? From a security perspective, >>> I would very much prefer it if this API had semantics closer to >>> PR_SET_PDEATHSIG. >> > [...] >> >> Regarding the impact of "setuid", this property "PR_SET_PREDUMP_SIG" has to >> do with the application/process whether the signal handler is set for receiving >> such a notification. If it is set, the "uid" should not matter. > > If an attacker's process first calls PR_SET_PREDUMP_SIG, then forks > off a child, then calls execve() on a setuid binary, the setuid binary > calls setuid(0), and the attacker-controlled child then crashes, the > privileged process will receive an unexpected signal that the attacker > wouldn't have been allowed to send otherwise. For similar reasons, the > parent death signal is reset when a setuid binary is executed: > > void setup_new_exec(struct linux_binprm * bprm) > { > /* > * Once here, prepare_binrpm() will not be called any more, so > * the final state of setuid/setgid/fscaps can be merged into the > * secureexec flag. > */ > bprm->secureexec |= bprm->cap_elevated; > > if (bprm->secureexec) { > /* Make sure parent cannot signal privileged process. */ > current->pdeath_signal = 0; > [...] > } > [...] > } > > int commit_creds(struct cred *new) > { > [...] > /* dumpability changes */ > if (!uid_eq(old->euid, new->euid) || > !gid_eq(old->egid, new->egid) || > !uid_eq(old->fsuid, new->fsuid) || > !gid_eq(old->fsgid, new->fsgid) || > !cred_cap_issubset(old, new)) { > if (task->mm) > set_dumpable(task->mm, suid_dumpable); > task->pdeath_signal = 0; > smp_wmb(); > } > [...] > } > > AppArmor and SELinux also do related changes: > > static void apparmor_bprm_committing_creds(struct linux_binprm *bprm) > { > [...] > /* bail out if unconfined or not changing profile */ > if ((new_label->proxy == label->proxy) || > (unconfined(new_label))) > return; > > aa_inherit_files(bprm->cred, current->files); > > current->pdeath_signal = 0; > [...] > } > > static void selinux_bprm_committing_creds(struct linux_binprm *bprm) > { > [...] > new_tsec = bprm->cred->security; > if (new_tsec->sid == new_tsec->osid) > return; > > /* Close files for which the new task SID is not authorized. */ > flush_unauthorized_files(bprm->cred, current->files); > > /* Always clear parent death signal on SID transitions. */ > current->pdeath_signal = 0; > [...] > } > > You should probably reset the coredump signal in the same places - or > even better, add a new helper for resetting the parent death signal, > and then add code for resetting the coredump signal in there. >