Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3843429pxb; Tue, 17 Nov 2020 05:12:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJym/eKmIkCgOE5e3lLoWK9FGl1iLmJuJKHNn8UhzFTowCBuzmbD0ajtImGFkBTQEmgtGNcu X-Received: by 2002:a50:f147:: with SMTP id z7mr557039edl.76.1605618733372; Tue, 17 Nov 2020 05:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605618733; cv=none; d=google.com; s=arc-20160816; b=tCg9243gi+snN3KKo8cTUitwdj0Iv6UiW7Ie5lDiNimkyz5X7kvJ+bsXGEphZ4igtk hmevjGYgS5dZ75+gZ4JivwSJMdgl9NFyWCrg53wAlm3fR4Oh6hilvvr9BqgV++A4cVa7 OXEXVHwt0GirLRSTFv9zqaGV5StBa4Gtcojiyn+EuI7vHp97sauKg88UttBGMY4sowsy FiOMAPu+nZ7wu7LdpklzG53n2C0c358DaU2MfIMUmxTRnPf5KghSwE8iwZ70kkbaXWEn E0QsszNUqYaZD4esErzMndVbYxMYZwOyehIilIUx0SqQsCBIwAbgF1I33IrwAvHEMshQ EJNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vNGihYclW1ttfUAkBi5iaY1b7K0e+z7vQa2xFkeGhQw=; b=eRyvw0QXr5gVF/Hc6vmu9P/nxoIYBHz/W/ruLeshblOHadbwVK0qHr+RhrKRY8eXiG 9rLOCCX2ADcCd3e4S/hEc9EpzDBzJsQboj0AShkyga1woIds36fGBu4L+z2XWqdKFQo3 ehqOwn1mfXzSX8QZLY6mKKLykVkVPjKdHoHUZhLw2iDxTTcgHp6AnmtfiPzSatuZX9gW Bhz4BAxsbVXeaDiiGuDIhN4hUQxIzbnAc6y2jjbn69L3aGPTG5Q/AD/JdOAjV975wQ6J LZ4v71ws3QG1/jFZzemhath5MrtfW3PSt7T5p7wZp3UnrrJYK87acg7pCBYENoi50iOb xzFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LoJTf0+s; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si13995229edx.450.2020.11.17.05.11.49; Tue, 17 Nov 2020 05:12:13 -0800 (PST) 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=@kernel.org header.s=default header.b=LoJTf0+s; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729125AbgKQNHh (ORCPT + 99 others); Tue, 17 Nov 2020 08:07:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:35096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729107AbgKQNHa (ORCPT ); Tue, 17 Nov 2020 08:07:30 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C5832468F; Tue, 17 Nov 2020 13:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618449; bh=SYfwzIgWl8g1P/EmMrMx3AnqOwe83/QwaaKVAqhaHWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LoJTf0+s4NP4FwDl9mcs7T9qWwjmrW01D7iLrpIS2++PZIl1++3qqx9Eid1ahvlWD zHMy0luTSlPc+I7ROkUjepEUbjOn1+B83WQMChP8NfGC3or5Z1VY5XyhFaT7fX/HBw /JSyCsVumaxlYWOOwim/eGD/teKVP6WVy/nsWEro= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Eric W. Biederman" , Al Viro Subject: [PATCH 4.4 37/64] dont dump the threads that had been already exiting when zapped. Date: Tue, 17 Nov 2020 14:05:00 +0100 Message-Id: <20201117122107.990579548@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122106.144800239@linuxfoundation.org> References: <20201117122106.144800239@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro commit 77f6ab8b7768cf5e6bdd0e72499270a0671506ee upstream. Coredump logics needs to report not only the registers of the dumping thread, but (since 2.5.43) those of other threads getting killed. Doing that might require extra state saved on the stack in asm glue at kernel entry; signal delivery logics does that (we need to be able to save sigcontext there, at the very least) and so does seccomp. That covers all callers of do_coredump(). Secondary threads get hit with SIGKILL and caught as soon as they reach exit_mm(), which normally happens in signal delivery, so those are also fine most of the time. Unfortunately, it is possible to end up with secondary zapped when it has already entered exit(2) (or, worse yet, is oopsing). In those cases we reach exit_mm() when mm->core_state is already set, but the stack contents is not what we would have in signal delivery. At least on two architectures (alpha and m68k) it leads to infoleaks - we end up with a chunk of kernel stack written into coredump, with the contents consisting of normal C stack frames of the call chain leading to exit_mm() instead of the expected copy of userland registers. In case of alpha we leak 312 bytes of stack. Other architectures (including the regset-using ones) might have similar problems - the normal user of regsets is ptrace and the state of tracee at the time of such calls is special in the same way signal delivery is. Note that had the zapper gotten to the exiting thread slightly later, it wouldn't have been included into coredump anyway - we skip the threads that have already cleared their ->mm. So let's pretend that zapper always loses the race. IOW, have exit_mm() only insert into the dumper list if we'd gotten there from handling a fatal signal[*] As the result, the callers of do_exit() that have *not* gone through get_signal() are not seen by coredump logics as secondary threads. Which excludes voluntary exit()/oopsen/traps/etc. The dumper thread itself is unaffected by that, so seccomp is fine. [*] originally I intended to add a new flag in tsk->flags, but ebiederman pointed out that PF_SIGNALED is already doing just what we need. Cc: stable@vger.kernel.org Fixes: d89f3847def4 ("[PATCH] thread-aware coredumps, 2.5.43-C3") History-tree: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git Acked-by: "Eric W. Biederman" Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- kernel/exit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/exit.c +++ b/kernel/exit.c @@ -408,7 +408,10 @@ static void exit_mm(struct task_struct * up_read(&mm->mmap_sem); self.task = tsk; - self.next = xchg(&core_state->dumper.next, &self); + if (self.task->flags & PF_SIGNALED) + self.next = xchg(&core_state->dumper.next, &self); + else + self.task = NULL; /* * Implies mb(), the result of xchg() must be visible * to core_state->dumper.