Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp50273imu; Thu, 8 Nov 2018 14:35:11 -0800 (PST) X-Google-Smtp-Source: AJdET5cG65qd8z6pbEGVt6zNhDptSn2WA1BrEhxE40rgSIrjkilWx9G6IRPDjNhN1tQBH9JTL9b9 X-Received: by 2002:a62:4681:: with SMTP id o1-v6mr6473780pfi.172.1541716511852; Thu, 08 Nov 2018 14:35:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716511; cv=none; d=google.com; s=arc-20160816; b=OgZiPKFtauqyMFHdFP3M1LIrHEmCKrbKk5QRo+v/qZkd0m2JCM8y1vucRcBQoqa4IT jJ6C5yv6lzUsOS6hmLxDJLKOOBgWM28zSizDrzEdDdvf3QsOj9D9b1sUaIR74pCsC14Q MEkUNgBK4/vVREQLsrXeHW9YmOaG8XGf2ytXmj/5cn+I+R+NLzKLCYUsLL3CDrA1U6l+ 32PVxENKdjCA28HLLWXGYpH7Qq9CV3rwhlmiIuxIJAO6qiTeaQQudHgohbQakqhC6Tni 0VVRxTE14DJ/JE2ro/YWn4cst6bVXpB+Tztu7//jKv1boRBy1AYOZVo7YhIUIi1JcQh2 N3kg== 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=DIQ6TVWb2tXVnhaevP2UnlP/5zLgg9rO4DCHiNYcoZc=; b=JvnZzVTvKA7ChRMw19SRYsl0sOjIjvnGrsxL5u+qy2O/CXnZytba+nseT8UXL4vx1e GWha0PbvxV9Gif4SIU59xqfXOJ1N+WNJUVDC65zVw48S9YzRbgGoQxIpM62C/CNUue62 9cf2vYMxexr6maStAhKRGrqgWMi0XNBvths/BLPocf0t2d0dxoGOposCctL6/Szh9CBG q20s+2lx8Psv5cwrIFfDjKmJ00MFzpIyhADgsr2iEYeYeMDfPvD6/lr4nAgkbh2MPvZB +juXTTCJE1PVKwAuz5876iQlrgXkQm0heHSaAQG0h85ali6IwT3YXftpkAWCcT7mWgoj 1okQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ys5X23Di; 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 p11-v6si4803426pgb.563.2018.11.08.14.34.55; Thu, 08 Nov 2018 14:35:11 -0800 (PST) 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=ys5X23Di; 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 S1730122AbeKIHhO (ORCPT + 99 others); Fri, 9 Nov 2018 02:37:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:55098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729144AbeKIHhO (ORCPT ); Fri, 9 Nov 2018 02:37:14 -0500 Received: from localhost (unknown [208.72.13.198]) (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 A865720818; Thu, 8 Nov 2018 21:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714385; bh=DzzgLSUeZLFs7eRPk/yJOWE/pqUY0lPsFsJIQNbGA28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ys5X23DiUUJuZqIc5p/uV7fBWg4OeQRcpYz4J5ya3SRxEWe/10L6TywHC3HQe1VFA 3zpIa2ddTooClc1zrt1n5EzKOCGMl8sxgQDHYIZbHBvBb3Zxlm95bfikpQfzhL2KsM Sj6qvQn1ktbdAyf1h9+hCbPWjClYxbGiG2dsy5HU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Basseri , Steffen Klassert , Sasha Levin Subject: [PATCH 4.4 046/114] xfrm: Clear sk_dst_cache when applying per-socket policy. Date: Thu, 8 Nov 2018 13:51:01 -0800 Message-Id: <20181108215105.345040279@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 2b06cdf3e688b98fcc9945873b5d42792bd4eee0 ] If a socket has a valid dst cache, then xfrm_lookup_route will get skipped. However, the cache is not invalidated when applying policy to a socket (i.e. IPV6_XFRM_POLICY). The result is that new policies are sometimes ignored on those sockets. (Note: This was broken for IPv4 and IPv6 at different times.) This can be demonstrated like so, 1. Create UDP socket. 2. connect() the socket. 3. Apply an outbound XFRM policy to the socket. (setsockopt) 4. send() data on the socket. Packets will continue to be sent in the clear instead of matching an xfrm or returning a no-match error (EAGAIN). This affects calls to send() and not sendto(). Invalidating the sk_dst_cache is necessary to correctly apply xfrm policies. Since we do this in xfrm_user_policy(), the sk_lock was already acquired in either do_ip_setsockopt() or do_ipv6_setsockopt(), and we may call __sk_dst_reset(). Performance impact should be negligible, since this code is only called when changing xfrm policy, and only affects the socket in question. Fixes: 00bc0ef5880d ("ipv6: Skip XFRM lookup if dst_entry in socket cache is valid") Tested: https://android-review.googlesource.com/517555 Tested: https://android-review.googlesource.com/418659 Signed-off-by: Jonathan Basseri Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_state.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index d6a11af0bab1..9b6e51450fc5 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -1884,6 +1884,7 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen if (err >= 0) { xfrm_sk_policy_insert(sk, err, pol); xfrm_pol_put(pol); + __sk_dst_reset(sk); err = 0; } -- 2.17.1