Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2120435rwd; Mon, 15 May 2023 07:31:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6GzGzQaI8E62A6e/2bJ4WFBv8ZTPUk7Wa3oX763ZKZIRwOIG9Fnccltoe09x1RquqIHcwn X-Received: by 2002:a17:90a:df0c:b0:250:8834:307f with SMTP id gp12-20020a17090adf0c00b002508834307fmr25657536pjb.0.1684161119489; Mon, 15 May 2023 07:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684161119; cv=none; d=google.com; s=arc-20160816; b=qUI7+7QhxMBCnAGnaQXQYn9EHAnRSUAxbykUhVM9lFTXRh7jePIJiNZgdja1gYLStb AyspqXelwboAsbhI0kIlnvIqWkrs73rGXHM4ui+slVyz/WMikN5jOw2g48oLvBfNw100 7DSjwWSlcz7sUjDdo/j6z69XQw3khlRs/XTPFoXaHDK2EQJ7/G/kyxIF0Nh0idPVWtzb kgxFbYsRn60X7c/uA4il4GZW8+vrv+lrBBGoCr6unsu4OjbavAtTyIEx/YLEgFRY7bnj GlyrmmolNnMDtX6vHYLoQEpdIpI+42CpaVLHR9aAQSezBMkfTeyuKczKZddV/sE4PTrH 2jIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=jA3QwQjBqDJrJTjgRNETRueuYrj+CbZcHOaOvd2mTCk=; b=sUKvCFwykwk8egRgdZleAujKX5/tIgBZDhPro3tfwPRra5LGcobwwm2M9ylzmUxBLQ 1Ov94QJyBQI7eecM90cYyxgFtNWlDdMGLLPGZQVZHLz+K9Sg+U/xBzGUOItlJgaCGZWi q+wZ6FgL/I5y55bG5qZiz0jVeU7iLc2gA5BtdTO52hY4ONHe8WJ3HjE3kvJOKTaFWLOW Wg/DNjZX6DIPI5IaqluE07cbZCblpF/CkWBjUmrNXgJDUMyE9tbDCSpNkL2uLSgP1/OF dwPpZiZDEL86irc3CnFd+7M764a56xFY8E/jc7VqS2N23HDwz7R9/J3lhf5aH8jTY3vO ajww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a17090a1a4800b0024e47fae466si29444494pjl.180.2023.05.15.07.31.36; Mon, 15 May 2023 07:31:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240244AbjEOOH3 (ORCPT + 99 others); Mon, 15 May 2023 10:07:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239978AbjEOOHW (ORCPT ); Mon, 15 May 2023 10:07:22 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id D1F551982 for ; Mon, 15 May 2023 07:07:16 -0700 (PDT) Received: (qmail 791507 invoked by uid 1000); 15 May 2023 10:07:15 -0400 Date: Mon, 15 May 2023 10:07:15 -0400 From: Alan Stern To: Ruihan Li Cc: linux-mm@kvack.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Pasha Tatashin , David Hildenbrand , Matthew Wilcox , Andrew Morton , Christoph Hellwig , Greg Kroah-Hartman , syzbot+fcf1a817ceb50935ce99@syzkaller.appspotmail.comm, stable@vger.kernel.org Subject: Re: [PATCH v2 1/4] usb: usbfs: Enforce page requirements for mmap Message-ID: <761a2bf5-fdd3-4b4d-a14c-87add51db13a@rowland.harvard.edu> References: <20230515130958.32471-1-lrh2000@pku.edu.cn> <20230515130958.32471-2-lrh2000@pku.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230515130958.32471-2-lrh2000@pku.edu.cn> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 15, 2023 at 09:09:55PM +0800, Ruihan Li wrote: > The current implementation of usbdev_mmap uses usb_alloc_coherent to > allocate memory pages that will later be mapped into the user space. > Meanwhile, usb_alloc_coherent employs three different methods to > allocate memory, as outlined below: > * If hcd->localmem_pool is non-null, it uses gen_pool_dma_alloc to > allocate memory; > * If DMA is not available, it uses kmalloc to allocate memory; > * Otherwise, it uses dma_alloc_coherent. > > However, it should be noted that gen_pool_dma_alloc does not guarantee > that the resulting memory will be page-aligned. Furthermore, trying to > map slab pages (i.e., memory allocated by kmalloc) into the user space > is not resonable and can lead to problems, such as a type confusion bug > when PAGE_TABLE_CHECK=y [1]. > > To address these issues, this patch introduces hcd_alloc_coherent_pages, > which addresses the above two problems. Specifically, > hcd_alloc_coherent_pages uses gen_pool_dma_alloc_align instead of > gen_pool_dma_alloc to ensure that the memory is page-aligned. To replace > kmalloc, hcd_alloc_coherent_pages directly allocates pages by calling > __get_free_pages. > > Reported-by: syzbot+fcf1a817ceb50935ce99@syzkaller.appspotmail.comm > Closes: https://lore.kernel.org/lkml/000000000000258e5e05fae79fc1@google.com/ [1] > Fixes: f7d34b445abc ("USB: Add support for usbfs zerocopy.") > Fixes: ff2437befd8f ("usb: host: Fix excessive alignment restriction for local memory allocations") > Cc: stable@vger.kernel.org > Signed-off-by: Ruihan Li > --- For parts 1/4 and 2/4: Acked-by: Alan Stern Alan Stern