From patchwork Mon Oct 30 14:58:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Smalley X-Patchwork-Id: 832085 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yQd6K06gzz9t2c for ; Tue, 31 Oct 2017 02:03:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932348AbdJ3PDu (ORCPT ); Mon, 30 Oct 2017 11:03:50 -0400 Received: from upbd19pa10.eemsg.mail.mil ([214.24.27.85]:19975 "EHLO upbd19pa10.eemsg.mail.mil" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932103AbdJ3PDs (ORCPT ); Mon, 30 Oct 2017 11:03:48 -0400 Received: from emsm-gh1-uea10.ncsc.mil ([214.29.60.2]) by upbd19pa10.eemsg.mail.mil with ESMTP/TLS/AES256-SHA; 30 Oct 2017 15:03:45 +0000 X-IronPort-AV: E=Sophos;i="5.44,320,1505779200"; d="scan'208";a="5265785" IronPort-PHdr: 9a23:B0Xb9B1yrbCKmo3gsmDT+DRfVm0co7zxezQtwd8ZsesXK/XxwZ3uMQTl6Ol3ixeRBMOHs6oC17Kd7PmocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmCaxbal9IRmqognctNQaipZ+J6gszRfEvmFGcPlMy2NyIlKTkRf85sOu85Nm7i9dpfEv+dNeXKvjZ6g3QqBWAzogM2Au+c3krgLDQheV5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j0WWirildboH0S7T+2eM03COsFtbUAFuS6XFW24QZk/ModT+/EPCQOzmNbNyNAZdxcOcArVFZ8evjlhcQvrnftPEbDGfgWC1UC2Uy6uMYYyiQGAU2CHQGQBQiAwI1WqXPgg5QCG6qiTRCyI4RgGnWF/l7eQr8CDzdUQz1QzfKhc52g== X-IPAS-Result: A2AdBADpPvdZ/wHyM5BcHAEBBAEBCgEBFwEBBAEBCgEBgwgsgVInnSw/AQEBAQEHl3OCER2FKIRhQRYBAQEBAQEBAQEBAWoogjgkgm9SgVGIBoIQDao7Oop+ATGDLoIHgQyHIgGEFIUqBaIDlG8NkysCl0kmAi+BaCoKAh8IIw+DLYJoghMlNopfLIIWAQEB Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by EMSM-GH1-UEA10.NCSC.MIL with ESMTP; 30 Oct 2017 15:03:44 +0000 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto [192.168.25.131]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id v9UF3fLQ031006; Mon, 30 Oct 2017 11:03:42 -0400 From: Stephen Smalley To: netdev@vger.kernel.org Cc: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, fw@strlen.de, davem@davemloft.net, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, paul@paul-moore.com, Stephen Smalley Subject: [RFC PATCH] xfrm: fix regression introduced by xdst pcpu cache Date: Mon, 30 Oct 2017 10:58:43 -0400 Message-Id: <20171030145843.13496-1-sds@tycho.nsa.gov> X-Mailer: git-send-email 2.9.5 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since 4.14-rc1, the selinux-testsuite has been encountering sporadic failures during testing of labeled IPSEC. git bisect pointed to commit ec30d78c14a813db39a647b6a348b4286 ("xfrm: add xdst pcpu cache"). The xdst pcpu cache is only checking that the policies are the same, but does not validate that the policy, state, and flow match with respect to security context labeling. As a result, the wrong SA could be used and the receiver could end up performing permission checking and providing SO_PEERSEC or SCM_SECURITY values for the wrong security context. security_xfrm_state_pol_flow_match() exists for this purpose and is already called from xfrm_state_look_at() for matching purposes. Further, xfrm_state_look_at() also performs a xfrm_selector_match() test, which is also missing from the xdst pcpu cache logic. Add calls to both of these functions when validating the cache entry. With these changes, the selinux-testsuite passes all tests again. Fixes: ec30d78c14a813db39a647b6a348b4286ba4abf5 ("xfrm: add xdst pcpu cache") Signed-off-by: Stephen Smalley Tested-by: Stephen Smalley --- This is an RFC because I am not entirely confident in the fix, e.g. is it sufficient to perform this matching only on the first xfrm or do they all need to be walked as in xfrm_bundle_ok()? Also, should we perform this matching before (as in this patch) or after calling xfrm_bundle_ok()? Also, do we need to test xfrm->sel.family before calling xfrm_selector_match (as in this patch) or not - xfrm_state_look_at() does so when the state is XFRM_STATE_VALID but not when it is _ERROR or _EXPIRED? net/xfrm/xfrm_policy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 2746b62..171818b 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1820,6 +1820,11 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols, !xfrm_pol_dead(xdst) && memcmp(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols) == 0 && + (!xdst->u.dst.xfrm->sel.family || + xfrm_selector_match(&xdst->u.dst.xfrm->sel, fl, + xdst->u.dst.xfrm->sel.family)) && + security_xfrm_state_pol_flow_match(xdst->u.dst.xfrm, + xdst->pols[0], fl) && xfrm_bundle_ok(xdst)) { dst_hold(&xdst->u.dst); return xdst;