Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp771813ybl; Wed, 11 Dec 2019 07:17:25 -0800 (PST) X-Google-Smtp-Source: APXvYqw+HNhuEHoLOjYGWzffYvHv2LKZ5gB6jLa5nFrIOO/Ne8sbtThmlxPzk5ASZ4BoMe6YUuqT X-Received: by 2002:a05:6830:158d:: with SMTP id i13mr2724656otr.33.1576077445289; Wed, 11 Dec 2019 07:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077445; cv=none; d=google.com; s=arc-20160816; b=yPocaN7POq1fxP4/nXzRRit5RFzFD9g43u6WXTc3ggddj20i/XjhU2Fkv33vlQ4c/j duK3SV1T6Yt7qMYi7PsR70BRN+rW8f74JI2mBWmmPA4m407RGlcLRRgroBvflKyccAk4 X87sRKR6UUE8BINXrriesMmJHmbkRL95LrodewKWbgKNIk34SbdUmukMMaaePy474AGz Ssvuit7/MrOY3vSjj1USwjhOIQQohuP8O2h43shaMZdg19iZEs/XscKx84mnExQ7aXHV BglHN58CasB3MUwX6HMQuHSC1ARRKcRFNYlHvwNwTJzOvrmq1IEHpJJQoU3jc8mXLCwD ZA2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lPFTK8h3xWF5cOyIq3eLNUS37rP59pEjZcx8pq1ioDk=; b=QaZ2W4fOkLiD3WUXON0MmIPkdoLUQyEduCw+m17hrbHVNiFJUCosPMbQQ7gK7N7+PC uZ+LY21De6vtlM/mFOPen8bvlrfncXxgIN8mTT7P7b2k+P4ncV0jBcKoDZEmZGot9grs OkWLLSiamGMVxy9v/3TRs+ZxKx9QSY5r1O1AlVqwqqZ0lkj3hgfVuQq7LcGsWKbQzjVz LIBoCJP1V2YbLBmUhs33x2X77oTzoXvxtVDmR0LG40NnFP+cU8QPAnYpwcvHfIDjRdj6 E8uz1R4p/qHxZI1y0xF5iwGQJ0FPkvUtL90PchyyxQjrAPCQF5LSm4feeoVpl4x4kp8G M4zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9PnWj4+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l19si1286278oii.54.2019.12.11.07.17.13; Wed, 11 Dec 2019 07:17:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B9PnWj4+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731744AbfLKPPU (ORCPT + 99 others); Wed, 11 Dec 2019 10:15:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:39130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731598AbfLKPOM (ORCPT ); Wed, 11 Dec 2019 10:14:12 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D561524682; Wed, 11 Dec 2019 15:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077252; bh=2j01xrxU82dvx7hc0Z9HeqJbY1k1vJAGGnbMsKIBhaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9PnWj4+dPe787OHLrW3zogRQ0fFNCdvXN1dPXGvfKu3gJbJpgczJ35UHhPMAwKNA 0wEJ471Ak1gRUbONMJimr2tKCbOW3RHYPVbit9ItyXFoizqO9Pwq8cImrTmAE2OnML OvAnK/H6do5W7bUlSHhYYeoPwtHTWc8vQnqHxe9k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Andres Freund , Jens Axboe Subject: [PATCH 5.3 047/105] io_uring: ensure req->submit is copied when req is deferred Date: Wed, 11 Dec 2019 16:05:36 +0100 Message-Id: <20191211150240.986496848@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe There's an issue with deferred requests through drain, where if we do need to defer, we're not copying over the sqe_submit state correctly. This can result in using uninitialized data when we then later go and submit the deferred request, like this check in __io_submit_sqe(): if (unlikely(s->index >= ctx->sq_entries)) return -EINVAL; with 's' being uninitialized, we can randomly fail this check. Fix this by copying sqe_submit state when we defer a request. Because it was fixed as part of a cleanup series in mainline, before anyone realized we had this issue. That removed the separate states of ->index vs ->submit.sqe. That series is not something I was comfortable putting into stable, hence the much simpler addition. Here's the patch in the series that fixes the same issue: commit cf6fd4bd559ee61a4454b161863c8de6f30f8dca Author: Pavel Begunkov Date: Mon Nov 25 23:14:39 2019 +0300 io_uring: inline struct sqe_submit Reported-by: Andres Freund Reported-by: Tomáš Chaloupka Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1787,7 +1787,7 @@ static int io_poll_add(struct io_kiocb * } static int io_req_defer(struct io_ring_ctx *ctx, struct io_kiocb *req, - const struct io_uring_sqe *sqe) + struct sqe_submit *s) { struct io_uring_sqe *sqe_copy; @@ -1805,7 +1805,8 @@ static int io_req_defer(struct io_ring_c return 0; } - memcpy(sqe_copy, sqe, sizeof(*sqe_copy)); + memcpy(&req->submit, s, sizeof(*s)); + memcpy(sqe_copy, s->sqe, sizeof(*sqe_copy)); req->submit.sqe = sqe_copy; INIT_WORK(&req->work, io_sq_wq_submit_work); @@ -2114,7 +2115,7 @@ static int io_queue_sqe(struct io_ring_c { int ret; - ret = io_req_defer(ctx, req, s->sqe); + ret = io_req_defer(ctx, req, s); if (ret) { if (ret != -EIOCBQUEUED) { io_free_req(req);