Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4903378rwr; Mon, 8 May 2023 14:41:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7zSpextjuI6RfuPk6G8W2+d4tz84G2PyHU8bdu7799YAY55pk6xAff0D1Q6oECuBJct7Xq X-Received: by 2002:a17:90b:400a:b0:24e:1c3d:e624 with SMTP id ie10-20020a17090b400a00b0024e1c3de624mr11246854pjb.25.1683582065529; Mon, 08 May 2023 14:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683582065; cv=none; d=google.com; s=arc-20160816; b=gh+G4smB78kU5/qijlJ0eGQxtIVFynw5JyRNm0ae5UMR+CTAIDLvHujELr/APxJxlp VKt8ZHSEsHRn8+aoQfLP7vog1zo/gOfdHphlmeZjXmTWHWGT+7/d+rTxGugP8sDpxmTU FacVjCuWbm9saV8i+lFbh7CrpibsXhGTBI0fQ5IQyOKKnXIkER8tKWQ18jRmS96eqI2Y 2TS4JPTb6gva2jBQRqEiUQIsS/CFA97c5KFSnnAqOrxOgCrTrk5WFlR72yL/SGR0X1x9 6Vx1csQ1vrA92Z8wJlGYsG34Xm7ZtFePBjOUVEcQ4F/t5BUkMVd0PtM+rGCQ9wsvzBiH Tguw== 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:dkim-signature; bh=sluKTgzIYnZt5qgmSic5hrYiEppZOIqLRDgvZHsGOvg=; b=jFEX/kmxADjoa7G0cPKrGF+YIabOUDWeFay3RTS4zw39eWiiopTouMNDIjpEvNPFhr 463TSSEakgpe7XzBWbOFgvAZy9GWdNTydLYRK+2wv5F6QYVWEJM7RKPXNnXVGeeDTIzF ACaEXAAEvg7mlxS4OSFG8JxGTn+kizp/pfYn8ian6rGx5G7/fOl2b7LNrO8GUCCDTcLE sMA6VY7+dmcIKbyVhiVjSNLRS7eyk5jwApgR9qmPg/U4tI9anZJCJF+kW3m16hIO2waV OXNRiXHBL084Z/GqOqxN6BDe6NOUyvmNvaHzFRm+EjGPI9z3XXiFBW+N+GECVa0PPx+B Uahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="J20RWy6/"; 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 v16-20020a63d550000000b0052c8d4d0d1esi9043905pgi.364.2023.05.08.14.40.51; Mon, 08 May 2023 14:41:05 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="J20RWy6/"; 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 S234299AbjEHViE (ORCPT + 99 others); Mon, 8 May 2023 17:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233845AbjEHVhr (ORCPT ); Mon, 8 May 2023 17:37:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF371BF1; Mon, 8 May 2023 14:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sluKTgzIYnZt5qgmSic5hrYiEppZOIqLRDgvZHsGOvg=; b=J20RWy6/4iso/DH1JGHycdBG0r Z5Tjbp+CA/ex5lfSnUnNGDfA3i6ZZuNLeko++UyfbmKyIZAYT79WhIXzqkndFhBrmrJ4RIoeGXlHV ZxO9XFZEpzWDhmBJ2VmrDdTbzemFPmMjrA0N0DIho+cfVhw/UR+CAJ0s6JSQYbwk27vAB39yR/Q0W tkvIdHZ0/PjcqlSeV6Lz2ghIxHpPFrDWZpJacfqaDv6jGmtIJU34dCW5kpz4tD3vZUot2+W0emthM rThRBoBxnJoFzTuKfkuUZMonUDdPZWzEfNVoiFV63EkN5/cG9UltQxIyLIeAJQoKzgWVH784EiW/V hv1yQzgA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pw8XE-00EWN6-P4; Mon, 08 May 2023 21:36:44 +0000 Date: Mon, 8 May 2023 22:36:44 +0100 From: Matthew Wilcox To: Pasha Tatashin Cc: Ruihan Li , syzbot+fcf1a817ceb50935ce99@syzkaller.appspotmail.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: usbdev_mmap causes type confusion in page_table_check Message-ID: References: <000000000000258e5e05fae79fc1@google.com> <20230507135844.1231056-1-lrh2000@pku.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 08, 2023 at 05:27:10PM -0400, Pasha Tatashin wrote: > > static void page_table_check_set(struct mm_struct *mm, unsigned long addr, > > unsigned long pfn, unsigned long pgcnt, > > bool rw) > > { > > // ... > > anon = PageAnon(page); > > for (i = 0; i < pgcnt; i++) { > > // ... > > if (anon) { > > BUG_ON(atomic_read(&ptc->file_map_count)); > > BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw); > > } else { > > BUG_ON(atomic_read(&ptc->anon_map_count)); > > BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0); > > } > > // ... > > } > > // ... > > } > > > > This call to PageAnon is invalid for slab pages because slab reuses the bits > > in struct page/folio to store its internal states, and the anonymity bit only > > exists in struct page/folio. As a result, the counters are incorrectly updated > > and checked in page_table_check_set and page_table_check_clear, leading to the > > bug being raised. > > We should change anon boolean to be: > > anon = !PageSlab(page) && PageAnon(page); No. Slab pages are not elegible for mapping into userspace. That's all. There should be a BUG() for that. And I do mean BUG(), not "return error to user". Something has gone horribly wrong, and it's time to crash.