Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4617450pxj; Wed, 12 May 2021 09:20:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJpM9mKsBuK2Mf1bRRiy9quHJJL2m/aosb2j0w6Qd9JDgWp/U8SZ0aOKokk83Z5FMumdR8 X-Received: by 2002:aa7:c390:: with SMTP id k16mr40767115edq.97.1620836399846; Wed, 12 May 2021 09:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836399; cv=none; d=google.com; s=arc-20160816; b=mVE57O/k4F8Ys7ke4cAvVw3+ChiEZAb0jl5JCdU12T8od05vlsui5WaADVkUiRSP03 ++GW2mYRh/4S1Awg2zNbJ2Q9glZrcPa6tDIbunVx5a33tlnQ2zwCP1Y9fMMKQrmorwLk S7lTU0p/vnCp6pA4MNlA0DdGqBF41a0N5NdcKE0uZ6lX3ZFvucWOJjHXfu2EHh45m0dQ 7KF+i6TloiKLm1K7NjHJOcDcES5yjAdHy7SRDZYLK4wQ3gjVXQR7djUA4dNIPN0gybUQ f2N54f94P915UVtlB9KZ2gdMP49vCRv/N1CiceZmiwenx79LzgK3Ww1P6v5w7sI8hSgr uqWA== 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=TVyspuTlAn20RnHBVDmQxHKy085QdezOJIi/xf7LG0U=; b=u32ywRcThFp4LAtq6XEmapAPLP2zqW/FsjBf46Xk6fUSFKNyH+/BGPmFfG46ITdgge jOG5LKaD6Ln0LETWbqLTnEwDaY99ibJPXI6IdZVfU/hMhTnEiIjz22UuiPzwtkBwx9p7 PR42qO2ryFjRluk7J2Q8E+XT/tPbFXxTxrrryf5ZOfYqfVk41KEDMV7gCqqIQ0EqkPVi YrQUl7wB/CqZAkuPXN9obTkjPyIKiSA78qrw8bLUJr6KWc0gvgq+ArO9wPDP/Q+1+L3M ZbPZKccjs3jKLuKbOEtoEP39ORwCjdZ8aVTcnzaxevypLfMPMuvLEyJIsj8krXYyLGb+ 0Mkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U06enR/+"; 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 hq17si193717ejc.641.2021.05.12.09.19.35; Wed, 12 May 2021 09:19:59 -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="U06enR/+"; 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 S239714AbhELQPh (ORCPT + 99 others); Wed, 12 May 2021 12:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:50218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234022AbhELPcB (ORCPT ); Wed, 12 May 2021 11:32:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 31E3461106; Wed, 12 May 2021 15:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832593; bh=om4ymYeSu37bHGDCB/1xijYMwPt9F0hOXoCQtMmZfng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U06enR/+jAVdM2f3f7TnLF9gqTzeZUDIHMbJYkBF32Bo7HLZXbqAZGMy7/rya8wyp 6cFJ52DYB6RT0AJo9PWnySvooSTC3jLgj0WZHvW3E176h9+G4/xUT8HdQDu/rjLdks ePhwd+EMTt2QoU+1JjWiuxbrrIGPGx/Pg1OwqsBU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 344/530] io_uring: fix overflows checks in provide buffers Date: Wed, 12 May 2021 16:47:34 +0200 Message-Id: <20210512144831.099914180@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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: Pavel Begunkov [ Upstream commit 38134ada0ceea3e848fe993263c0ff6207fd46e7 ] Colin reported before possible overflow and sign extension problems in io_provide_buffers_prep(). As Linus pointed out previous attempt did nothing useful, see d81269fecb8ce ("io_uring: fix provide_buffers sign extension"). Do that with help of check__overflow helpers. And fix struct io_provide_buf::len type, as it doesn't make much sense to keep it signed. Reported-by: Colin Ian King Fixes: efe68c1ca8f49 ("io_uring: validate the full range of provided buffers for access") Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/46538827e70fce5f6cdb50897cff4cacc490f380.1618488258.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 55e214defb42..369ec81033d6 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -527,7 +527,7 @@ struct io_splice { struct io_provide_buf { struct file *file; __u64 addr; - __s32 len; + __u32 len; __u32 bgid; __u16 nbufs; __u16 bid; @@ -3996,7 +3996,7 @@ static int io_remove_buffers(struct io_kiocb *req, bool force_nonblock, static int io_provide_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { - unsigned long size; + unsigned long size, tmp_check; struct io_provide_buf *p = &req->pbuf; u64 tmp; @@ -4010,6 +4010,12 @@ static int io_provide_buffers_prep(struct io_kiocb *req, p->addr = READ_ONCE(sqe->addr); p->len = READ_ONCE(sqe->len); + if (check_mul_overflow((unsigned long)p->len, (unsigned long)p->nbufs, + &size)) + return -EOVERFLOW; + if (check_add_overflow((unsigned long)p->addr, size, &tmp_check)) + return -EOVERFLOW; + size = (unsigned long)p->len * p->nbufs; if (!access_ok(u64_to_user_ptr(p->addr), size)) return -EFAULT; -- 2.30.2