Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3610679pxf; Mon, 29 Mar 2021 06:59:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsehsBNtyIlmuO18b2JggAFubjtOdrYKmKiNnOlYJvxekyWBUVPPFIsqL2Cn8EM033g85W X-Received: by 2002:a17:906:2e45:: with SMTP id r5mr27764808eji.380.1617026350144; Mon, 29 Mar 2021 06:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617026350; cv=none; d=google.com; s=arc-20160816; b=oJxFS3ntFJc/lk5Fj2Cy7x7wWQSJ+Eo/gbfQAf/G+95eRut6qeen/tw6GROGOv+6rc Obbo6+00AxDaKPpeQIJ4txLg59AX26dpgu06ju9Y3jO6V0/W4lJzayE07JCRA3H6Qrvd 0ZOdTI53oDUdrX7OFqx/GWBRe5YBEA3+Q6dfIdrCWzOzFrnNHqKIX+vwMohy+aPFhIIi +i+bE0UcUjmkAoqZV2HkSslcpyi5A5tjg0m+iT9YTkk/NHAA8neh/3xBFkabyl/1NjIo NA74EkG1r/+RJMSeas72l3/oA/qU+MT6isX/PTylqwWOCQTKQGb5UVFdoZvmhU3SrpUz kNvA== 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; bh=r04hsNqwXlCoxspK8AFIPd3n53HsoJQ2usz0WCFjdpk=; b=0gEihfcKlE1UAdQDq0VTG9m8y49w3goDyE+OuqCPXoH2qUyyDO0brfPwjPLbw50jk7 Oz9aZ2jgU6aPgJYOuYnpjAG1TGvg/kfN/tqsUWTD8dESiE8Wx0kK4Gg30QPzxsJ3dy9f 7aIY4cDlmybyRO0fygWsDEeFG4u1Wq7SSPOhUQDKWSJZtarJmz+cvnKgZ9il9bCE5Scg 6gv9dknB16QUnR2ErCeDBn8tNwtAR6OlbcEJ3KGCjV0yKhqofxsW51ooTbyyI57guiZz wP1k6bc5pXsCCPn1iGzmYk2gvkQai5zfYkcSONjKLsAZMLV1Kk3/TpvZrZR0Emt1DmxP Go1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si13406401edr.249.2021.03.29.06.58.47; Mon, 29 Mar 2021 06:59:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230247AbhC2N5t (ORCPT + 99 others); Mon, 29 Mar 2021 09:57:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:36318 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231378AbhC2N5n (ORCPT ); Mon, 29 Mar 2021 09:57:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 46480B12A; Mon, 29 Mar 2021 13:57:42 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 9AC6F1E4353; Mon, 29 Mar 2021 15:57:40 +0200 (CEST) Date: Mon, 29 Mar 2021 15:57:40 +0200 From: Jan Kara To: lyl2019@mail.ustc.edu.cn Cc: jack@suse.cz, amir73il@gmail.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake Message-ID: <20210329135740.GB4283@quack2.suse.cz> References: <39095113.1936a.178781a774a.Coremail.lyl2019@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <39095113.1936a.178781a774a.Coremail.lyl2019@mail.ustc.edu.cn> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello! On Sun 28-03-21 17:11:43, lyl2019@mail.ustc.edu.cn wrote: > My static analyzer tool reported a use after free in fsnotify_put_mark_wake > of the file: fs/notify/mark.c. > > In fsnotify_put_mark_wake, it calls fsnotify_put_mark(mark). Inside the function > fsnotify_put_mark(), if conn is NULL, it will call fsnotify_final_mark_destroy(mark) > to free mark->group by fsnotify_put_group(group) and return. I also had inspected > the implementation of fsnotify_put_group() and found that there is no cleanup operation > about group->user_waits. > > But after fsnotify_put_mark_wake() returned, mark->group is still used by > if (atomic_dec_and_test(&group->user_waits) && group->shutdown) and later. > > Is this an issue? I don't think this scenario is possible. fsnotify_put_mark_wake() can be called only for marks attached to objects and these have mark->conn != NULL and we are sure that fsnotify_destroy_group() will wait for all such marks to be torn down and freed before dropping last group reference and freeing the group. Honza -- Jan Kara SUSE Labs, CR