Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4092106pxb; Mon, 21 Feb 2022 12:00:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5J8IuR8z0I74cvJfy0Z0Ixlqz9YLhdq7z3+zg1cJ4s+njGL0leNwUx1sJKKUSlNU96wo9 X-Received: by 2002:a05:6402:50d2:b0:413:1cd8:e08e with SMTP id h18-20020a05640250d200b004131cd8e08emr1381608edb.276.1645473653873; Mon, 21 Feb 2022 12:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645473653; cv=none; d=google.com; s=arc-20160816; b=vCntH+gFkFuS/BfE5xpOASb+kAkgP3B40g9MPuQeJ3JWt7rIQlePveNDz8F0iLgUIB VIDQOI4MMY3MKJLIFQyhliopw7j3TpNefQuieEuUZ0gnyCyVNvAVtsIORTFlKQvjblOZ gLksh6cjZuNd5OQ5pMPhmKDlU7/T14Rqnde6sMAYL365Y5LfH5UAOFTsvMZ/zfriB1at A/hXkh+ddYBdfH5wG2hnbyjoQe+E2gDjZbzEsf2T1CzLkuJbj/RrKs9dvqa+futMrrzu CjdGaRznljqntoDUimRnnYt3sJnmR2GIyRgvLK0SYgb8BI308J0vp7heU63x8qoH7q0o gxMA== 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=wu6awE0ZycioYX3CM4Fd/wJDHkoSyHUKAA/dUhsa+8s=; b=NMsKJaQEy9jli1sCSERU4jo8JRhid7RwIS/8yq294CDEjXjWafbCp1fBzeJGKXR0BP o2icwWEIj0tlS8JcUnD+Kb0Z79ae8gbiAhRQk0acU7s1EDnLXtIq4H9DOqK7BrJ7rVyB hyMEImQ6txhw8JfNxod1OpNPlpiEe2BUYwm7YQnVDT87fypt17F+CW/Qf7y9pQMi0XSw AZAC/pCRNH3PtNe9AtuBC0ZlZ88mvi/BngXXmNfEJbgNId3JXF1MueRUnNcy1KkcQeJO vVE0T5IoI1xS3+RYmBIJuOLyJIG6ATQ9wu8CPCDKG1RtZV6gqxdKTwdD/iS9MpO4Je3V NY1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZT5aGzS7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v5si13164244edi.429.2022.02.21.12.00.29; Mon, 21 Feb 2022 12:00:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZT5aGzS7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1347789AbiBUJJQ (ORCPT + 99 others); Mon, 21 Feb 2022 04:09:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347131AbiBUJEn (ORCPT ); Mon, 21 Feb 2022 04:04:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38562DD5E; Mon, 21 Feb 2022 00:58:49 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8C51FB80EB7; Mon, 21 Feb 2022 08:58:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAF88C340E9; Mon, 21 Feb 2022 08:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433927; bh=h5Dw3Vgeme5qSV/8KduGsJ/MLiraukhAcg98o51JmQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZT5aGzS7OuGWa3KWyJufRYnN6jcbTApp2O+mvXHkbj7VKYyaYc/empae3KJebqbik cSvKFGLRKacMYLvh/QNCLe2HDfMMVkyxgcqh+BXeCn+uBIIbA0beLfq76a3RCxP1a9 BLEst0XxgrULgDlJyASlpVOJjfTqUd6ZyBnRtfrU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Balbir Singh , "Eric W. Biederman" , Sudip Mukherjee Subject: [PATCH 5.4 32/80] taskstats: Cleanup the use of task->exit_code Date: Mon, 21 Feb 2022 09:49:12 +0100 Message-Id: <20220221084916.628257481@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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" [sudip: adjust context] Signed-off-by: Sudip Mukherjee 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 @@ -35,11 +35,10 @@ void bacct_add_tsk(struct user_namespace /* Convert to seconds for btime */ do_div(delta, USEC_PER_SEC); stats->ac_btime = get_seconds() - delta; - 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)