Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2286925rwi; Fri, 28 Oct 2022 05:26:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7tp6Z5syp6f7Rwf1SLM2OCZpUcFEe31dDybn+bZp3aZ40ac1rU/OmDRCYgO3FphUZLGzhH X-Received: by 2002:a05:6402:2804:b0:439:83c2:8be2 with SMTP id h4-20020a056402280400b0043983c28be2mr51516735ede.292.1666960002677; Fri, 28 Oct 2022 05:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666960002; cv=none; d=google.com; s=arc-20160816; b=g7+0+WpkFstePVbxMwvYWGpiqsVfK+AMPgIWFNWUa03oEWPnvLQHUy3SB/48xLmwrS YH75fhB00fgs7i4L0FGPnsZgW9cf9ok8y45Xa1MopZBNP8hBp5CfTF4VWpZNtp0xC/wt N1wF+4ZEANWjL+vPLPlC++4Q12Ymq6U79EEupbVPYgmtbaDm8iCGt7h52J14mNf2oIGX IahXuA17OF03cj+9w/iCYWKlTWCwLQhSOdviLwoQmc8SLNvk5XUXM/a9b5kZ2rpz3sXo WrsCuTRE7dcZCUGg6pbMId34BPMBChXUtgOWdB4J9ZZYKyD6u5T/uJ/eKqRiZ8rMSLB4 8h4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Nu+dNqyw2MSfxO5GDEKJfJJ4bD/Q1jRD9NyMKIrVtBQ=; b=uJNManfsNCH1ZRFo7qVxIYg94znEs0JDcjlHILpqnDKOt/pZFG49JIJ7dvMmpoG9K5 RHJ+LMr9t+dO1zvpRnyAS7YdQB/4znZ/cQeyRwZfj+Zyswb3mEKINDRTqCe0SwukzPgk BuNQ6WCDngqOUH9ZbtztBUCIQ7Vq727ITI3gL6QSIEYu+2hnrUN/W9mI6j+b4AIWNmk4 EjkiwcUAQ9iNydSF3JFXR2fCwccy9+RsViItKuy69yTBtST9KAIInhFl30D4LV2GZGos KuTTATg02qWrWSFbZ6tbGfDveCcjbN3HfuMXSbdiB0KeQE9X4pVCg8XO7tbSz6Svc7QY AzIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="IE/vZsWZ"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f24-20020a50a6d8000000b0045bd55b122fsi1611767edc.57.2022.10.28.05.26.15; Fri, 28 Oct 2022 05:26:42 -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=@linuxfoundation.org header.s=korg header.b="IE/vZsWZ"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbiJ1MHA (ORCPT + 99 others); Fri, 28 Oct 2022 08:07:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbiJ1MG7 (ORCPT ); Fri, 28 Oct 2022 08:06:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DC6D6BB4; Fri, 28 Oct 2022 05:06:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BA82AB829B8; Fri, 28 Oct 2022 12:06:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7819C433D6; Fri, 28 Oct 2022 12:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666958815; bh=KnqdBqXpwjnoczNNin28/Qu7T5+d3J3wqw/aPVgwV5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IE/vZsWZRUOQ2Vw4pgESvFMAaJEXn/0YCrZj+QFcp79NpOkUsm7MAu/bNYkgrDBR+ /g+VBuv5G40JPh7Hdm7R6L+gc/by/HeE8lijgv96lUE5WiCrq3IE3lzeiuelc+PMro 01M3gl+GnVkwa9WLS0CDFuy5sqYjk0dNTbfpTskA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jeff Layton , "J. Bruce Fields" , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Cyrill Gorcunov , Andrei Vagin , Pavel Tikhomirov , Sasha Levin Subject: [PATCH 5.10 61/73] fcntl: make F_GETOWN(EX) return 0 on dead owner task Date: Fri, 28 Oct 2022 14:03:58 +0200 Message-Id: <20221028120235.030794478@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221028120232.344548477@linuxfoundation.org> References: <20221028120232.344548477@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Pavel Tikhomirov [ Upstream commit cc4a3f885e8f2bc3c86a265972e94fef32d68f67 ] Currently there is no way to differentiate the file with alive owner from the file with dead owner but pid of the owner reused. That's why CRIU can't actually know if it needs to restore file owner or not, because if it restores owner but actual owner was dead, this can introduce unexpected signals to the "false"-owner (which reused the pid). Let's change the api, so that F_GETOWN(EX) returns 0 in case actual owner is dead already. This comports with the POSIX spec, which states that a PID of 0 indicates that no signal will be sent. Cc: Jeff Layton Cc: "J. Bruce Fields" Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Cyrill Gorcunov Cc: Andrei Vagin Signed-off-by: Pavel Tikhomirov Signed-off-by: Jeff Layton Stable-dep-of: f671a691e299 ("fcntl: fix potential deadlocks for &fown_struct.lock") Signed-off-by: Sasha Levin --- fs/fcntl.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index 71b43538fa44..5a56351f1fc3 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -148,11 +148,15 @@ void f_delown(struct file *filp) pid_t f_getown(struct file *filp) { - pid_t pid; + pid_t pid = 0; read_lock(&filp->f_owner.lock); - pid = pid_vnr(filp->f_owner.pid); - if (filp->f_owner.pid_type == PIDTYPE_PGID) - pid = -pid; + rcu_read_lock(); + if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type)) { + pid = pid_vnr(filp->f_owner.pid); + if (filp->f_owner.pid_type == PIDTYPE_PGID) + pid = -pid; + } + rcu_read_unlock(); read_unlock(&filp->f_owner.lock); return pid; } @@ -200,11 +204,14 @@ static int f_setown_ex(struct file *filp, unsigned long arg) static int f_getown_ex(struct file *filp, unsigned long arg) { struct f_owner_ex __user *owner_p = (void __user *)arg; - struct f_owner_ex owner; + struct f_owner_ex owner = {}; int ret = 0; read_lock(&filp->f_owner.lock); - owner.pid = pid_vnr(filp->f_owner.pid); + rcu_read_lock(); + if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type)) + owner.pid = pid_vnr(filp->f_owner.pid); + rcu_read_unlock(); switch (filp->f_owner.pid_type) { case PIDTYPE_PID: owner.type = F_OWNER_TID; -- 2.35.1