From patchwork Thu Jul 13 07:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 119604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1655977vqm; Thu, 13 Jul 2023 00:45:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlESuOxw4OnWsABwXZndUNuWRdEUBWUqwtDNlFgq5dcvt5YHM3GA2Z1FRyXnRNajGmw2jxXy X-Received: by 2002:aa7:d48f:0:b0:50b:c630:a956 with SMTP id b15-20020aa7d48f000000b0050bc630a956mr1058188edr.17.1689234316504; Thu, 13 Jul 2023 00:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689234316; cv=none; d=google.com; s=arc-20160816; b=v8N0y/8JRsMOpIn/CBYvhk1GPKlMrTFK3EzxQ3te/XE5ySjHy8pbtutE0hsVIO122F NbD1pUqxQ1aOSeyad82t6vJhojPaD+w2X6A97L35jaSe15iw/7fRt3lENkC96OxJDSkN jrXeyXpMrdW0SsX6+Q4WoR2yXCrtuaN0gy2fa2JGsVS0x5Sq0cqcVpmQgWMVG62oLu0R PPS3M9t6VvbmV3dj7MGW4lxX9UMJ5nijbYgJmhp8M1gjbjD3GGFZCDh0SMuLMy+m1/9+ Dfu1Qom/ArC88+9DujGbpO9rnF1iZHU49fMkLsCWbgh+cMWfgsq2QapyyVn4oRX0jgxf GYMg== 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 :message-id:date:subject:cc:to:from; bh=rClPgrZU548B6ztuTu3yfWH+AglLkkj35UunFFi8PBA=; fh=3mjrIilZhNyhfIqzk92PZQjk8WgduZSOzStXutZeIQ4=; b=Pq8uSXD92afyq7n1Jmh/oAOQ9/mw2veOluzONW+Ou7R6LnnEw+bp3v8pCRn1wsrR1V q8Yay8kpUSSzU7KQ8rin7rcas3u4WsJZK8NYW5fnq4nVYwbIXjBvGhWwh7KuU6wKrY6q lGnidE7Du0X8zipeP/LQS07fHRE7ysSDUBSX8gZ8qpA1QytP/uwWQdlLR11/sQbkEwJO xqdOdo8Q3kt+9Xo7+g8UK/8PsEg4nl9EewpDFIZo53BWABYa9vs0DRvV43mxxGU2qpym RRbN52sKepu+JwapGYqY4cS7aH6o8oBz4LqTrHgmzqYHpa0cyd5W66MHC3ihf+DOpGb0 2u9w== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a056402514500b0051db78fcbdbsi6617754edd.437.2023.07.13.00.44.51; Thu, 13 Jul 2023 00:45:16 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234199AbjGMHSc (ORCPT + 99 others); Thu, 13 Jul 2023 03:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234195AbjGMHSb (ORCPT ); Thu, 13 Jul 2023 03:18:31 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B62E75 for ; Thu, 13 Jul 2023 00:18:28 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 36D7HIYx035713; Thu, 13 Jul 2023 15:17:18 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4R1m9p6Sg7z2MDcHl; Thu, 13 Jul 2023 15:16:14 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.72) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 13 Jul 2023 15:17:16 +0800 From: Xuewen Yan To: , , , , CC: , , Subject: [PATCH] pid: Add the judgment of whether ns is NULL in the find_pid_ns Date: Thu, 13 Jul 2023 15:17:13 +0800 Message-ID: <20230713071713.5762-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.72] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 36D7HIYx035713 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771290562460660622 X-GMAIL-MSGID: 1771290562460660622 There is no the judgment of whether namspace is NULL in find_pid_ns. But there is a corner case when ns is null, for example: if user call find_get_pid when current is in exiting, the following stack would set thread_id be null: release_task __exit_signal(p); __unhash_process(tsk, group_dead); detach_pid(p, PIDTYPE_PID); __change_pid(task, type, NULL); If user call find_get_pid at now, in find_vpid function, the task_active_pid_ns would return NULL. As a result, it would be error when access the ns in find_pid_ns. So add the judgment of whether ns is NULL in the find_pid_ns to prevent this case happen. Signed-off-by: Xuewen Yan --- kernel/pid.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/pid.c b/kernel/pid.c index 6a1d23a11026..d4a9cb6f3eb9 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -308,6 +308,9 @@ void disable_pid_allocation(struct pid_namespace *ns) struct pid *find_pid_ns(int nr, struct pid_namespace *ns) { + if (!ns) + return NULL; + return idr_find(&ns->idr, nr); } EXPORT_SYMBOL_GPL(find_pid_ns);