Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp59607rdb; Mon, 14 Aug 2023 09:25:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1dWPA9e3mfZwd0uTF4qQFkI5q6l7tyPgsXRqO/yVVCErQGm+C8YRI/wryPoWgoUKcao65 X-Received: by 2002:a17:902:e5d1:b0:1bb:c7bc:ceb4 with SMTP id u17-20020a170902e5d100b001bbc7bcceb4mr11216461plf.60.1692030313555; Mon, 14 Aug 2023 09:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692030313; cv=none; d=google.com; s=arc-20160816; b=PtjMu2lSpY0qVmtJrT//w5q7OlGSwO/sC+kHQcWRpzzZ3pYoTwQr896tb9x6LtV+Gu G0CaogeU3og/AKBKwaAPUJKAt69YkW0PoIJ6HZTA5IzB2C0lyM11uXHDi0JdCDdl4muh 2oz7H7Fhr6e2/ljj7MQ3uh+ojrplF2+hc/qNQofZ965pK4CpVbiT76ZIGQzzJmV7MUgt UTv2FWZaZH2mnIj0W1JXj3Sbl2+PqKLMkav75pop7WUFkWohUgeLXTqBXtQiauPx8VHl CDUAsZN1RqERYp2Y3CD+IeqXqOs6L6ccwWIdnamAqpG5CeUPNVfZLU2tpPf0cp/agQ0M f1lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=v+ZzZLXft52nTXc/yGHvjzSyoTfsadVMBZSnkMauBwU=; fh=SuWWUlXp3vgWhthORSiehfmA5tZVdXV9Pai1unWPq5E=; b=ns5eiuoHmvO/Pjo1R5qqiVUU1uU/b/gcdOnknUW3zzxXqPv8SbsYiI1t9nvaUkV60F SXo0YFnSvMYWFRvzW+KrSYgSVHP6bHGczDLoNIb4PSYO42JwDHx7jr7kfsptbb6y4CNq JUdDAK/k9gybFgjSNvzEsX1eesNjD065pR1fEx3q4v9fZrSWotPW5PYVXwRI5xifPg1q wKefugEx6OBDsFIX4RzzgKANZp7L6S/P8Otc8s8do7TXbncDDCNL4B9Wdm9IzwyUOhkg zV3b/hLjup/AKXyt39L+UOai2Y37cXKsonZZwdoiEK35UPLYL9VFhVw+i8E9WwQuG7ss ACCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=alARDBQe; 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 kb14-20020a170903338e00b001b89bfd0c2csi7796669plb.647.2023.08.14.09.24.10; Mon, 14 Aug 2023 09:25:13 -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=alARDBQe; 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 S230429AbjHNQAK (ORCPT + 99 others); Mon, 14 Aug 2023 12:00:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbjHNP7r (ORCPT ); Mon, 14 Aug 2023 11:59:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3C512D for ; Mon, 14 Aug 2023 08:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692028747; 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=v+ZzZLXft52nTXc/yGHvjzSyoTfsadVMBZSnkMauBwU=; b=alARDBQeVMwiHSCHAVmPwCAL7GJ0MmYXjRi6ohSmS1CEb06/OI51GZ70m/t7oGSv5rLfZb t2WZzgrNpOWThWfeX84voprNvFGOUx4GckqLXNsgsLUWw/+8gMxaqr9gGAeNG1PL+ojZ0A HlpxKBMB6d9LLQIhNr7ojr7N1st5e80= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-235-LYfPDIfUMVCE_zyxgtWkkw-1; Mon, 14 Aug 2023 11:59:03 -0400 X-MC-Unique: LYfPDIfUMVCE_zyxgtWkkw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44E972A59577; Mon, 14 Aug 2023 15:59:03 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.27]) by smtp.corp.redhat.com (Postfix) with SMTP id E7D652166B25; Mon, 14 Aug 2023 15:59:00 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 14 Aug 2023 17:58:20 +0200 (CEST) Date: Mon, 14 Aug 2023 17:58:17 +0200 From: Oleg Nesterov To: David Hildenbrand Cc: Mateusz Guzik , linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, brauner@kernel.org, ebiederm@xmission.com, akpm@linux-foundation.org, linux-mm@kvack.org, koct9i@gmail.com, dave@stgolabs.net Subject: Re: [PATCH] kernel/fork: stop playing lockless games for exe_file replacement Message-ID: <20230814155817.GC17738@redhat.com> References: <20230813123333.1705833-1-mjguzik@gmail.com> <20230814150530.GB17738@redhat.com> <20230814152038.GA2367@redhat.com> <52192c2f-c7b1-9c07-7ca2-10fc6bd347b0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52192c2f-c7b1-9c07-7ca2-10fc6bd347b0@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 08/14, David Hildenbrand wrote: > > >OK, I seem to understand... without mmap_read_lock() it is possible that > > > > - dup_mm_exe_file() sees mm->exe_file = old_exe_file > > > > - replace_mm_exe_file() does allow_write_access(old_exe_file) > > > > - another process does get_write_access(old_exe_file) > > > > - dup_mm_exe_file()->deny_write_access() fails > > > >Right? > > From what I recall, yes. Thanks! but then... David, this all is subjective, feel free to ignore, but the current code doesn't look good to me, I mean the purpose of mmap_read_lock() is very unclear. To me something like if (old_exe_file) { /* * Ensure that if we race with dup_mm_exe_file() and it sees * mm->exe_file == old_exe_file deny_write_access(old_exe_file) * can't fail after we do allow_write_access() and another task * does get_write_access(old_exe_file). */ mmap_read_lock(mm); mmap_read_unlock(mm); allow_write_access(old_exe_file); fput(old_exe_file); } looks more understandable... But this patch from Mateusz looks even better to me. So, FWIW, Acked-by: Oleg Nesterov