Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5557351rwe; Tue, 18 Apr 2023 08:20:51 -0700 (PDT) X-Google-Smtp-Source: AKy350YgKGUVAJ/zLJ8RGpRggVQKBzF4JajHyRTqPVGFsMGmBHXNGx4XVpL5IRi/P0xwEDuB7/CH X-Received: by 2002:a05:6a21:6d96:b0:ef:2389:66c5 with SMTP id wl22-20020a056a216d9600b000ef238966c5mr209564pzb.12.1681831251099; Tue, 18 Apr 2023 08:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681831251; cv=none; d=google.com; s=arc-20160816; b=wytduIQqNrnbPiwCC7RR1HOaK89/N+zCi+rfBIymbZEvBp7v4n/j6sWz9k80zF87At V91ysgfnYLrIAqAgDsWsVxA3pqP28S2WjTOE6EWFB1rMxysiAnONzHoLpwUNGIFaGd/Y vtmvtBirPS60d821NqcEXoJI9Cb8G6ffQMTpTUSLy7BH54wYGU/RL3xFKsrLlipP1+zX IYFrwz3Bk/fl38P9J6jQxWDG0r3FB9v4N7tN032Xbawwp3RADIcfc9hnDR5Oe058goNK EHMmGFrECnq8uHYopjugCqHtETDeoltwN0dfiG5sYQIKGH+9dHbwPmBpJUOEN5LIrepr +lhg== 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=uEbLiIoDuJvtlF8aE44HZGzs1BH3gYE48UCaK8yzhWk=; b=IgM0TLzcpXBU7OuxduMhm63sHaKX/WGKiGw/yEVsqTC5vR35Rgte7Gt1/BHYrRAkbs bKFOx8W5YZNs3gy00uGZCuAR10DNkegWufbqo8JN/1TQg+yoCkLssRT2Rb/IFs5JjIhG YGuCjmrHHZyM1IXW1nnfesVrgM9QuEpwjHepDHF03BJoNsfqjEHal6c3gIF4aCCS/v8N 9b2MZWIu49LfcTP+DJjBKAAS6t+4av4EfJlgtD+5egS6XR8XVY039caSMYEIHuvnNjyP mhp0CbKWE10V3TJx77UUaXQJ6HE7xY1BQ22TV2M+2s/G2ViR72FRFvDvtgwaxTzIjKtW a9Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XpQQxR9J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r26-20020aa7963a000000b0063b858960fasi7702258pfg.127.2023.04.18.08.20.35; Tue, 18 Apr 2023 08:20:51 -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=@redhat.com header.s=mimecast20190719 header.b=XpQQxR9J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjDRPP3 (ORCPT + 99 others); Tue, 18 Apr 2023 11:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjDRPP2 (ORCPT ); Tue, 18 Apr 2023 11:15:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87CEFAF17 for ; Tue, 18 Apr 2023 08:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681830881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uEbLiIoDuJvtlF8aE44HZGzs1BH3gYE48UCaK8yzhWk=; b=XpQQxR9J9MM1BrrOxyHgk2Kh5rliwoG9NNURxMOrVCdnagSCBb8JNk/eDd1itXyjGkDcKr CnLYcGuQGRYUW5+51sZR0qfFxIcCue1D1/E+Fx9ORr6GKIc7zxSK1sc+I6mzy67ZQgnupo syXJKWDphzYoqyw+6ypzpp9TEO+0Rus= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-FVzIqMigP-eBeHQuQImJLg-1; Tue, 18 Apr 2023 11:14:40 -0400 X-MC-Unique: FVzIqMigP-eBeHQuQImJLg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74d96c33de9so59662185a.1 for ; Tue, 18 Apr 2023 08:14:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681830879; x=1684422879; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uEbLiIoDuJvtlF8aE44HZGzs1BH3gYE48UCaK8yzhWk=; b=N6vZTzW5P5x5Q9FMMPxNd+JkS7h103XGp5EMgtsvjQ3NoutpKXSvw+BiD7tASbA6L9 4gj3Fjn38iESJiZUfH5NjvGK+UnRPuwvbuuqaONt28CshAddFXjuSTsZn20YZFE58LF+ yh5xDANdAFFzRJ2azvpP3dR+n7meLWes7oW5TqUoOQZcUHMQUWx0a8Rt4t/26nlV7FH6 JWf4lyyLsRAHomp/IikRiB4riol/kpeFLFrwNzCp0rLezuiGRv9yoJbzjzv8KegiAYIv q+FbOAdrZLVXRgFteKXrDnvqINNkGxXpsT7mEvdU8m5F0MjZnBHeCb4ZW/KKdFADg+1N 66vA== X-Gm-Message-State: AAQBX9dI/Zd7yCANu9y5FWSFHdo78HGo5+Xz1DM6fjTY6FwoTI/T2G1I +zu6MGbCu0uCAtWC8kOxs5CzeawGjO2uhy77ki8GVsRDUvl8JfE3sA8KlsQLkDuylt24sen+dfu TQu9N7v12iguu3NhJaW3ZRPsw X-Received: by 2002:a05:6214:5083:b0:5df:4d41:9560 with SMTP id kk3-20020a056214508300b005df4d419560mr22254099qvb.0.1681830879175; Tue, 18 Apr 2023 08:14:39 -0700 (PDT) X-Received: by 2002:a05:6214:5083:b0:5df:4d41:9560 with SMTP id kk3-20020a056214508300b005df4d419560mr22254071qvb.0.1681830878851; Tue, 18 Apr 2023 08:14:38 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id mf10-20020a0562145d8a00b005dd8b9345d2sm3730109qvb.106.2023.04.18.08.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 08:14:37 -0700 (PDT) Date: Tue, 18 Apr 2023 11:14:36 -0400 From: Peter Xu To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , Andrea Arcangeli , Mika =?utf-8?B?UGVudHRpbMOk?= , Axel Rasmussen , Nadav Amit , David Hildenbrand , linux-stable Subject: Re: [PATCH v2 2/6] mm/hugetlb: Fix uffd-wp bit lost when unsharing happens Message-ID: References: <20230417195317.898696-1-peterx@redhat.com> <20230417195317.898696-3-peterx@redhat.com> <20230417164822.d1f5d162115c53aab4c85e85@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230417164822.d1f5d162115c53aab4c85e85@linux-foundation.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Andrew, On Mon, Apr 17, 2023 at 04:48:22PM -0700, Andrew Morton wrote: > On Mon, 17 Apr 2023 15:53:13 -0400 Peter Xu wrote: > > > When we try to unshare a pinned page for a private hugetlb, uffd-wp bit can > > get lost during unsharing. Fix it by carrying it over. > > > > This should be very rare, only if an unsharing happened on a private > > hugetlb page with uffd-wp protected (e.g. in a child which shares the same > > page with parent with UFFD_FEATURE_EVENT_FORK enabled). > > What are the user-visible consequences of the bug? When above condition met, one can lose uffd-wp bit on the privately mapped hugetlb page. It allows the page to be writable even if it should still be wr-protected. I assume it can mean data loss. However it's very hard to trigger. When I wrote the reproducer (provided in the last patch) I needed to use the newest gup_test cmd introduced by David to trigger it because I don't even know another way to do a proper RO longerm pin. Besides that, it needs a bunch of other conditions all met: (1) hugetlb being mapped privately, (2) userfaultfd registered with WP and EVENT_FORK, (3) the user app fork()s, then, (4) RO longterm pin onto a wr-protected anonymous page. If it's not impossible to hit in production I'd say extremely rare. > > > Cc: linux-stable > > When proposing a backport, it's better to present the patch as a > standalone thing, against current -linus. I'll then queue it in > mm-hotfixes and shall send it upstream during this -rc cycle. > > As presented, this patch won't go upstream until after 6.3 is released, > and as it comes later in time, more backporting effort might be needed. > > I can rework things if this fix is reasonably urgent (the "user-visible > consequences" info is the guide). If not urgent, we can leave things > as they are. IMHO it's not urgent so suitable for mm-unstable (current base of this set; sorry if I forgot to mention it explicitly). I'll post (and remember to post) patches on top of mm-stable if they're urgent, or e.g. bugs introduced in current release. I copied stable for the pure logic of fixing a bug in old kernels. The consequence of hitting the bug is very bad but chance to hit is very low. Thanks, -- Peter Xu