From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4112C35247 for ; Wed, 5 Feb 2020 16:52:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 779EC20674 for ; Wed, 5 Feb 2020 16:52:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="MmkLrMyy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727083AbgBEQwp (ORCPT ); Wed, 5 Feb 2020 11:52:45 -0500 Received: from mail-il1-f196.google.com ([209.85.166.196]:40460 "EHLO mail-il1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbgBEQwo (ORCPT ); Wed, 5 Feb 2020 11:52:44 -0500 Received: by mail-il1-f196.google.com with SMTP id i7so2429553ilr.7 for ; Wed, 05 Feb 2020 08:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=kVisYlHjgDUQz0luYS84AW0y0CIaKZqaVDGoqmEU6RU=; b=MmkLrMyyfoG1gUTS6tU9ThTU5hElGpTSBw5TLQSunm+iTehLGMOSzK65m7NuWKWFv9 9BDLpQAHhv46s3uKYsqjlZXYlJDx2FoXPG6pOvTQQDkQfqrVBjq4vpBKmGB0b5k2ODlf mq2ysYDet++HKskxbQXDccCD/EdxHQSNAcEebQ73o3DkqP5BrZAb1fWwiImcSR56NAKi 3YnVwMGdFYib9GUI6YfdsRq3qZjhkcEfcQx9IkZye0tEFjJ2DxtqjmtkfoiAHAogbRWA pyPfCctu+VwDTqL1UlF4LzK+9eCNAPAy2vChIAJRL+L9pBZEIm53gZuRzKY2vgfHilPY vI/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kVisYlHjgDUQz0luYS84AW0y0CIaKZqaVDGoqmEU6RU=; b=jflSkP1lCigooum3H+zlaJxUffVklcjWbXIskGADthlGMc/UK6sTszoasPqRIpv6/X Lfe+5AdyvuGVWo8nJBC8ylq9asUuGkIrso/8njvrvzl45ES8HpFzvBj0v97iPVHrFNGw a14E7iMzh8mKK/a5GA0PeGRmZl8mAppHYb0J2CsyWRxqz3YrmwKTPwzEEV8d/QNs1Lve G+nc/ztrXSXYDndUi5vx1WvbphGZ2fqxVdGn10vg7muup2yhN1rGDKS43M8hwmFwChzc zT07lr9j+m1bqVl0U+SeM46MDHtNKE/4rPMx5kSa1F1yVCAoHuZeSbcbPZOxJzeCco4B DUrg== X-Gm-Message-State: APjAAAV9dHwStB/bAHkotELz3UqON+C/EzQ0KR3VybRhT6+At7jF8ilp 61pqvC4TzP4/zfsXJ+l5AfrFsw== X-Google-Smtp-Source: APXvYqyjKlq3/gWCB7sCS+DZSxiGGmEJ6N0g9df1NfetAcfyAepGVSobi+rCOfJ4px4cKUlcsRIk0Q== X-Received: by 2002:a92:d9ce:: with SMTP id n14mr27423896ilq.25.1580921562847; Wed, 05 Feb 2020 08:52:42 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id q90sm40606ili.27.2020.02.05.08.52.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Feb 2020 08:52:42 -0800 (PST) Subject: Re: [PATCH] io_uring: fix mm use with IORING_OP_{READ,WRITE} To: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <951bb84c8337aaac7654261a21b03506b2b8a001.1580914723.git.asml.silence@gmail.com> <62e33e81-7857-fb5c-92be-6757623a6478@gmail.com> From: Jens Axboe Message-ID: Date: Wed, 5 Feb 2020 09:52:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <62e33e81-7857-fb5c-92be-6757623a6478@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 2/5/20 9:50 AM, Pavel Begunkov wrote: > On 05/02/2020 19:16, Jens Axboe wrote: >> On 2/5/20 9:05 AM, Jens Axboe wrote: >>> On 2/5/20 9:02 AM, Pavel Begunkov wrote: >>>> On 05/02/2020 18:54, Jens Axboe wrote: >>>>> On 2/5/20 8:46 AM, Pavel Begunkov wrote: >>>>>> IORING_OP_{READ,WRITE} need mm to access user buffers, hence >>>>>> req->has_user check should go for them as well. Move the corresponding >>>>>> imports past the check. >>>>> >>>>> I'd need to double check, but I think the has_user check should just go. >>>>> The import checks for access anyway, so we'll -EFAULT there if we >>>>> somehow messed up and didn't acquire the right mm. >>>>> >>>> It'd be even better. I have plans to remove it, but I was thinking from a >>>> different angle. >>> >>> Let me just confirm it in practice, but it should be fine. Then we can just >>> kill it. >> >> OK now I remember - in terms of mm it's fine, we'll do the right thing. >> But the iov_iter_init() has this gem: >> >> /* It will get better. Eventually... */ >> if (uaccess_kernel()) { >> i->type = ITER_KVEC | direction; >> i->kvec = (struct kvec *)iov; >> } else { >> i->type = ITER_IOVEC | direction; >> i->iov = iov; >> } >> >> which means that if we haven't set USER_DS, then iov_iter_init() will >> magically set the type to ITER_KVEC which then crashes when the iterator >> tries to copy. >> >> Which is pretty lame. How about a patch that just checks for >> uaccess_kernel() and -EFAULTs if true for the non-fixed variants where >> we don't init the iter ourselves? Then we can still kill req->has_user >> and not have to fill it in. >> >> > On the other hand, we don't send requests async without @mm. So, if we fail them > whenever can't grab mm, it solves all the problems even without extra checks. > What do you think? I agree, the check is/was just there as a safe guard, it's not really needed. -- Jens Axboe