Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3674514pxv; Mon, 26 Jul 2021 09:10:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJc10y1/sc+YFPAqG+tPqXs2vOBn2bInELqigVIIhx7n/PwPD6fwT0+CBLgdtKsOwlkQ8f X-Received: by 2002:aa7:c6d2:: with SMTP id b18mr14743844eds.266.1627315800175; Mon, 26 Jul 2021 09:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315800; cv=none; d=google.com; s=arc-20160816; b=pRdj7nAM6S5Mo/0SEP2zvmSQFiY76wX75XFNO3JvOpqG8L+EL5uAsjHk65LpOkBmY9 +VKZBVuczOXWr0Jk5fokuz4DRr6F4JNeh7NNPL4hqexDBAmx5z9GSho4nhVhCatRuRQf /C2TP/wxG67CDMQcmdROyOS+OZKzpudGEj4uUECJIdsmlQ5tMe/T+qhsj6NbnCtPHLm6 4V3rWLJAKaE3CxP8QL7oFXaBn1N7CQKM2AxaxKHUxZKxeIVo2Lx8IrwLb20TorpzWPjO Qlg4CIdcZVymMsfLFnXS54solPDXVRwu7fL0OvaEd6vnCRj1376xYcCOBryZyh77nKj3 R2Bw== 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=RU9InUmFfJd0KBQgQk+d/AyAaT7yk8y2FN8obPBW6rc=; b=bhPEr090xvMfnMV0buHuJNRQmEqjotLv9YuN3FB5ikXLnfDJsNPJAOCovgbDsDqmIf TDB6wSWkSkry7GU+6slAh15+SWdF+ZEvkQRG9+UFsKp1Y+E+Jh2CS/MdoxQxM3yI1RHE YI9+SJduin4dnJzBYa54FMdvTCiaJMwKQnMUa/4AwQORRvqLS/R2g/hFzINQzqpWYEqJ +1ar4OTebM8v7bC3aB9GJnbey9a+ea0fgHcqi6gHMd120lRmJ6nKif32OLPSsNXXA2AK DovCrn/ZmnHwUOlz63NFEFJQLOpQoYAZTHXXVJiZl9j1ZQhM95B8RzvS1MMjnKzE8v7w SM3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r17esQGX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si202084eju.237.2021.07.26.09.09.34; Mon, 26 Jul 2021 09:10:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r17esQGX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237549AbhGZPX0 (ORCPT + 99 others); Mon, 26 Jul 2021 11:23:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237492AbhGZPPw (ORCPT ); Mon, 26 Jul 2021 11:15:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 42E7860F42; Mon, 26 Jul 2021 15:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627314981; bh=WiCRf5DJ73hqLGq5e37eaQKkkD1kuiAjVY7yrmfLq+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r17esQGXB9F37OWH+QFFe+X+vfXQloAhBQtJnkFjsGGQW+nOaRFlB/5ahzMWinrLT Euk2qQsiw1rwV4afZFIfmJ8brm61WiAbtGGT7/eaeNO/DO+k41GGY+80+u45O+X31j BFrxwI1T6gNFahB/wkkTkeP/uDn0icoIvjT7h2Cc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+09a5d591c1f98cf5efcb@syzkaller.appspotmail.com, Ziyang Xuan , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 041/108] net: fix uninit-value in caif_seqpkt_sendmsg Date: Mon, 26 Jul 2021 17:38:42 +0200 Message-Id: <20210726153833.009641473@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ziyang Xuan [ Upstream commit 991e634360f2622a683b48dfe44fe6d9cb765a09 ] When nr_segs equal to zero in iovec_from_user, the object msg->msg_iter.iov is uninit stack memory in caif_seqpkt_sendmsg which is defined in ___sys_sendmsg. So we cann't just judge msg->msg_iter.iov->base directlly. We can use nr_segs to judge msg in caif_seqpkt_sendmsg whether has data buffers. ===================================================== BUG: KMSAN: uninit-value in caif_seqpkt_sendmsg+0x693/0xf60 net/caif/caif_socket.c:542 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1c9/0x220 lib/dump_stack.c:118 kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:118 __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:215 caif_seqpkt_sendmsg+0x693/0xf60 net/caif/caif_socket.c:542 sock_sendmsg_nosec net/socket.c:652 [inline] sock_sendmsg net/socket.c:672 [inline] ____sys_sendmsg+0x12b6/0x1350 net/socket.c:2343 ___sys_sendmsg net/socket.c:2397 [inline] __sys_sendmmsg+0x808/0xc90 net/socket.c:2480 __compat_sys_sendmmsg net/compat.c:656 [inline] Reported-by: syzbot+09a5d591c1f98cf5efcb@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=1ace85e8fc9b0d5a45c08c2656c3e91762daa9b8 Fixes: bece7b2398d0 ("caif: Rewritten socket implementation") Signed-off-by: Ziyang Xuan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/caif/caif_socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c index ef14da50a981..8fa98c62c4fc 100644 --- a/net/caif/caif_socket.c +++ b/net/caif/caif_socket.c @@ -539,7 +539,8 @@ static int caif_seqpkt_sendmsg(struct socket *sock, struct msghdr *msg, goto err; ret = -EINVAL; - if (unlikely(msg->msg_iter.iov->iov_base == NULL)) + if (unlikely(msg->msg_iter.nr_segs == 0) || + unlikely(msg->msg_iter.iov->iov_base == NULL)) goto err; noblock = msg->msg_flags & MSG_DONTWAIT; -- 2.30.2