From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE351CA40; Tue, 16 Jul 2024 15:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721144159; cv=none; b=mU61Id5X5i2ShTw4prun4LLKe3GQvTUGSSX6HDRyo/jb8gtRsbQ2P0UspMAb0Ix+6cA4yD1QQbY6MLhnhx3jo9NgC4rhdPu42DZo2ruNVQTnotlk+ELBq2j+qqk+jrBXrCxf2zDVoGeEatNKLsqJQfLYC8Jt8AL49R/IKiEoyVg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721144159; c=relaxed/simple; bh=9+s+uSHPnKj8IYFDUQ/UzVLABKt8WGIzoGFOQNh64Sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FCeB0em8lFpaCllYcZ4N52KJwURslSzoqq1CHN3CHmGAtHKRuJ/1WpN2tRzDKfkhr14in7WOXT+pBaZhKKnkaNOlW9z92sJX7O6/TpaOJLPqbdNR3sD1drkN2bK0o8TsCJ10Lhx7wH41jFH1BljWCwZBun2Iqjm9jeWPiJWuKz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oKrke97s; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oKrke97s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54BBFC116B1; Tue, 16 Jul 2024 15:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721144159; bh=9+s+uSHPnKj8IYFDUQ/UzVLABKt8WGIzoGFOQNh64Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKrke97skMNwmW7k0VCZqmgYQU4XBdfvU+I/U8eRlN05NK2lQ6KX4uBlvQpJB/yyr F0h0V1IZ48o6a39hSf8AU1ka0O+Y0lST1aUXAt7Tg56997XjuS/xuxV2M6LtSV6cWw LSF1z/GBIeRJ2KcABe5FXNXhbTf1/TDMnNnT/HSk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+ec0723ba9605678b14bf@syzkaller.appspotmail.com, Dmitry Antipov , Paolo Abeni , Sasha Levin Subject: [PATCH 4.19 46/66] ppp: reject claimed-as-LCP but actually malformed packets Date: Tue, 16 Jul 2024 17:31:21 +0200 Message-ID: <20240716152739.926539035@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716152738.161055634@linuxfoundation.org> References: <20240716152738.161055634@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Antipov [ Upstream commit f2aeb7306a898e1cbd03963d376f4b6656ca2b55 ] Since 'ppp_async_encode()' assumes valid LCP packets (with code from 1 to 7 inclusive), add 'ppp_check_packet()' to ensure that LCP packet has an actual body beyond PPP_LCP header bytes, and reject claimed-as-LCP but actually malformed data otherwise. Reported-by: syzbot+ec0723ba9605678b14bf@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=ec0723ba9605678b14bf Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Dmitry Antipov Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/ppp/ppp_generic.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 220b28711f98e..5c737c6aa58b9 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -74,6 +74,7 @@ #define MPHDRLEN_SSN 4 /* ditto with short sequence numbers */ #define PPP_PROTO_LEN 2 +#define PPP_LCP_HDRLEN 4 /* * An instance of /dev/ppp can be associated with either a ppp @@ -495,6 +496,15 @@ static ssize_t ppp_read(struct file *file, char __user *buf, return ret; } +static bool ppp_check_packet(struct sk_buff *skb, size_t count) +{ + /* LCP packets must include LCP header which 4 bytes long: + * 1-byte code, 1-byte identifier, and 2-byte length. + */ + return get_unaligned_be16(skb->data) != PPP_LCP || + count >= PPP_PROTO_LEN + PPP_LCP_HDRLEN; +} + static ssize_t ppp_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { @@ -517,6 +527,11 @@ static ssize_t ppp_write(struct file *file, const char __user *buf, kfree_skb(skb); goto out; } + ret = -EINVAL; + if (unlikely(!ppp_check_packet(skb, count))) { + kfree_skb(skb); + goto out; + } switch (pf->kind) { case INTERFACE: -- 2.43.0