Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2453839imd; Fri, 2 Nov 2018 11:40:22 -0700 (PDT) X-Google-Smtp-Source: AJdET5fHZifSjKKBMXaE+7qPMABUuGjWSdX/vgJ/ToPI0hno1HHkMToGWNKdGjhgFgs2b3pFmflH X-Received: by 2002:a63:cf0e:: with SMTP id j14-v6mr11937540pgg.195.1541184022705; Fri, 02 Nov 2018 11:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184022; cv=none; d=google.com; s=arc-20160816; b=OdUVoqXUvVyMapl9fNm5xMRBzbro+WHOhpszfhcQzL6UBDGYGd72jydi7E1DMvdB9I +aLoKo6UALeNGmwfdvxrhU4TxqsPYlfZwgic1umNXndyJ9h2/FpLJE+cR51kHLqt4xZ7 hW4OaLntmj+3bNwYJpywGZ+UzT+2U/W4ePEzDI8T5PEqI4t4vVTKyApNQFaEaV+rPmkn r4bzA5qQCN0IIkWD4lg1qnmeEEEtQ3CIpG1K5KOzdcETqRbpoQ/5s2x5LlMbFRu/IuZE 8/O92E5DsEhMrf6EmDNeY1idI2rgK76s1S2sj/SRowtYkXpFTbDIyPl2rJPJB1eSJ0xJ DRvg== 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=Hyi/NEYuVElrtpXUPRgivbsFUDXUqJJ9CdqLx3wZLIU=; b=mmvOc0ediajmjVPCNdNBoipRza2ng8jFGCOygATd+J4GRrO6Vt1GRATWxymmpGHf4I LmnYsbfFNzuStSL2tT3N27nBflI3BdBhOO2lBSF0TDudJ5qUvBct83fyNwIIhU7nXDh0 4vyFh5wmubTa5wF0mRXNww2bP2DF9P+LpNTgKdFyD6FnWJ89Dyjp1v5zdePPJ3R3RWsy KOe+kyBS+LYrjbjEMzeEF8HscZ1suyHjvYgW3tmJt8l1sPPpVMzbLYJWPe56Y3DJdTs+ f3+WWJxVMwFbRrcyJNKz4XeFxEo9oeE8sCrwIINsHqKPsNZIl7rf+WTEUQnEeHZe/Era J2Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C1EAFkt3; 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 o12-v6si37525156pfh.9.2018.11.02.11.40.07; Fri, 02 Nov 2018 11:40:22 -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=C1EAFkt3; 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 S1729008AbeKCDrM (ORCPT + 99 others); Fri, 2 Nov 2018 23:47:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728028AbeKCDrL (ORCPT ); Fri, 2 Nov 2018 23:47:11 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 8C4C62082D; Fri, 2 Nov 2018 18:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541183940; bh=M/0DrshPbypXOxFA7fHC04JY3YNXwEqNJgJd+R7nj8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1EAFkt3eQMrZTMIHX7gb7sNnalUS8K8wNg3uRuQRkdfG+J7p0ar8E30k4TftKDfo n1Yxv5UokQJjbOTrQHKfeM/hhhr6f4wuVaoBU/Sm2zu7MRxVPqyDudrhpVUOwQTckt ddFPrEKbREddxdfP+S0lY0aMX0K7wXpyF0OJYAt8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tobias Hommel , Kristian Evensen , Wolfgang Walter , Steffen Klassert , Sasha Levin Subject: [PATCH 4.18 011/150] xfrm: Fix NULL pointer dereference when skb_dst_force clears the dst_entry. Date: Fri, 2 Nov 2018 19:32:53 +0100 Message-Id: <20181102182903.432633549@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 9e1437937807b0122e8da1ca8765be2adca9aee6 ] Since commit 222d7dbd258d ("net: prevent dst uses after free") skb_dst_force() might clear the dst_entry attached to the skb. The xfrm code don't expect this to happen, so we crash with a NULL pointer dereference in this case. Fix it by checking skb_dst(skb) for NULL after skb_dst_force() and drop the packet in cast the dst_entry was cleared. Fixes: 222d7dbd258d ("net: prevent dst uses after free") Reported-by: Tobias Hommel Reported-by: Kristian Evensen Reported-by: Wolfgang Walter Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_output.c | 4 ++++ net/xfrm/xfrm_policy.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c index 89b178a78dc7..36d15a38ce5e 100644 --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c @@ -101,6 +101,10 @@ static int xfrm_output_one(struct sk_buff *skb, int err) spin_unlock_bh(&x->lock); skb_dst_force(skb); + if (!skb_dst(skb)) { + XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR); + goto error_nolock; + } if (xfrm_offload(skb)) { x->type_offload->encap(x, skb); diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index a94983e03a8b..526e6814ed4b 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -2551,6 +2551,10 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family) } skb_dst_force(skb); + if (!skb_dst(skb)) { + XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR); + return 0; + } dst = xfrm_lookup(net, skb_dst(skb), &fl, NULL, XFRM_LOOKUP_QUEUE); if (IS_ERR(dst)) { -- 2.17.1