Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9193517rwl; Wed, 11 Jan 2023 02:42:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXu2LnEAIiOe+4gGua0W5r/tfBIMdz8IPpd+Xr9BFumYdwAd0ejmAikmF1MHAU+rno3v6rG5 X-Received: by 2002:a17:906:6b97:b0:805:1e6e:6777 with SMTP id l23-20020a1709066b9700b008051e6e6777mr66911058ejr.23.1673433760844; Wed, 11 Jan 2023 02:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673433760; cv=none; d=google.com; s=arc-20160816; b=gz3RFhyQ2cvGd9hg7V/0sjlNU8/4hOnNMnqhpfG5W0r3Oi/kuF+0mbublKag8OemgU 8gVdITQMb71VbISMnWUb+vXCC8fGXhxGxeB247xx69AP4lK7nkhC+OklKpMsOlFJLdvP bWOE8xLSgNzEf/vm85bH6wYvuQ2IxmRXD/KBGsZg50DRF4J8N47T/BHKjIK4DSBFwQxM sTZaju25fVMZpF0Q0hTTfpZmt6pWVwE2rT/znmBt1EsO4OmclL76eUVmV2uBDnJRIeHG JtYl/aqlzD5n4ivG/vhbYtzyp2nv5fZBaKimfhdXeB5yVE1gQ912gkiDBz8D/DH6Yrde N4bw== 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:dkim-signature; bh=g71XtJYmKF1U64u/mKee6gqmuQMnGQrpGMXwCiQqmnM=; b=VEaey4KWLQdXceKE8dz6ZS1df/xifeEnSM3XPN9CEFG6WKCTGKiBcIhLp2olsdk4qD H2KARv8j/0f+NJK/LQ3aILROXxKFnBo/PzkmxcwxwPkmfWNmE0G3T5MCjP8LHUVcDJef Kqcuwqf1mtqPfi0BmvzUhHDJM+6MUHZYaDoXgHVq/cmu8SLnmxmLw5HNhvmSC8/c+IZB MO/Ytn1ZIGBML9GQPMGbnnorXiu0uyK1ZZMpNjepQNGSj4UdSX5cyJLEojA4XaMwUHXq n6c+wIGY2S+WER6qNzhzm7CWc4FY7r5UMlGpnWu6VNN/WbfcjMwAl1SUnKooIHs6Dhxk sXJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=o3SbFNcg; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb40-20020a1709076da800b007baa6e2275asi16605916ejc.236.2023.01.11.02.42.27; Wed, 11 Jan 2023 02:42:40 -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=@gmail.com header.s=20210112 header.b=o3SbFNcg; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233328AbjAKKUe (ORCPT + 55 others); Wed, 11 Jan 2023 05:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238079AbjAKKUG (ORCPT ); Wed, 11 Jan 2023 05:20:06 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C59C7BCC; Wed, 11 Jan 2023 02:20:05 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id y5so11049536pfe.2; Wed, 11 Jan 2023 02:20:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g71XtJYmKF1U64u/mKee6gqmuQMnGQrpGMXwCiQqmnM=; b=o3SbFNcgwgzOvz4PAWC7qpB3Yz+gUEFvjJ5ORg1nI+7VuDs3WKd+SWQGyo0t4NbTru 3Q3cn9wYg37lK28hwpq6UZxB52lNRr99WB5jxTj8O+ZS3L8rCseHqtrrsJzAdjjGuktP 2lybFkIyQkzfsJZFTuvbhTvyceX4ENEEqX5cvukge+1MF55qQ7aSy9DGgBcl31pjJf1e PhZQIAyTdcmgouKcnqufa/msLhrx7fJK+eyUwmDp4STb6hNba3feoMIv+eFwrvGN5dtg OXHm4cB7p9T+U9cbLfbVvKlizDdrxtiIdhXQQKA6hWTsbUe3eChDgMAerWZR+4IIxpl4 Oegw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g71XtJYmKF1U64u/mKee6gqmuQMnGQrpGMXwCiQqmnM=; b=c2Up8iwwPRQlc7XsY3zl6LjhWeiUGAwHThughhUSadfKoEiagFEwu6+sca40tQrAC/ 30CueplhrUD5J+8aolt+cjdQ68paqVW6zqEHwF/nGemrM6wREJyVmeD8pkzP+OIMn/Bj 2Zo6EpP3RiFAr79fRaYZZjlZD5o+Bp0SZ3VwS2YHM/JwUgslA99ZT4zL5TRgKcT7ZSL9 b8xJQcCQtZP82AT5M09lF2pMic4K8So0TvgbXR2c8GLv7vzK0IE5xfj5DTY8xHn3mg02 hB36YZHSAZFcagw6vPX9dzGCoNlBDsqj96aY3tweTkjynh/qlTzZw7/o0RJW2GlDOM/o l2hQ== X-Gm-Message-State: AFqh2krhYhi/JCxf2RgMsv2HtRcUu0N9ulz18ORKYnbDyVvlFlauecOX gVkXrRhVLYlnEREDjmchWTE= X-Received: by 2002:a62:1c4e:0:b0:587:e40c:59e with SMTP id c75-20020a621c4e000000b00587e40c059emr1740065pfc.18.1673432405307; Wed, 11 Jan 2023 02:20:05 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.142]) by smtp.gmail.com with ESMTPSA id u190-20020a6260c7000000b00575caf80d08sm9663761pfb.31.2023.01.11.02.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 02:20:04 -0800 (PST) From: Jia-Ju Bai To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai , TOTE Robot Subject: [PATCH] io_uring: Add NULL checks for current->io_uring Date: Wed, 11 Jan 2023 18:19:07 +0800 Message-Id: <20230111101907.600820-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 As described in a previous commit 998b30c3948e, current->io_uring could be NULL, and thus a NULL check is required for this variable. In the same way, other functions that access current->io_uring also require NULL checks of this variable. Signed-off-by: Jia-Ju Bai Reported-by: TOTE Robot --- io_uring/io_uring.c | 3 ++- io_uring/io_uring.h | 3 +++ io_uring/tctx.c | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 2ac1cd8d23ea..8075c0880c7a 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2406,7 +2406,8 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) /* try again if it submitted nothing and can't allocate a req */ if (!ret && io_req_cache_empty(ctx)) ret = -EAGAIN; - current->io_uring->cached_refs += left; + if (likely(current->io_uring)) + current->io_uring->cached_refs += left; } io_submit_state_end(ctx); diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index ab4b2a1c3b7e..398c7c2ba22b 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -362,6 +362,9 @@ static inline void io_get_task_refs(int nr) { struct io_uring_task *tctx = current->io_uring; + if (unlikely(!tctx)) + return; + tctx->cached_refs -= nr; if (unlikely(tctx->cached_refs < 0)) io_task_refs_refill(tctx); diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 4324b1cf1f6a..6574bbe82b5d 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -145,7 +145,8 @@ int __io_uring_add_tctx_node_from_submit(struct io_ring_ctx *ctx) if (ret) return ret; - current->io_uring->last = ctx; + if (likely(current->io_uring)) + current->io_uring->last = ctx; return 0; } @@ -200,6 +201,9 @@ void io_uring_unreg_ringfd(void) struct io_uring_task *tctx = current->io_uring; int i; + if (unlikely(!tctx)) + return; + for (i = 0; i < IO_RINGFD_REG_MAX; i++) { if (tctx->registered_rings[i]) { fput(tctx->registered_rings[i]); @@ -259,6 +263,9 @@ int io_ringfd_register(struct io_ring_ctx *ctx, void __user *__arg, return ret; tctx = current->io_uring; + if (unlikely(!tctx)) + return -EINVAL; + for (i = 0; i < nr_args; i++) { int start, end; -- 2.34.1