cifs: fix integer overflow in match_server()
authorRoman Smirnov <r.smirnov@omp.ru>
Mon, 31 Mar 2025 08:22:49 +0000 (11:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:32 +0000 (10:45 +0200)
commit 2510859475d7f46ed7940db0853f3342bf1b65ee upstream.

The echo_interval is not limited in any way during mounting,
which makes it possible to write a large number to it. This can
cause an overflow when multiplying ctx->echo_interval by HZ in
match_server().

Add constraints for echo_interval to smb3_fs_context_parse_param().

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes: adfeb3e00e8e1 ("cifs: Make echo interval tunable")
Cc: stable@vger.kernel.org
Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/fs_context.c

index b90cc918de7a3918f66868c73063f6fbd67cdacd..d2e291ef104ec0d6a985f85ecded88e9e91e871d 100644 (file)
@@ -1299,6 +1299,11 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
                ctx->closetimeo = HZ * result.uint_32;
                break;
        case Opt_echo_interval:
+               if (result.uint_32 < SMB_ECHO_INTERVAL_MIN ||
+                   result.uint_32 > SMB_ECHO_INTERVAL_MAX) {
+                       cifs_errorf(fc, "echo interval is out of bounds\n");
+                       goto cifs_parse_mount_err;
+               }
                ctx->echo_interval = result.uint_32;
                break;
        case Opt_snapshot: