Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2548981pxj; Mon, 10 May 2021 05:42:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAo648oLh/QFsSR3ZzIMSRlcP+Yv6OxW2MjV3W87KCGa67YrabeTJVn3VciDgCaIu/aLaZ X-Received: by 2002:a6b:ed11:: with SMTP id n17mr17227544iog.171.1620650534962; Mon, 10 May 2021 05:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620650534; cv=none; d=google.com; s=arc-20160816; b=eOZWjx7d4iXUck6KlGxZuZ3FB6KYelWCc8hqv23worV/sZH7BRs4A6IntXoFXkYsDZ hduXWGVkXcZEgdwICb/wADtVHcs/FberqBTheAIj4KBr0jd3Uyl/SxHg8qvxztuoV8Pm 4NmWpK+VwZwICDq+DIffVaOyGjBfuP3d2lTm++Emhkc4bIyiMmqHpRkEKmEiZEbiFMqq VFVkcukc6/g6O9JZLZcFOo2nNaWicRnNdr5a7iIX7cwiGn3I3NSX18faxDIsmKCUMMxG eDUV2yi+RUqHmOrduoVhll73K/zz+n7a6WTut1C+7lYxhSMGShGhsCRvYMDMwkz0uFqj 875w== 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=4+zXQMX56k3zAOtsl6CxPR3QS5xL0VyjSuXsK0i5xcI=; b=E3BZFIw5BrZzMSWRwQKjQLQq4f9TxAj/OoA37BYCJUT8szePwLzCiRFsyWZaCE+2Mi rlmoAyH1e5az5oWPZlog5L2dkxxjyU3tMNcQVtjq2GF2eU2dph7/emDLFzbXB5dmOqEe Hu+EytUGAgVVsNDTWRdm97l1kr6nqmsb09JY0ot4f1SIPPk9QXTmHo6dvCKA3dSGRj9h wPD97piyvRizHCPr3m9Z/wv+wu4B2dc74W8teCk8njNbCexr17ybG7ldZj33siV0cs49 c8bS1NTl+W1VutnBvZLYjAxUrQhkcQzbOjU7Aef4ftKw1/ecvGtd9uQClDjMx2RmBmnv yGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=081ywrFE; 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 9si5848144ilg.48.2021.05.10.05.42.00; Mon, 10 May 2021 05:42:14 -0700 (PDT) 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=081ywrFE; 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 S1348138AbhEJMkQ (ORCPT + 99 others); Mon, 10 May 2021 08:40:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:33952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238020AbhEJLQt (ORCPT ); Mon, 10 May 2021 07:16:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 94F956134F; Mon, 10 May 2021 11:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620645125; bh=xJpKT9jbw9nlEjm3sZDy1uV1JBWCXPSZ6iR1738HbsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=081ywrFE/NvF7RsiM5MQZMdyyyFIFFk5wJjLQrRHI9Rf7w9cQoAInW25rukrmn+5+ f7Ek4N0qGrPii7GuRIHK9U3yZq/QHchzv0cE9MojqNN6knAb0oket1lpUJa77rAxuD HRKVGcHUehNuHhrmlvnvbN/5JT3pt+v/j7I4Burs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+be51ca5a4d97f017cd50@syzkaller.appspotmail.com, Palash Oswal , Jens Axboe Subject: [PATCH 5.12 362/384] io_uring: Check current->io_uring in io_uring_cancel_sqpoll Date: Mon, 10 May 2021 12:22:31 +0200 Message-Id: <20210510102026.695307574@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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: Palash Oswal commit 6d042ffb598ed83e7d5623cc961d249def5b9829 upstream. syzkaller identified KASAN: null-ptr-deref Write in io_uring_cancel_sqpoll. io_uring_cancel_sqpoll is called by io_sq_thread before calling io_uring_alloc_task_context. This leads to current->io_uring being NULL. io_uring_cancel_sqpoll should not have to deal with threads where current->io_uring is NULL. In order to cast a wider safety net, perform input sanitisation directly in io_uring_cancel_sqpoll and return for NULL value of current->io_uring. This is safe since if current->io_uring isn't set, then there's no way for the task to have submitted any requests. Reported-by: syzbot+be51ca5a4d97f017cd50@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: Palash Oswal Link: https://lore.kernel.org/r/20210427125148.21816-1-hello@oswalpalash.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -9005,6 +9005,8 @@ static void io_uring_cancel_sqpoll(struc s64 inflight; DEFINE_WAIT(wait); + if (!current->io_uring) + return; WARN_ON_ONCE(!sqd || sqd->thread != current); atomic_inc(&tctx->in_idle);