From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67F2FBA49 for ; Tue, 7 Mar 2023 18:32:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E4DC433D2; Tue, 7 Mar 2023 18:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678213924; bh=Rhg17fZJvSBTmZQ07asP2+nngFnAzMKw0sAvwzynhG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eJdq0+FSijfdQfhdd7CF5c4G8t+aE8//Wf51qugzrV1uXoqsz6/IhFhTCvectQzah 2Nkrw5YEwSy7fne9PD492z2QwXnykfpQMLY8rJDtGoBgHzhtz5JAJ8fAWt2sbbfmSU 8ZGveXSwepcbqXXSnfsw8PNP/eZjAp6zQRJtC2yY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pavel Begunkov , Jens Axboe Subject: [PATCH 6.1 662/885] io_uring/rsrc: disallow multi-source reg buffers Date: Tue, 7 Mar 2023 17:59:56 +0100 Message-Id: <20230307170030.923135015@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170001.594919529@linuxfoundation.org> References: <20230307170001.594919529@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Pavel Begunkov commit edd478269640b360c6f301f2baa04abdda563ef3 upstream. If two or more mappings go back to back to each other they can be passed into io_uring to be registered as a single registered buffer. That would even work if mappings came from different sources, e.g. it's possible to mix in this way anon pages and pages from shmem or hugetlb. That is not a problem but it'd rather be less prone if we forbid such mixing. Cc: Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- io_uring/rsrc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1147,14 +1147,17 @@ struct page **io_pin_pages(unsigned long pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM, pages, vmas); if (pret == nr_pages) { + struct file *file = vmas[0]->vm_file; + /* don't support file backed memory */ for (i = 0; i < nr_pages; i++) { - struct vm_area_struct *vma = vmas[i]; - - if (vma_is_shmem(vma)) + if (vmas[i]->vm_file != file) { + ret = -EINVAL; + break; + } + if (!file) continue; - if (vma->vm_file && - !is_file_hugepages(vma->vm_file)) { + if (!vma_is_shmem(vmas[i]) && !is_file_hugepages(file)) { ret = -EOPNOTSUPP; break; }