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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85C8EC77B7C for ; Wed, 10 May 2023 15:38:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED8786B0071; Wed, 10 May 2023 11:38:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E88396B0072; Wed, 10 May 2023 11:38:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D50066B0074; Wed, 10 May 2023 11:38:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C276D6B0071 for ; Wed, 10 May 2023 11:38:29 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9041180A4A for ; Wed, 10 May 2023 15:38:29 +0000 (UTC) X-FDA: 80774752338.27.6156095 Received: from zg8tmtyylji0my4xnjqunzqa.icoremail.net (zg8tmtyylji0my4xnjqunzqa.icoremail.net [162.243.164.74]) by imf22.hostedemail.com (Postfix) with ESMTP id 1D88DC0011 for ; Wed, 10 May 2023 15:38:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=pku.edu.cn header.s=dkim header.b=ZHxe2XQz; spf=pass (imf22.hostedemail.com: domain of lrh2000@pku.edu.cn designates 162.243.164.74 as permitted sender) smtp.mailfrom=lrh2000@pku.edu.cn; dmarc=pass (policy=none) header.from=pku.edu.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683733106; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E5X1EnY8H+9y2Bd0/LtCE7uJbb9eEk4yWHczmrin+AY=; b=CVI2bt+u0FeiE5QsR6PUnc43Vl6RcuBev9VPlIcS89Ixkg78zNdk/c6BVmUaB3Wq+/EPQz nagNkSxtiGQLjKgfPw7Hy0slG5L+I4P62P/hm5AC5g7hXuoVSXqWKDxVJmAkOW6EYzh6nn lAy0QvAvZrvrNTIeJQtjbwuFX9a0pms= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=pku.edu.cn header.s=dkim header.b=ZHxe2XQz; spf=pass (imf22.hostedemail.com: domain of lrh2000@pku.edu.cn designates 162.243.164.74 as permitted sender) smtp.mailfrom=lrh2000@pku.edu.cn; dmarc=pass (policy=none) header.from=pku.edu.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683733106; a=rsa-sha256; cv=none; b=fB3CZNBO03e1qdB0NbxtCxKA3WGPfq3yr4Yr7itwJy9EV/dbt5nv/R682aB7hWQni4L1x0 IMmNvTMRan7Wj7lL86pPFUS2jb6r3sBsoEy18PmdM441m9086W/o7OX2EQk5o81IL9663M aMuNmD3l2crbjeop9NdbQe+zKtrEnGA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pku.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=E5X1EnY8H+9y2Bd0/LtCE7uJbb9e Ek4yWHczmrin+AY=; b=ZHxe2XQz9hSXcE4d88DTlLHtyDTyeiwG9+TTEVy0B1FH /GKBjvRkDEncHlC5rfaJ0T2ElgUf0/gMxVf6AHRUNGbvw5m4kkiVXRRZ2WS9mE9V +eeMJuqszXAVs3wTUw3IoDlbAPbUHfJ3DUl683KrLs6B9p06ZsR5W82AhSTQQRs= Received: from localhost (unknown [10.7.101.92]) by front01 (Coremail) with SMTP id 5oFpogCH7b5lultkKXGDAg--.38057S2; Wed, 10 May 2023 23:38:18 +0800 (CST) Date: Wed, 10 May 2023 23:38:12 +0800 From: Ruihan Li To: Alan Stern 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, Ruihan Li Subject: Re: [PATCH 1/4] usb: usbfs: Enforce page requirements for mmap Message-ID: References: <20230510085527.57953-1-lrh2000@pku.edu.cn> <20230510085527.57953-2-lrh2000@pku.edu.cn> <65ae7b7f-9dea-429f-aca6-2ce4a75b6531@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <65ae7b7f-9dea-429f-aca6-2ce4a75b6531@rowland.harvard.edu> X-CM-TRANSID:5oFpogCH7b5lultkKXGDAg--.38057S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCr4DJr48uw4DGF1kJrW5KFg_yoW5uF1fpF WrWr1Yka98tr93CrnIgFn8uFy5Zan5XFy5GryIv34rZr9xZry3Krn0yF45ur1kAr40ga1F qFs0yF1Yka45Za7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBY1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24V AvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IY64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26w 4UJr1UMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbHa0DUUUUU== X-CM-SenderInfo: yssqiiarrvmko6sn3hxhgxhubq/1tbiAgEHBVPy772BUwADsj X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1D88DC0011 X-Stat-Signature: js8z6a3wtud8ba1br4uf6k51ffckhjeo X-HE-Tag: 1683733104-934761 X-HE-Meta: U2FsdGVkX1/tJGV5+eMbyxZQijWNTGVDBysCAqckZEJZzrkn6LWz+DJJVjhLwwK7SnxCa4nCyom7Mxa63RKXiEfKjBelcxI2xN8EnzUw/L1kT3UqcBBa+7O/zmi6jnXrzC4YG1YcrofDNYhSFwEs+Gf2VGflMfHQTh7DXd0NRr5CjGjDoMcXf0pAFWol6cLIlI0mLiv88Dlidj+8yyORCPb9gsoZt0Gd1fT/sjmmE+seVh1Qv36zVW81+1+TvpVAD2GMAUUGPlioBlUIedmr3PR43ot47jeQVz1NqRFPM/mub+BvnpbehjPrVlWgYiZImJW50kq7R15Z3eoGxq2BkWp6pyLCkJgNI0mi6ElSNV+4l8FzVY6OLYiAV30GJYxRLBoIfR4kW+XRhVGYYDNcfwfNfX18mlnQ/2z66bYyWV3op90oQDplv36sE/ddEOKf1a1sPhtZoU2RBClYXMpe4re6TMtU5oz0dK9ZjpS26CR5A9FSmXzsTuNlN5TFftxg/MC5/8PmUmf4YbpxwobgrrGeLkCT+FlIYBGX7UIC0gUH6Q08JzIBzprbGxYAfXBRGpTx/g9OgeKxqM9YiuNy3LcwdUuX09N5eDvbwLRg8i9zc7hNYJslxfhZgsAddUN7OIMM7erANUd6d8AsDcRfIEZwMBd7lZdocre3TySvo396OL/xO3TcJRAm8Go1aerZLAeTv2Trmgn2YZDlhNHi4Vj5evI2YMDPcPWdlCS4KRuCn1iqB9gPPreiTJKGII+4lA/mOTigimtg21KgjjJTyKqG7T+aiMRdWHjOBKh9m0sVJ5S9NKNIDPQbBh3uliJTaUZxLQ/10IrJuMdpVHzfPCP6yhYTurw1NpB3MXWkIM9DXvbbyT/l8syTYRruVVvoC04nxNbiKizc583WyRjowUI5APC+b+N05sfqlHdQmeEK1e3LC8RlIkgtQfDhqCS42NN7SLVEtCh2l+ktqmc 1AUN3Ck1 772O48cAosnIiDBWQz/mUWmbX+6SPq5VdKVygcpHnuW3/NfkfMEH5Snic75oRn4I9u9pwZAM5KbwYgio7FzlzldYwBYqQVxkgslS9boC5ND7bZysHEUxLzfwJruvVDQPl5t/m+q5IVPNRzjeYJja+bF8bmR7+U9ePYLwQ+Va0IBm0aLn8cjbD3kx/ZNwVNUR687v7QCHGQeGsR3S0vCgmj3rFfK5wHH7Q5tfkvXE3B5YLFO1RDjd3xso/LviuXknzyR1c3YdUQ0x7El/G/7XUsYiSxZpC9VspXGS53MN2cBqgaG6kTRRUmSDYyqltFTHcBw43 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Alan, On Wed, May 10, 2023 at 10:37:45AM -0400, Alan Stern wrote: > On Wed, May 10, 2023 at 04:55:24PM +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] > > Cc: stable@vger.kernel.org > > Signed-off-by: Ruihan Li > > --- > > I'm never quite sure about when it makes sense to complain about > stylistic issues. Nevertheless, I'm going to do so here... > > > drivers/usb/core/buffer.c | 41 +++++++++++++++++++++++++++++++++++++++ > > drivers/usb/core/devio.c | 9 +++++---- > > include/linux/usb/hcd.h | 5 +++++ > > 3 files changed, 51 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c > > index fbb087b72..6010ef9f5 100644 > > --- a/drivers/usb/core/buffer.c > > +++ b/drivers/usb/core/buffer.c > > @@ -172,3 +172,44 @@ void hcd_buffer_free( > > } > > dma_free_coherent(hcd->self.sysdev, size, addr, dma); > > } > > + > > +void *hcd_buffer_alloc_pages(struct usb_hcd *hcd, size_t size, > > + gfp_t mem_flags, dma_addr_t *dma) > > +{ > > + if (size == 0) > > + return NULL; > > + > > + if (hcd->localmem_pool) > > + return gen_pool_dma_alloc_align(hcd->localmem_pool, > > + size, dma, PAGE_SIZE); > > C isn't Lisp. Expressions in C are not based entirely around > parentheses, and it's not necessary to align our code based on the > parenthesized sub-expressions to avoid hopelessly confusing the reader. > > The style used in this file (and many other places in the USB core) is > to indent continuation lines by two tab stops. The same comment applies > to all the other continuation lines you added or changed in this patch > and in patch 2/4. > > Alan Stern I'm just a bit shocked to find out that different subsystems might prefer different styles of coding. In the net subsystem, checkpatch.pl will complain that: CHECK: Alignment should match open parenthesis Nevertheless, in the next version, I'll follow the coding style that you have pointed out. Thanks, Ruihan Li