Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3502290pxb; Mon, 18 Oct 2021 17:03:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/saomN2mhGWhhf20A8LJM0C+s8lpqg98EPEpe861AxZ8gzGWyiva3r7EFkk19WkUNxEnS X-Received: by 2002:a05:6402:d47:: with SMTP id ec7mr48780411edb.230.1634601824380; Mon, 18 Oct 2021 17:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634601824; cv=none; d=google.com; s=arc-20160816; b=dSk+IXcUSGat/9QunHaFpGOWx8VdYjh15VlwS/zJrhzn2Q9EKxodGfukBX31pBrzXi crLC17hNi9A/tuazpj0LiSfzjuBlV/T8MgNrrf80KIwdISZEplVAjss0jbPBtXZgvqhp y5wMKVRk1JD88b/7EX7lUoVGgSItH0IeNKZc+RK1vcIrqZnhs4TxP5Y7oWuo3scpyQ5X 5RJJD5kzcbE8blixeleEAvDtObrxMC57Jkq0Cl09CNtxr6ujZ0ZUwJPqRamgbjY8XYbX kcq8NAdkcrcU4btJUHe0EPi8L+BlUsLXvoRXULWPtuQpDULaEU+1SywnQ9EABC/t5HyI 7yTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nXQhVOvLvdU/vxSAMvHYmtUAlVx8uTbqMbLVCZH1Im0=; b=Hd6s76JbjrkrD+BcqLYdW4aCJGpwz7ztOXEFy1snxinzpeXNBKfWn0hV1zK3zUwJVq SXPJUUXqDUbgJXYNEyGZgEfKGU0yUQqc96q4ORKjA38bYHRGoLf+UhaDq0yYlOmjDz1P ZvAfX06mrQ31weyYoiGIZmifrJ07WlcOjNXrVN1yc5peD4giBAHINwhnQIkByQR7P+rd dEkCij5iP1XhZ0Ys7R1e56o1ki6yJMhxzr8qi+ngZHsPjzwf0yoGop+3f2xc/iMYVdaS e1K5mIYHMEy4K+wNoMdzWS5wudwsR2Z8HHso6IZV8W8bEVePKzwfULr7v39NEGkqTxEx zQgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t7si26967796edd.523.2021.10.18.17.03.21; Mon, 18 Oct 2021 17:03:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233961AbhJSAEf (ORCPT + 99 others); Mon, 18 Oct 2021 20:04:35 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40832 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233931AbhJSAEf (ORCPT ); Mon, 18 Oct 2021 20:04:35 -0400 Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id CB0671F411B7; Tue, 19 Oct 2021 01:02:21 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v8 15/32] fanotify: Encode empty file handle when no inode is provided Date: Mon, 18 Oct 2021 20:59:58 -0300 Message-Id: <20211019000015.1666608-16-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211019000015.1666608-1-krisman@collabora.com> References: <20211019000015.1666608-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Instead of failing, encode an invalid file handle in fanotify_encode_fh if no inode is provided. This bogus file handle will be reported by FAN_FS_ERROR for non-inode errors. Reviewed-by: Amir Goldstein Reviewed-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi --- Changes since v6: - Use FILEID_ROOT as the internal value (jan) - Create an empty FH (jan) Changes since v5: - Preserve flags initialization (jan) - Add BUILD_BUG_ON (amir) - Require minimum of FANOTIFY_NULL_FH_LEN for fh_len(amir) - Improve comment to explain the null FH length (jan) - Simplify logic --- fs/notify/fanotify/fanotify.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index ec84fee7ad01..c64d61b673ca 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -370,8 +370,14 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, fh->type = FILEID_ROOT; fh->len = 0; fh->flags = 0; + + /* + * Invalid FHs are used by FAN_FS_ERROR for errors not + * linked to any inode. The f_handle won't be reported + * back to userspace. + */ if (!inode) - return 0; + goto out; /* * !gpf means preallocated variable size fh, but fh_len could @@ -403,6 +409,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, fh->type = type; fh->len = fh_len; +out: /* * Mix fh into event merge key. Hash might be NULL in case of * unhashed FID events (i.e. FAN_FS_ERROR). -- 2.33.0