Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3712618pxv; Mon, 26 Jul 2021 10:01:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBE0celmmin8w4DNkKnjirGt+ux8icM4NeMuWDWTBdLp7dBt2RMyZLyewjyPGHevucwsxr X-Received: by 2002:a05:600c:21c8:: with SMTP id x8mr26759957wmj.173.1627318915080; Mon, 26 Jul 2021 10:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318915; cv=none; d=google.com; s=arc-20160816; b=Bu2yvbcYsAMXruTUIFukKsWCqpoSqcVyNyUrZPkgrCpOF+T8js9pwn+IzCQqQKfovR O5JdOp2z7I+dh7o+IEFKZEPSbkvN6ERXLe7Mi/NKI3SYeCg3tFr69CZhkK4MhzqPfI4+ PxF978yx1+kDyWQC2QQNZguElMUqVi36tm8THnm0FWuL2QKtil81FYzRTYEPSsxmEJp2 QKoSgbzJ1Fl7Z0LugJEBPBqraUz3T5LPifU/08N6/90EzE73boHPtUJ+YNLs3z2QfX6D yq59DfEpwZ+iIUxHDtnNWh1XiuUQavXRrSR4ehyzgqdaAjvHMLYL2j6A9WmQ3WjMx7wq 2QWg== 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=co0uG9vaq6f6cJkQUkRoansKZyL5mqnwgXNz2q4oz/Q=; b=atWQJQFBCJH/w0xEc9RfBIYK2mixblKwgtGZb56SNjKRBYu1Vm1SiVCdu7XauZ1Gib mOwL3779ArAoCSFfhAqGHk/6SZtPutgguKtb+bE4S1Y8+Oj6eOrnfu9wPTbqbmrDEqob 5MaW7FuOffhoq6Ks84u2ix4QAWMOhV99JiEHTzg8B3neGZCiBK4Zq51S0/jFJ85QIh/v HtVXkaXmc1Mg92Ie5SMvLpSDLAoqHauR0ek9/U132OiAUW+3CvtSqICXhQTGUrA+KTbA SJVxgllK9SbRuX0ZI8GADVdWJC28BPZgQxQng5Onp04nJVlRBncUN8LQXUaAvBiWrNZW 7xhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="eLIaJPp/"; 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 i7si299159wrv.388.2021.07.26.10.01.27; Mon, 26 Jul 2021 10:01:55 -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="eLIaJPp/"; 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 S237487AbhGZPi6 (ORCPT + 99 others); Mon, 26 Jul 2021 11:38:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:36762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237272AbhGZPWN (ORCPT ); Mon, 26 Jul 2021 11:22:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5AE5C60EB2; Mon, 26 Jul 2021 16:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315361; bh=B6JJ3IY2p8yTR4M1J49UqgRmpT+RwB8ZHB9+uJt4OK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLIaJPp/SYMb0/RpXPos1fYrsbOYnPJOEt2LCw8JMoexi0wSsij/w0h/ez9epYbUI qr2U07aDP5qBLGMGRYOaw7+dDchPR41f7lme6K/SxBwyVS2PGMPDHRdeb279UG9gNc UzH94hQQPf1+JKTCYG/+eYGuKq9UdThZl7N6pS2s= 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.10 065/167] net: fix uninit-value in caif_seqpkt_sendmsg Date: Mon, 26 Jul 2021 17:38:18 +0200 Message-Id: <20210726153841.574635480@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@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 3ad0a1df6712..9d26c5e9da05 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