Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3972710pxb; Tue, 25 Jan 2022 00:20:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeEITE5V3LTm4EfAs+ISNb4Mwqv2E7oH7CLx41msiCjJ85L/CxVjX/qHhfGoNPwCmmPiDb X-Received: by 2002:a17:906:4fc8:: with SMTP id i8mr15449711ejw.427.1643098832586; Tue, 25 Jan 2022 00:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643098832; cv=none; d=google.com; s=arc-20160816; b=Nta2zslB+ofc7Nfje39DQ0DN+EIy4Rj2kC52AX8HvmzTaQzdb9l+JY7Vx2gGEwSK7j XOmbndvZJbHJjDh+EA/EQjb+qXEqA44W9OR28U9zlDxOfNqMZU8KjYybz8ooijZ/en8D 9awn7UmzZqcQvUJjLNc4W1pAbOEpQIOzonRb6eL4bd517k42aw+O6uPVPfOkckpasN8f CVfGhZ9BY5d8RFexy5GIRomxiQIhaPjCfMX92vp9/D4How/k8rCKxSIufwglSBz1DtVZ NjfZIQTJi9sO8FPAcJR6CXI2p9qJEUi1W+i33MhIS+m5Tmn0xXUUrbBdjGWV2c/EHQqg ttOw== 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=g1pr2EiMjXF9Lbr6TYOKvAuD9PlSZpj1FTFJzysWyAQ=; b=LTybxqpHPatEt5jLeq1zhKJEyn5yRUdMlw2JR4xJHShMiGmsD3uNc6ObF8oZgf2nUy uqt8C8F3d97O7RYzklNSAObvaiSHGBaDODjE0MDElNQRTChQPvBbBQ32b0/E0lrOo8ke ifahSVCZ5mM2lOJ/hZK76sORI5bLL952EfEdXUXSulkX6yeLoJubrAgXWSaT6vRXw0zL eRaUEvrMDox6/hMXDeJxpSi51OZWVF90eYd7AE4+TGx+zGKXO/1jo7vno6842mmMRT+5 sMmsgB4xOBzyTuQSfaiobhVQ/ALOjDVnV7jJUB9+JNFXQ60q8Q5cLG4MDQzO+uwymuEs PH/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="QU1Vt/+b"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j8si8980580edp.379.2022.01.25.00.20.07; Tue, 25 Jan 2022 00:20:32 -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=@linuxfoundation.org header.s=korg header.b="QU1Vt/+b"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S3412884AbiAYAh6 (ORCPT + 99 others); Mon, 24 Jan 2022 19:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2364082AbiAXXqp (ORCPT ); Mon, 24 Jan 2022 18:46:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B07C2C0612B2; Mon, 24 Jan 2022 13:42:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4F2C460917; Mon, 24 Jan 2022 21:42:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 210FCC340E4; Mon, 24 Jan 2022 21:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060544; bh=OLGhyBE3yYUeUqi46/+gVKgkTva0eh9cbOByjskd/PM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QU1Vt/+bGGqrbdJxxqryg9INuKTWr1rpUID7XPQKOeFTqcem6r044qd0/JRk0AmS1 0D23XOOsJKDDMUxbsxBeXsnr5tMiSBsFVoWpusWAtfJVSuWNCeqBBnMW0siq97i18l Qjzmtbxi4OIdiprFdNj3Zgmrg9S9FTDS0VZpy4Fc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Balbir Singh , "Eric W. Biederman" Subject: [PATCH 5.16 0984/1039] taskstats: Cleanup the use of task->exit_code Date: Mon, 24 Jan 2022 19:46:13 +0100 Message-Id: <20220124184158.349632089@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Eric W. Biederman commit 1b5a42d9c85f0e731f01c8d1129001fd8531a8a0 upstream. In the function bacct_add_task the code reading task->exit_code was introduced in commit f3cef7a99469 ("[PATCH] csa: basic accounting over taskstats"), and it is not entirely clear what the taskstats interface is trying to return as only returning the exit_code of the first task in a process doesn't make a lot of sense. As best as I can figure the intent is to return task->exit_code after a task exits. The field is returned with per task fields, so the exit_code of the entire process is not wanted. Only the value of the first task is returned so this is not a useful way to get the per task ptrace stop code. The ordinary case of returning this value is returning after a task exits, which also precludes use for getting a ptrace value. It is common to for the first task of a process to also be the last task of a process so this field may have done something reasonable by accident in testing. Make ac_exitcode a reliable per task value by always returning it for every exited task. Setting ac_exitcode in a sensible mannter makes it possible to continue to provide this value going forward. Cc: Balbir Singh Fixes: f3cef7a99469 ("[PATCH] csa: basic accounting over taskstats") Link: https://lkml.kernel.org/r/20220103213312.9144-5-ebiederm@xmission.com Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- kernel/tsacct.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -38,11 +38,10 @@ void bacct_add_tsk(struct user_namespace stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); stats->ac_btime64 = btime; - if (thread_group_leader(tsk)) { + if (tsk->flags & PF_EXITING) stats->ac_exitcode = tsk->exit_code; - if (tsk->flags & PF_FORKNOEXEC) - stats->ac_flag |= AFORK; - } + if (thread_group_leader(tsk) && (tsk->flags & PF_FORKNOEXEC)) + stats->ac_flag |= AFORK; if (tsk->flags & PF_SUPERPRIV) stats->ac_flag |= ASU; if (tsk->flags & PF_DUMPCORE)