Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3595458pxf; Mon, 15 Mar 2021 13:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCDsN7OvHSZ7qOvF/2EwtH6u7jEGbP9a0XFmugS/0rRb6L4SID8AHmJ5kWGwSXuiguG5jL X-Received: by 2002:a17:907:20e4:: with SMTP id rh4mr26035747ejb.369.1615839613889; Mon, 15 Mar 2021 13:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615839613; cv=none; d=google.com; s=arc-20160816; b=Uy5Altdh/e9+GRW4X4U25bKQadQGVXAY+8DDBBewotSV8JXyH7JxbmVr/X2fuoufkp UD4ybvSzIQHlWMPDDrI3FwbCXzy3UNrXmm3zikqqscD6mPXgg9G7Yt+AHyEKh1BU5dPh +lDaDxmq072NaLIZFN4ikvU9FroQg5qwCLgMQYUAfvSc0Zb3YgsADQCHyG2O7rtYxzbq LYhT8Y/Uq26YgjksFfakTSDQFzbKibXF4oxgCmEbE5IiRzoeiAPdAyvevmlDZeHqySBW AEWf7qiRq94xpGCNyxdxTLAnnA76IHJ1j5nludXHV4t9pz6zcTXRxSulj7KawXAujjSv xL/Q== 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=OUF/gOzlSs5+psMV/9ZzADU6u8vff3i3N2wfNM7ITKI=; b=iihYlz89ngaao/OxVK1mAhykYIVt4XWHuelNCoIXBqBcZi5woBuj5i9y8lrqZBy1OD k3e6F3KhnTxZCcPQ1x7PVUKf1df4crGIfpwVR3vVbIVJL0sjKeSJJE2J5u2m+qCxY9nn WlHiX59vE5YxxcNvKERVAMcaAUHKhpJAmPS5c8XzO94IDyMCTV62MIAu6iSO2IrdsqLZ ywbgtOy0oK3AmAwkXYX5rYSVr52IDcEOxtoX8fzeq90KIQ9ShgtpwLEU6pokrJr5mivC oRmn34bC5AIxdzROvsCAHVFcGrUK5pm7v20TTBejsfedg5bvPDbsHR/f89zTXQBQUc1j F8zw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ho11si11970640ejc.258.2021.03.15.13.19.33; Mon, 15 Mar 2021 13:20:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbhCOR43 (ORCPT + 99 others); Mon, 15 Mar 2021 13:56:29 -0400 Received: from h4.fbrelay.privateemail.com ([131.153.2.45]:38211 "EHLO h4.fbrelay.privateemail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbhCORzg (ORCPT ); Mon, 15 Mar 2021 13:55:36 -0400 X-Greylist: delayed 415 seconds by postgrey-1.27 at vger.kernel.org; Mon, 15 Mar 2021 13:55:35 EDT Received: from MTA-11-4.privateemail.com (mta-11.privateemail.com [198.54.118.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h3.fbrelay.privateemail.com (Postfix) with ESMTPS id 2B6A48142D; Mon, 15 Mar 2021 13:47:30 -0400 (EDT) Received: from mta-11.privateemail.com (localhost [127.0.0.1]) by mta-11.privateemail.com (Postfix) with ESMTP id 56C998008C; Mon, 15 Mar 2021 13:46:29 -0400 (EDT) Received: from pwning.systems.github.io (unknown [10.20.151.213]) by mta-11.privateemail.com (Postfix) with ESMTPA id 0F5288004A; Mon, 15 Mar 2021 13:46:27 -0400 (EDT) From: Jordy Zomer To: axboe@kernel.dk, asml.silence@gmail.com Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Jordy Zomer Subject: [PATCH] Fix use-after-free in io_wqe_inc_running() due to wq already being free'd Date: Mon, 15 Mar 2021 18:44:26 +0100 Message-Id: <20210315174425.2201225-1-jordy@pwning.systems> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org My syzkaller instance reported a use-after-free bug in io_wqe_inc_running. I tried fixing this by checking if wq isn't NULL in io_wqe_worker. If it does; return an -EFAULT. This because create_io_worker() will clean-up the worker if there's an error. If you want I could send you the syzkaller reproducer and crash-logs :) Best Regards, Jordy Zomer Signed-off-by: Jordy Zomer --- fs/io-wq.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/io-wq.c b/fs/io-wq.c index 0ae9ecadf295..9ed92d88a088 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -482,6 +482,10 @@ static int io_wqe_worker(void *data) char buf[TASK_COMM_LEN]; worker->flags |= (IO_WORKER_F_UP | IO_WORKER_F_RUNNING); + + if (wq == NULL) + return -EFAULT; + io_wqe_inc_running(worker); sprintf(buf, "iou-wrk-%d", wq->task_pid); -- 2.25.1