Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2900304pxb; Tue, 24 Aug 2021 10:10:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3gwA4q1Y7bohndYie84TdYJkumXi/ratYpI90OXVUpzlXf7zlEXnF1Mofy32R38Qn0hRe X-Received: by 2002:a92:b308:: with SMTP id p8mr27215959ilh.296.1629825042625; Tue, 24 Aug 2021 10:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825042; cv=none; d=google.com; s=arc-20160816; b=PeRQAkP/rbPcxmvvq19f6nW0tYDRR/ah6CGm0EiVUZWxlvx2KaRtmoRFe5+TfB7ti4 5gL9m5anzYyg6nEsh9a6FuTa00qd31xRtCk3RkYRRU9oJ0U0yXC2uV5g0sWiwcOmXqel 1J5c1MEQvgTK5kT//XpWpPY5vVHVMvQX/EoBtzqJeV2QPA3lLrFUUO7L7zUGpWvKvXC6 QqIRxU4mSRDiOAumZ59aJUCRB54zEVvuVVA0dSTdyIaCNozjzwVTND4M2/y5lGgKXQ+I NyEmd6F7EHv5B+Y/tutdAhGymyQKZUXnCt+3ZTMwMoEanQWMaPIJtmIrAsyke99r/uSo 5jaw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fbWstAn+SWDbJ8ERpoNLSPwCjy6uSRiRbIZxaOQKwcM=; b=gM02mwaFWZg18RnF9Gh2BOgBUncRCIgVX4GwbKLgRrqHc1S79jYV+DDLqY0M6iRRnV 17c//MV+cA5MKbfTj0inhi/6eUKPkunodG7a6LHTOrRtMz3mHZgxPTTlTqEXssGgGT1o yPZrguaPcKLhYPCbAlqRnBknX0ql9eby8VP5xI5svjkKYjMNQDrt3uoVenEQO6nHqu28 zC2Ox4z/79jbTp5hEUhsvJ1la3odjZd/ECw3bBhWIbj90xkUGudf9mVMh70KWU+DvQkW 37UAUPYm0K/rOOI8BefBfPh1EFk3dsJKVVcGjxOkFGP5VqvStmmjODJJWtyLwjvfJ1hj QwwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Xj3Mt/t0"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si17589564jam.111.2021.08.24.10.10.30; Tue, 24 Aug 2021 10:10:42 -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=@kernel.org header.s=k20201202 header.b="Xj3Mt/t0"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239139AbhHXRK0 (ORCPT + 99 others); Tue, 24 Aug 2021 13:10:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:47426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238884AbhHXRID (ORCPT ); Tue, 24 Aug 2021 13:08:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC25B61A08; Tue, 24 Aug 2021 17:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824402; bh=/JHi0V3cli/t8sdZnMZ9wI7O5zk3Oa0nGm1mPlNynys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xj3Mt/t0EazQ74Doaw4wQXkMB1sqrDhtbuBfPDAabifMXZJmCoBSUez646pOsanRE P/Vj1RNxvD177zafAjHNA89I5awlBSeasrMFV/4xyh3BmThngX0Z+z++F/cDS+PeDI mcpJkD+KVuOrNX7hCCFFmFCuWoMh1LSi6kg3ArBWSUe6bGdTdjKmF4NQtb616foML4 ANmErMwM6PM0n62+8nofkxiWKbf8KBztcrc9lUwMR/ArYiSjV2zLm1coS8HmT/z/QD 7CvMbaWPZZDLD8Yhm8Ckw77Nyggs+FqvJOo3LMPThsQIWVLLP0kpmieO+xlfbY368y YxqQ4Dg5BY9KA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Skripkin , syzbot+fc8cd9a673d4577fb2e4@syzkaller.appspotmail.com, Dan Carpenter , "David S . Miller" , Sasha Levin Subject: [PATCH 5.10 53/98] net: 6pack: fix slab-out-of-bounds in decode_data Date: Tue, 24 Aug 2021 12:58:23 -0400 Message-Id: <20210824165908.709932-54-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165908.709932-1-sashal@kernel.org> References: <20210824165908.709932-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.61-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.61-rc1 X-KernelTest-Deadline: 2021-08-26T16:58+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 19d1532a187669ce86d5a2696eb7275310070793 ] Syzbot reported slab-out-of bounds write in decode_data(). The problem was in missing validation checks. Syzbot's reproducer generated malicious input, which caused decode_data() to be called a lot in sixpack_decode(). Since rx_count_cooked is only 400 bytes and noone reported before, that 400 bytes is not enough, let's just check if input is malicious and complain about buffer overrun. Fail log: ================================================================== BUG: KASAN: slab-out-of-bounds in drivers/net/hamradio/6pack.c:843 Write of size 1 at addr ffff888087c5544e by task kworker/u4:0/7 CPU: 0 PID: 7 Comm: kworker/u4:0 Not tainted 5.6.0-rc3-syzkaller #0 ... Workqueue: events_unbound flush_to_ldisc Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x197/0x210 lib/dump_stack.c:118 print_address_description.constprop.0.cold+0xd4/0x30b mm/kasan/report.c:374 __kasan_report.cold+0x1b/0x32 mm/kasan/report.c:506 kasan_report+0x12/0x20 mm/kasan/common.c:641 __asan_report_store1_noabort+0x17/0x20 mm/kasan/generic_report.c:137 decode_data.part.0+0x23b/0x270 drivers/net/hamradio/6pack.c:843 decode_data drivers/net/hamradio/6pack.c:965 [inline] sixpack_decode drivers/net/hamradio/6pack.c:968 [inline] Reported-and-tested-by: syzbot+fc8cd9a673d4577fb2e4@syzkaller.appspotmail.com Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Pavel Skripkin Reviewed-by: Dan Carpenter Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/hamradio/6pack.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index 71d6629e65c9..da13683d52d1 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c @@ -839,6 +839,12 @@ static void decode_data(struct sixpack *sp, unsigned char inbyte) return; } + if (sp->rx_count_cooked + 2 >= sizeof(sp->cooked_buf)) { + pr_err("6pack: cooked buffer overrun, data loss\n"); + sp->rx_count = 0; + return; + } + buf = sp->raw_buf; sp->cooked_buf[sp->rx_count_cooked++] = buf[0] | ((buf[1] << 2) & 0xc0); -- 2.30.2