Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1238818ybj; Fri, 20 Sep 2019 07:20:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOwmPxLe/QakbYwXV+Z08LLxrpsmISlPNr+Tn8zQiaXANmGkODm0ULCML9cPPpwgbZYB2a X-Received: by 2002:aa7:d9d2:: with SMTP id v18mr22242882eds.177.1568989246021; Fri, 20 Sep 2019 07:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568989246; cv=none; d=google.com; s=arc-20160816; b=z+Vd+Pb4DCSva6eM4N3zbQDE9FVZdNYCFej/JYwi2M1H2cSjicOPfICY1byiJ74q4H x0HVbhaNpqkfIZpSBtvJ2HqLrCTDqpax1/B5QP1w2cfv9yx9w8eSzif02goXyLNpLw8O n3lLXkwr09oZ9hmKb4hAGEv540O8dCgRi61wTTrmIMrD+8bpLwVpSb3zVDsDGZb7BEHQ zSrAO0WPDhCcW+205a9Sosy7ixGEMgK9MShbs2z8JhcWDy1d4Yi3JZOkXfFuC6nU45SS zU6DIP05LzLZMazSPjxGBVCvOyYH3wfDmU2VcaMwWvLz/4kkcZl0O7OJMTacsxFXbxLL X/mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CHosr5k/ySbLe4GCmfA+/uDOladOzTCIcEcYDL04vrQ=; b=QSOeqAfRlpMsyz9x5IFzfrUlS17+4EQNAR4hThKzlnJuaB3d5N3Hv8RHyoiBN775Ff glDXoyzQrtT4bJFk3zTFZELzHlDlb5JlPjzewJ6v8+5p02nnMWM7GQJ8/pa54UPtQNDo RayV60/61wskezDaDGqGxR2TR2hwHOcMqyMPHkc2Cu3CINbEDOIu+0J5cOiqYoP9WRWB wy3jeir9+GksojhzuY/yR/A3D+djLtXpiaEp9f9t95fz7166lnmouBc1tznpXqv3y19C pxJT4436hX39nayQPl1F7vv/GhHCBFUns5PU/3CgllZobpAe4t2NXP57jURS3ECkHe7G 5m7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nt8yQV1U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si1286802ejo.255.2019.09.20.07.20.21; Fri, 20 Sep 2019 07:20:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nt8yQV1U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389292AbfISWTh (ORCPT + 99 others); Thu, 19 Sep 2019 18:19:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:33272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392803AbfISWTe (ORCPT ); Thu, 19 Sep 2019 18:19:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8AC3B21907; Thu, 19 Sep 2019 22:19:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568931573; bh=XFsM7wsdcQyLz8XZBImqAGO66RPcnyCSdekJTBoxyIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nt8yQV1Upxqp/gxCDPTl6QHWvi2IN9Iw0sCf6TBvdOju4yEYW6qEspojDDmn7D3ca jTo7dpghIsZZtqKQhsGXSVYcZXi0Q78MUCvTLQAiLjD7HuBmrpynDc0v16Q4rPCfMX 0XEhaLJGGe8vqZawX8lTWL+5/ZAPkna+PT4KCB30= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , "David S. Miller" , syzbot+0849c524d9c634f5ae66@syzkaller.appspotmail.com Subject: [PATCH 4.9 04/74] isdn/capi: check message length in capi_write() Date: Fri, 20 Sep 2019 00:03:17 +0200 Message-Id: <20190919214801.315764204@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214800.519074117@linuxfoundation.org> References: <20190919214800.519074117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers [ Upstream commit fe163e534e5eecdfd7b5920b0dfd24c458ee85d6 ] syzbot reported: BUG: KMSAN: uninit-value in capi_write+0x791/0xa90 drivers/isdn/capi/capi.c:700 CPU: 0 PID: 10025 Comm: syz-executor379 Not tainted 4.20.0-rc7+ #2 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x173/0x1d0 lib/dump_stack.c:113 kmsan_report+0x12e/0x2a0 mm/kmsan/kmsan.c:613 __msan_warning+0x82/0xf0 mm/kmsan/kmsan_instr.c:313 capi_write+0x791/0xa90 drivers/isdn/capi/capi.c:700 do_loop_readv_writev fs/read_write.c:703 [inline] do_iter_write+0x83e/0xd80 fs/read_write.c:961 vfs_writev fs/read_write.c:1004 [inline] do_writev+0x397/0x840 fs/read_write.c:1039 __do_sys_writev fs/read_write.c:1112 [inline] __se_sys_writev+0x9b/0xb0 fs/read_write.c:1109 __x64_sys_writev+0x4a/0x70 fs/read_write.c:1109 do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:291 entry_SYSCALL_64_after_hwframe+0x63/0xe7 [...] The problem is that capi_write() is reading past the end of the message. Fix it by checking the message's length in the needed places. Reported-and-tested-by: syzbot+0849c524d9c634f5ae66@syzkaller.appspotmail.com Signed-off-by: Eric Biggers Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/isdn/capi/capi.c | 10 +++++++++- include/uapi/linux/isdn/capicmd.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -687,6 +687,9 @@ capi_write(struct file *file, const char if (!cdev->ap.applid) return -ENODEV; + if (count < CAPIMSG_BASELEN) + return -EINVAL; + skb = alloc_skb(count, GFP_USER); if (!skb) return -ENOMEM; @@ -697,7 +700,8 @@ capi_write(struct file *file, const char } mlen = CAPIMSG_LEN(skb->data); if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) { - if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) { + if (count < CAPI_DATA_B3_REQ_LEN || + (size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) { kfree_skb(skb); return -EINVAL; } @@ -710,6 +714,10 @@ capi_write(struct file *file, const char CAPIMSG_SETAPPID(skb->data, cdev->ap.applid); if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) { + if (count < CAPI_DISCONNECT_B3_RESP_LEN) { + kfree_skb(skb); + return -EINVAL; + } mutex_lock(&cdev->lock); capincci_free(cdev, CAPIMSG_NCCI(skb->data)); mutex_unlock(&cdev->lock); --- a/include/uapi/linux/isdn/capicmd.h +++ b/include/uapi/linux/isdn/capicmd.h @@ -15,6 +15,7 @@ #define CAPI_MSG_BASELEN 8 #define CAPI_DATA_B3_REQ_LEN (CAPI_MSG_BASELEN+4+4+2+2+2) #define CAPI_DATA_B3_RESP_LEN (CAPI_MSG_BASELEN+4+2) +#define CAPI_DISCONNECT_B3_RESP_LEN (CAPI_MSG_BASELEN+4) /*----- CAPI commands -----*/ #define CAPI_ALERT 0x01