From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79B1B2D29C3; Tue, 12 Aug 2025 18:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755022500; cv=none; b=pWf93hJxZYU8g4N6oXOcIMhBpC7uZOjUtVYOjDvsmhlIoTCRC+A9y8AZRAzsMn4P+pLHCZ0ecqnF+7bfCOSfsGXdWko39oGG0GvfL42sn3mGquYpzyQELnaphc6n5jmJdL9OnIMH3/MRTzCVouApJZMCLqzYHalmUFzB2mqGYr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755022500; c=relaxed/simple; bh=BETvVSMKL/1LHIaos6PsLuFhohgleCEKXavfxO3Szns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F3WrsJL/gMA97EKcrLxQqA1hDmim1IlTVII+n46GBcIgVB4qAYDKz0mfDKvBj5CqCOvHc2w60pri3N+Uv0QwAw1+aOZBTYl57jV/mp17XL3MpcvXqiVDdv3S3VE1O6C1CcPP+GsmecT1ytVh4ifjx2GDukClWQgy/Ke68l65cNQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yG2l6Yt4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="yG2l6Yt4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFE5BC4CEF1; Tue, 12 Aug 2025 18:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755022500; bh=BETvVSMKL/1LHIaos6PsLuFhohgleCEKXavfxO3Szns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yG2l6Yt4OonotVBfC3mBGR3Ehh9jDGX40qLcKBABWsC4qYJ/gfkVHhssp8ip7vs/s DP+bJ079hpHKeSvRr8EGW6xCroy4fE5jpX9QNqjKt9Luz/WJ2LPeBMNoVwyib2Soez Q/0vJWsL3SB27U977RNjYsLjAIQg4WkdvWJ5l97A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Amir Goldstein , Jan Kara , Sasha Levin Subject: [PATCH 6.12 172/369] fanotify: sanitize handle_type values when reporting fid Date: Tue, 12 Aug 2025 19:27:49 +0200 Message-ID: <20250812173021.234585556@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812173014.736537091@linuxfoundation.org> References: <20250812173014.736537091@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amir Goldstein [ Upstream commit 8631e01c2c5d1fe6705bcc0d733a0b7a17d3daac ] Unlike file_handle, type and len of struct fanotify_fh are u8. Traditionally, filesystem return handle_type < 0xff, but there is no enforecement for that in vfs. Add a sanity check in fanotify to avoid truncating handle_type if its value is > 0xff. Fixes: 7cdafe6cc4a6 ("exportfs: check for error return value from exportfs_encode_*()") Signed-off-by: Amir Goldstein Signed-off-by: Jan Kara Link: https://patch.msgid.link/20250627104835.184495-1-amir73il@gmail.com Signed-off-by: Sasha Levin --- fs/notify/fanotify/fanotify.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 224bccaab4cc..bb00e1e16838 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -441,7 +441,13 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, dwords = fh_len >> 2; type = exportfs_encode_fid(inode, buf, &dwords); err = -EINVAL; - if (type <= 0 || type == FILEID_INVALID || fh_len != dwords << 2) + /* + * Unlike file_handle, type and len of struct fanotify_fh are u8. + * Traditionally, filesystem return handle_type < 0xff, but there + * is no enforecement for that in vfs. + */ + BUILD_BUG_ON(MAX_HANDLE_SZ > 0xff || FILEID_INVALID > 0xff); + if (type <= 0 || type >= FILEID_INVALID || fh_len != dwords << 2) goto out_err; fh->type = type; -- 2.39.5