Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3138021pxb; Mon, 18 Apr 2022 17:01:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpXmLArmoqSEEWwTq6Devw3wIEC7o8Y6Svw2mFEQ0xRVTFDMXR2oRfSip2ba2y2TwyExxb X-Received: by 2002:a05:6402:2309:b0:41f:a5a9:fe13 with SMTP id l9-20020a056402230900b0041fa5a9fe13mr14480473eda.123.1650326474894; Mon, 18 Apr 2022 17:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650326474; cv=none; d=google.com; s=arc-20160816; b=HehcncBGc//1KrSPNCmnUJtSbudCqGFt/xnbWAlHI3wKnV7urnoxtmmsfPwBgYrFBY 1VQXDeuf14XnOB+jfsVPuVtF9gLwhQhtNqaFnln3/HJ/dBF4LsWQvYyxuxJbvRULTd1O IwSr9HPnCLfnTktAF56Toauw/9MHkCP7jMqJCyelwuJFgfKd1a5epbkGMtp9OcVTjDx+ DU34LIuq1kknQhK0WuheOYA0edj7aCCrceNlAymuFc2spUj3zmIIQY3sS9mcU3mxEa5t QHQNj0D/a2Xwzmc656N0Cg2FfX0S5OqLza3uxPDgh/LzZmMM4aKBLVaS17Bmrt99r9LT w2XA== 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=BmvusyCBDS3Fm925g0lRVmh7weIrsBSp0+lV+kD6en4=; b=ESDLVydP/73bMYZx6Eegeylioqu0i2mxCklwhaDbfJ/osgyJNFTOz7RyBqJqYpf7yd c2wJVGY/8gkD5djF2swUvX+EOP3BcdnXi29ErlqwLk0lYd6DWqQtGciHDPaF+6rNvedL ZhD+ffPxbUtawA45kEPj/rw0l1yC4e1FdjQ1Is1daYtxRPH+GIPpUAJI7IvhCiOLiKE9 h16BX4wbpSyVvbj2li5aZdMvFLqwSasqUss455v96Zq9FG7J6/ZSDLcwEGYil7/mV80T e0NzNQV9zCgw8QCsU0TVfPlcxtvP+kTl5vGuW03uun4v4s434HvMMBdO3vNyU8mN1f52 UxfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FeWTPBD9; 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 b14-20020a1709065e4e00b006df85d83e7csi6957704eju.226.2022.04.18.17.00.50; Mon, 18 Apr 2022 17:01:14 -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=FeWTPBD9; 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 S239136AbiDRMgK (ORCPT + 99 others); Mon, 18 Apr 2022 08:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238887AbiDRM1I (ORCPT ); Mon, 18 Apr 2022 08:27:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2E521CFDE; Mon, 18 Apr 2022 05:20:53 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 279A760F0C; Mon, 18 Apr 2022 12:20:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3874AC385A7; Mon, 18 Apr 2022 12:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284452; bh=1ZR11ZiS9Zx+BLT5iJLPGmUOQMhGcjaQF2rDXTOW1JA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FeWTPBD9tR+4b2DCoVVIw1ULaQtVXZvDgXU32SBbwdi4tk8+pTlfakmqxbDNiHjBa XGPpNKJsP67pX/7znRIGvjmzu5lPw0hvlnIiBGzGA+pjBAPTrxg7RdzVHxbAHLQjwv kTB95m664XEtAlkPrvhYBgzzbcH0Qw7R0jHjGVXM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harshit Mogalapalli , Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.17 120/219] cifs: potential buffer overflow in handling symlinks Date: Mon, 18 Apr 2022 14:11:29 +0200 Message-Id: <20220418121210.257572780@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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,T_SCC_BODY_TEXT_LINE 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: Harshit Mogalapalli [ Upstream commit 64c4a37ac04eeb43c42d272f6e6c8c12bfcf4304 ] Smatch printed a warning: arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error: __memcpy() 'dctx->buf' too small (16 vs u32max) It's caused because Smatch marks 'link_len' as untrusted since it comes from sscanf(). Add a check to ensure that 'link_len' is not larger than the size of the 'link_str' buffer. Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()") Signed-off-by: Harshit Mogalapalli Reviewed-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/link.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 852e54ee82c2..bbdf3281559c 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c @@ -85,6 +85,9 @@ parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len, if (rc != 1) return -EINVAL; + if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN) + return -EINVAL; + rc = symlink_hash(link_len, link_str, md5_hash); if (rc) { cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc); -- 2.35.1