Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2626257rdb; Wed, 15 Nov 2023 06:20:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlbWe4MmYMMTmHNA9Oak2R05RqrC145e/+9ODY3M000FN/pyz+4pHc+Gar2aFHX3PBmWAM X-Received: by 2002:a05:6a20:3d20:b0:186:7eaf:717e with SMTP id y32-20020a056a203d2000b001867eaf717emr9831470pzi.20.1700058010139; Wed, 15 Nov 2023 06:20:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700058010; cv=none; d=google.com; s=arc-20160816; b=Miv5rPvgygsWz639P47KF7IGS9ZqkxUo/RfZO7gdZryxhI0XSXZg8hR7LxuUpHAgI3 xLO7S6mwWjzqZftIERQLbT7IY6aAt7S0iCRoR+CRyomBoZAHKSb/3JrwBN8AJhSFoEQd 5KSVPHZ4kz2rGZWMr3afOnyeIMf4XWE4CfOv82kVtAngdHv+I6frTQc6cIJjzuwECgY8 H7v/Ck2j7cU9GNZcCpmnfi4tAgMPmj/XbP9LbVYDDIhuLMCLdgK8ZuHjCHgdDo6Dq2dV CMchzHI5r7A719u/oM9yvc3btrX0nv0oO7BCQWK1ffuZsqmEXy21Tz5aJw6vfDeb+Tok YJAA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8wVh7DNUM7SnBmRuhtk1Q8XS+buoIAZhntJMpDAZN9s=; fh=NQnj/rchRllh9GSRuGOWJu6NLsiHALFP7nyEQF3YpBg=; b=zwl9LKg7Me6kO93ulsI3vIo/26RETKguTMTkHqu2KeK+2c5PpEcB2ucn/GJkQHkj3s P4R82noePKRBAPJ7FbdhZwfsBgl0k+cki8j+DjYTpzBjfjV/NC2DNbAVQnj5BsPnWIbs 7tNOhaIC8ESsp8XG9tjASPubiJq8Z0SzGkpAT5Apfn+gNyHzmG5pYUsKPNBxi6f1marZ yyRaJDpC06YR8dI4uURjmq8ktcv2onDnwedTVkBF+0ubI7be6bbCkhpSwrPt+MeMT/kI I2tMPb5bP4rIb9m5d6BZAM79OS41k2YR0PIUuW0A0nLVShpNJ7N+gtkhhWiG/HrP8gf5 NtVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CkLWirzP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id fc5-20020a056a002e0500b006be1dd2313asi10452200pfb.210.2023.11.15.06.19.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 06:20:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CkLWirzP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 116C4809646D; Wed, 15 Nov 2023 06:19:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344181AbjKOOTm (ORCPT + 99 others); Wed, 15 Nov 2023 09:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344159AbjKOOTl (ORCPT ); Wed, 15 Nov 2023 09:19:41 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 014F3C5 for ; Wed, 15 Nov 2023 06:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=8wVh7DNUM7SnBmRuhtk1Q8XS+buoIAZhntJMpDAZN9s=; b=CkLWirzPtZyuIqJtO/yj4dR8ED VmPqsDv+N0TdxUVmsRFwrWQj428Pmah59NVEjJB74wg7JRFWMvDES4RAXI9s7RpUvvjsPrNIaaXVg N4T8JsQefBRczx7SkSy1sCw/4fIDjOfo6LYqXqTQDZtZppFsQ5g7OUqg31qMMKPCBM4LATNf2eueY 0ZKJKBE/hNWqK1goS88kx5kDx3DD1zY6cawzbRihDONBejLL2aXY9GaNa8LZigajivqS5JyVvHK20 qcUrWVVlFGUmCAfPwFZSQa/9cUWiN1fNuN1bmLu26zaIonEcKla7dquCqe2QTG+ymhPukrViod3+v YRk+8CXw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r3Gjm-00EekH-Dv; Wed, 15 Nov 2023 14:19:26 +0000 Date: Wed, 15 Nov 2023 14:19:26 +0000 From: Matthew Wilcox To: =?iso-8859-1?Q?Jos=E9?= Pekkarinen Cc: akpm@linux-foundation.org, skhan@linuxfoundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linux.dev, syzbot+89edd67979b52675ddec@syzkaller.appspotmail.com, Hugh Dickins Subject: Re: [PATCH] mm/pgtable: return null if no ptl in __pte_offset_map_lock Message-ID: References: <20231115065506.19780-1-jose.pekkarinen@foxhound.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231115065506.19780-1-jose.pekkarinen@foxhound.fi> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 06:19:53 -0800 (PST) On Wed, Nov 15, 2023 at 08:55:05AM +0200, Jos? Pekkarinen wrote: > Documentation of __pte_offset_map_lock suggest there is situations where You should have cc'd Hugh who changed all this code recently. > a pmd may not have a corresponding page table, in which case it should > return NULL without changing ptlp. Syzbot found its ways to produce a > NULL dereference in the function showing this case. This patch will > provide the exit path suggested if this unlikely situation turns up. The > output of the kasan null-ptr-report follows: There's no need to include all this nonsense in the changelog. > spin_lock include/linux/spinlock.h:351 [inline] > __pte_offset_map_lock+0x154/0x360 mm/pgtable-generic.c:373 > pte_offset_map_lock include/linux/mm.h:2939 [inline] > filemap_map_pages+0x698/0x11f0 mm/filemap.c:3582 This was the only interesting part. > +++ b/include/linux/mm.h > @@ -2854,7 +2854,7 @@ void ptlock_free(struct ptdesc *ptdesc); > > static inline spinlock_t *ptlock_ptr(struct ptdesc *ptdesc) > { > - return ptdesc->ptl; > + return (likely(ptdesc)) ? ptdesc->ptl : NULL; > } I don't think we should be changing ptlock_ptr(). > +++ b/mm/pgtable-generic.c > @@ -370,6 +370,8 @@ pte_t *__pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd, > if (unlikely(!pte)) > return pte; > ptl = pte_lockptr(mm, &pmdval); > + if (unlikely(!ptl)) > + return NULL; > spin_lock(ptl); I don't understand how this could possibly solve the problem. If there's no PTE level, then __pte_offset_map() should return NULL and we'd already return due to the check for !pte.