Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp33335pxb; Fri, 15 Jan 2021 05:12:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/Sm8M/kwHqYhaL/UAVwxyKbOo/rkaY1VxGH8+EFMwtafsS8JvO4EZd2wf3l4PFR5wWqdJ X-Received: by 2002:a17:906:2755:: with SMTP id a21mr8947536ejd.374.1610716337463; Fri, 15 Jan 2021 05:12:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610716337; cv=none; d=google.com; s=arc-20160816; b=maXRzY+c+Rj/ZjFs1Uoslg/ATMcz0Pl7y42DGtfG8N5nzrb8tpQrLKYFS0HHYoS5Ao 9oqt62ze4ZhYTa+nemdVOCGKz4w9jqJzopyrxAsz3GjAY4pV1kGNqoErYTFFSUvZ0GTR gMH9Bi57UPm0nOdbVcneI2Ppi3YRb3FvTvJLMvMJIQmd+N+kVS63ThiL1p9+Vj6Pai2O gCRdvRorLMCjEiluO2IQSCAcxyrg8i8kW5MDTjwDPtjVantf/4PdkrhvPOMUDoFXY7Yi l+z6DRV2dJCEee7SFyWi+66WFyaw8NNMcZ6lBo9wfiEuCIvSOCCWY+YpYYn/Su2tHq0n g1ig== 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=ZzlTXeJj0whrHlYPHjsx4e3/vza7osTdJPlrkA9AkFg=; b=pc2+tBwNEAUiXbhQyH1H6vHQZu4OJe8zxaQZo3xa2jW5OjffBawAdJPwGHlpfTnqJs e3GM/os7t72DFLCwPDTn9C+U6GWfPdwfAE7QMNAZMWG7Zq0ePWyfJVK9rPHGsP6cHwoF SiaVrS3JQiaoDGIReGaQnYV6Uo/DJlZ3QVRbAVAwdAEYitec+7gYkH6v7EcQRbLoBdXp G1YVqcHsSeDu4sOGKMO1SfAOdtyULzFVw4SyYBwY31Qe74oBjYa2njYOBly4SPvUMJam xlZxvISlaSZkVsVySQr1BS28NzXvqjWbbTyAraenp/ZRlpGPcZZXCnZXJqFKgdf8ANO6 mmMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DovKh7WW; 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 e10si4263361edk.554.2021.01.15.05.11.51; Fri, 15 Jan 2021 05:12:17 -0800 (PST) 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=DovKh7WW; 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 S2387515AbhAONIi (ORCPT + 99 others); Fri, 15 Jan 2021 08:08:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:36412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732157AbhAOMao (ORCPT ); Fri, 15 Jan 2021 07:30:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 36AB42333E; Fri, 15 Jan 2021 12:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610713777; bh=8tcTVkAs5155gqV6KdpmUfac/ys7Qi1zjNTA95lHapk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DovKh7WWLRzEs06cTOrY+cntP8TjpoQjwdX+LjKW6uAyNYWToww66XlzhsSHcQpEH 4+kIUueFN26S4huazYOuKKE65ZVkTbThuwrrE1p9f20sKgpb9cX5exSXYk7R6Wa0pc V4op6z6Pr1yRAwkRhe2Oxiv1T/HCJ+7DFJtVIrOU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7010af67ced6105e5ab6@syzkaller.appspotmail.com, Vasily Averin , Willem de Bruijn , Jakub Kicinski Subject: [PATCH 4.4 18/18] net: drop bogus skb with CHECKSUM_PARTIAL and offset beyond end of trimmed packet Date: Fri, 15 Jan 2021 13:27:46 +0100 Message-Id: <20210115121956.005103672@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121955.112329537@linuxfoundation.org> References: <20210115121955.112329537@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: Vasily Averin commit 54970a2fbb673f090b7f02d7f57b10b2e0707155 upstream. syzbot reproduces BUG_ON in skb_checksum_help(): tun creates (bogus) skb with huge partial-checksummed area and small ip packet inside. Then ip_rcv trims the skb based on size of internal ip packet, after that csum offset points beyond of trimmed skb. Then checksum_tg() called via netfilter hook triggers BUG_ON: offset = skb_checksum_start_offset(skb); BUG_ON(offset >= skb_headlen(skb)); To work around the problem this patch forces pskb_trim_rcsum_slow() to return -EINVAL in described scenario. It allows its callers to drop such kind of packets. Link: https://syzkaller.appspot.com/bug?id=b419a5ca95062664fe1a60b764621eb4526e2cd0 Reported-by: syzbot+7010af67ced6105e5ab6@syzkaller.appspotmail.com Signed-off-by: Vasily Averin Acked-by: Willem de Bruijn Link: https://lore.kernel.org/r/1b2494af-2c56-8ee2-7bc0-923fcad1cdf8@virtuozzo.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/skbuff.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1516,6 +1516,12 @@ int pskb_trim_rcsum_slow(struct sk_buff skb->csum = csum_block_sub(skb->csum, skb_checksum(skb, len, delta, 0), len); + } else if (skb->ip_summed == CHECKSUM_PARTIAL) { + int hdlen = (len > skb_headlen(skb)) ? skb_headlen(skb) : len; + int offset = skb_checksum_start_offset(skb) + skb->csum_offset; + + if (offset + sizeof(__sum16) > hdlen) + return -EINVAL; } return __pskb_trim(skb, len); }