Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp877048ybe; Fri, 13 Sep 2019 07:40:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWWV36OrJlintslZwbKhu6/zASxI1vIkIRfK8b9hqexRcmI6XWK4ZETQD98HORf53iW8g6 X-Received: by 2002:a17:906:f189:: with SMTP id gs9mr41054429ejb.274.1568385652825; Fri, 13 Sep 2019 07:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568385652; cv=none; d=google.com; s=arc-20160816; b=H2u2rHKIYOtNJZG+i4AuCphOmZXmrjizeCpq89Yc8frQ1jWyP0snxSHET19ObAz2KW KtCjHdibBPB5RU5awynGD7zalo5DZvZj/1ZCKTzaDScUf/Zqel6XGcSOxRil+vEMHfFM uPyWTZU+mHloqKo/kFF3N+xGLUVBGMYEkib0HKZnU9IKgyjswxTyz1rsYoMzZZUViEt3 4K8F7alXoCC/HDFYjIHrpyPhN/5SwR/ymrewoiloKUQbv3HraBlUZssET2jKrzvje/Ec 8eP4UsgMavayk5ifogk1nwLx/WGmG8OljVWyogBJetsj/X1mOPtilNnlV3W1QYnVQFkx KIJA== 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=ZteA6MYHyF2n8KSwX/4cg1WAyFH05GK1Oy3t2odsKjs=; b=Gju1t5+pQi7vCH/DEj0/+alpbCpDWi6IfahY/D0wXuGwYT3Rp5WaMKKBJ3q2LS5B5D vgGtIPgxVkdK2DVfxxD1E8yQFEhrGWK5ihxl5/Wxm0x/ZMKY+mpzhgVswddYQas4UGd2 NetClPnQ2HJN/cklQAj9+4Gnd/Y0yWbFKt2K0gtSkJWmnTYCuagi7ltlUp0FaBTDOYiv /E+kocX56K8YZP0qQUTNfYv99BcVLPbhmXU6lJC4NJQbWoUvOOiSSvyq3E9UlssX7KMm 7IABTycxmPKg/S9shxfMs/Jc1aNQ6KAEOXYwYhoCEbcAgO+RXFYxbzTkSgBtz8O4Or8E HZUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tSQ+xeE4; 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 p1si18227911eda.406.2019.09.13.07.40.29; Fri, 13 Sep 2019 07:40:52 -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=tSQ+xeE4; 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 S2389096AbfIMNME (ORCPT + 99 others); Fri, 13 Sep 2019 09:12:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:37386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388457AbfIMNMC (ORCPT ); Fri, 13 Sep 2019 09:12:02 -0400 Received: from localhost (unknown [104.132.45.99]) (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 72FFD20640; Fri, 13 Sep 2019 13:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568380322; bh=muFnp+O5xw4TkSa8cy2W+Meg+Wxkm4S1o6ITTHEpZgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSQ+xeE4sVQBUs0kROQRs/ALTABWaoH0kxgyMfGE2CXu8WfQU8/To84FC3yfiF3F1 sfVvz4QSzyEuRyPbbpl0mwKHlORAHboYdxv+SRz+VMHFnyWtfP241XkYbOOjyrOyW6 ST3fiJEchBzDOBph6aQa1er03eIKKOqxl0EaWyjw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+355cab184197dbbfa384@syzkaller.appspotmail.com, Sven Eckelmann , Antonio Quartulli , Simon Wunderlich Subject: [PATCH 4.19 012/190] batman-adv: Only read OGM tvlv_len after buffer len check Date: Fri, 13 Sep 2019 14:04:27 +0100 Message-Id: <20190913130600.586225639@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913130559.669563815@linuxfoundation.org> References: <20190913130559.669563815@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: Sven Eckelmann commit a15d56a60760aa9dbe26343b9a0ac5228f35d445 upstream. Multiple batadv_ogm_packet can be stored in an skbuff. The functions batadv_iv_ogm_send_to_if()/batadv_iv_ogm_receive() use batadv_iv_ogm_aggr_packet() to check if there is another additional batadv_ogm_packet in the skb or not before they continue processing the packet. The length for such an OGM is BATADV_OGM_HLEN + batadv_ogm_packet->tvlv_len. The check must first check that at least BATADV_OGM_HLEN bytes are available before it accesses tvlv_len (which is part of the header. Otherwise it might try read outside of the currently available skbuff to get the content of tvlv_len. Fixes: ef26157747d4 ("batman-adv: tvlv - basic infrastructure") Reported-by: syzbot+355cab184197dbbfa384@syzkaller.appspotmail.com Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli Signed-off-by: Simon Wunderlich Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/bat_iv_ogm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -463,17 +463,23 @@ static u8 batadv_hop_penalty(u8 tq, cons * batadv_iv_ogm_aggr_packet() - checks if there is another OGM attached * @buff_pos: current position in the skb * @packet_len: total length of the skb - * @tvlv_len: tvlv length of the previously considered OGM + * @ogm_packet: potential OGM in buffer * * Return: true if there is enough space for another OGM, false otherwise. */ -static bool batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, - __be16 tvlv_len) +static bool +batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, + const struct batadv_ogm_packet *ogm_packet) { int next_buff_pos = 0; - next_buff_pos += buff_pos + BATADV_OGM_HLEN; - next_buff_pos += ntohs(tvlv_len); + /* check if there is enough space for the header */ + next_buff_pos += buff_pos + sizeof(*ogm_packet); + if (next_buff_pos > packet_len) + return false; + + /* check if there is enough space for the optional TVLV */ + next_buff_pos += ntohs(ogm_packet->tvlv_len); return (next_buff_pos <= packet_len) && (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); @@ -501,7 +507,7 @@ static void batadv_iv_ogm_send_to_if(str /* adjust all flags and log packets */ while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, - batadv_ogm_packet->tvlv_len)) { + batadv_ogm_packet)) { /* we might have aggregated direct link packets with an * ordinary base packet */ @@ -1852,7 +1858,7 @@ static int batadv_iv_ogm_receive(struct /* unpack the aggregated packets and process them one by one */ while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb), - ogm_packet->tvlv_len)) { + ogm_packet)) { batadv_iv_ogm_process(skb, ogm_offset, if_incoming); ogm_offset += BATADV_OGM_HLEN;