Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5060964pxb; Thu, 14 Oct 2021 18:18:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWc3dy5X1gTcRuKRqEr4Qr+lH0e7K+Pf5hvoZWs9NgGZwZktuKAblaiNnN3lmPzUd3LVP2 X-Received: by 2002:a63:cf44:: with SMTP id b4mr6932517pgj.215.1634260738553; Thu, 14 Oct 2021 18:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634260738; cv=none; d=google.com; s=arc-20160816; b=WosJn6jtaT+CG/pMRMLJbsj6te/ThYFoq9UFO87r1rMWIUt72dVR9eoIrFxKCmhtoS 30mJZ4fcgE75LCNKpaitivdeuQSpkWOd1HOispZ64fAKELMPT6T26Z3Pf4S8oaskszOi TNOj9YwJTsObqV1pB7oSpNk5AvxBFuCfAVlOOt9IlXroRiKS/D2+X6mH8NXcUH4eOi6b UQV4EkfLHTHjiD1C7iZU/NV6mRvBXZGQ/JQyY0+ToKiLo7pDMmeC0JJ3j8y78AAMS21o o6shfWcQZRl6utUSBNHGHVHwXYwT4AafFkNmE8dMPqSWY0d+OJANuJhMpag5Pjfx37wm FAmg== 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=8UHvlOIz/tO2X2q7X7L9KcbmW+gkjJ1s9JoIB5cme78=; b=U+Tdq1fVLaMtpbIC4T4va/L/c9ReLiNvPR/Uh2qSR5hcfA8RH9Kdd7bFStMBfYV2cK yQJfiHm0C63BPL8BqA+jcZu/b4m3XefDp6szjV+Ulog2vj71mzayWA/N5IFEeR068HCW 7awG5ry2riXck62ykg1PJKa14p7gSFc8eQrwuGSUi0kSpeS+zfBtqjIaf+d6dQE7bu6w 7tb54YDzCpw/sF29MQxBW8zac3laUJQUWjNcXYQIY8NXr/uVevfcRpM3LuvWVhAJ8Fl5 1Jl87T67o2YBWtnLOwVADNZhzqmh2az3v69h/h2QwA2jNUswwLflRufjLlb7UL1TxqU3 tKdA== 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 y11si5860421pji.85.2021.10.14.18.18.45; Thu, 14 Oct 2021 18:18:58 -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 S233658AbhJNVkt (ORCPT + 99 others); Thu, 14 Oct 2021 17:40:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbhJNVks (ORCPT ); Thu, 14 Oct 2021 17:40:48 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85917C061570; Thu, 14 Oct 2021 14:38:43 -0700 (PDT) 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 AF0801F44F83; Thu, 14 Oct 2021 22:38:35 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, repnop@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v7 14/28] fanotify: Encode empty file handle when no inode is provided Date: Thu, 14 Oct 2021 18:36:32 -0300 Message-Id: <20211014213646.1139469-15-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014213646.1139469-1-krisman@collabora.com> References: <20211014213646.1139469-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. 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