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: 10032737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 185646039A for ; Mon, 30 Oct 2017 15:03:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F3AB28864 for ; Mon, 30 Oct 2017 15:03:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03D2928901; Mon, 30 Oct 2017 15:03:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89DA028864 for ; Mon, 30 Oct 2017 15:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932243AbdJ3PDt (ORCPT ); Mon, 30 Oct 2017 11:03:49 -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: =?us-ascii?q?9a23=3AB0Xb9B1yrbCKmo3gsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?sesXK/XxwZ3uMQTl6Ol3ixeRBMOHs6oC17Kd7PmocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZr?= =?us-ascii?q?KeTpAI7SiNm82/yv95HJbAhEmCaxbal9IRmqognctNQaipZ+J6gszRfEvmFGcP?= =?us-ascii?q?lMy2NyIlKTkRf85sOu85Nm7i9dpfEv+dNeXKvjZ6g3QqBWAzogM2Au+c3krgLD?= =?us-ascii?q?QheV5nsdSWoZjBxFCBXY4R7gX5fxtiz6tvdh2CSfIMb7Q6w4VSik4qx2RhDoki?= =?us-ascii?q?MHPCMn/m/RhMJ7kaZXrAu/qxBjxoLZZpyeOvhjcaPHZd4URXRPUNtfWSJCBY2x?= =?us-ascii?q?dJcDA/YbMOpEtYTxu0cCoB2jDgesHuPvzTpIi2fr060mzeshCQHG0xImH9kTrX?= =?us-ascii?q?rUqc/6NKMWUe+rzKjD0DLOb+hL1jfm84XIbhAgru2MXbJ3a8bRz1IvGBnfglWf?= =?us-ascii?q?rozlISqY2+IQuGaY9+ptTf+jhmEopg1rojWj290ghpfGi44L0FzI6CN0y5svK9?= =?us-ascii?q?KiUk50e9ukHYNVtyGdKoR5XNsvQ3ptuCYm0r0GvoO7fDQSxJQn2RHfb/uHfpCU?= =?us-ascii?q?4h35TuaRICp4hGl/dLKjhxe97UigyurmWsmyzFlKtTZKnsPJtnAM0xzf8smHSv?= =?us-ascii?q?1j8Ue9wTuDyg/e5+5eLU00iKbXMYAtz7EumpYJrEjPBir2l1/3jK+SeEUk4O+o?= =?us-ascii?q?6+H/b7X9u5CcLJR5ih3+M6symsy/Bv40Mg4VX2eB4+i827rj/VPhTLVQkvI2ir?= =?us-ascii?q?XZsIzdJckDvq62GRJV0oI45hanFTimzdAYkWACLFJCfxKHlZbmN0vSL/D/CPe1?= =?us-ascii?q?m06snytzx/DaIr3hBY3ALmPfkLj/c7Z95VBTyAwpwdBc45JbEKoBIOntVU/rqN?= =?us-ascii?q?zVFQQ5PBKozOb6DtVyyJ8eVXiTDa+eNaPYqUWI6f43I+mQeI8Vvy7wK/g76P70?= =?us-ascii?q?lnA2h0UdfbWy0JsYb3C4GOlpI0KDYXb2mNgBCX0FvgwkQ+Dwj12CSzFTa2yoUK?= =?us-ascii?q?Ih/js7Ep6pDZ/fRoCxh7yMxDq0EYdIZm9YD1CBCmrneJ+aW/gSbSKSJshhkjIY?= =?us-ascii?q?VbS7TY8uyw2uvhfgy7V7NurU5jEYtZX72dh76ezejgoy9SBuD8SZzW6NSXt4kX?= =?us-ascii?q?4WSDUuxqBwvVR9ykuf0ah/m/FYEd1T5/VUUgY1LJLc1PJ1BMzvWgLbf9eJVFan?= =?us-ascii?q?TsyjATE2U90x3tsObFhmFtW8gRDMwTCqD6UWl7OVHpw09LzT33zrK8Z60XbG27?= =?us-ascii?q?Erj0M6TctXKW2mmql/+hDVB4HXj0WWirildboH0S7T+2eM03COsFtbUAFuS6XF?= =?us-ascii?q?W24QZk/ModT+/EPCQOzmNbNyNAZdxcOcArVFZ8evjlhcQvrnftPEbDGfgWC1UC?= =?us-ascii?q?2Uy6uMYYyiQGAU2CHQGQBQiAwI1WqXPgg5QCG6qiTRCyI4RgGnWF/l7eQr8CDz?= =?us-ascii?q?dUQz1QzfKhc52g=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2AdBADpPvdZ/wHyM5BcHAEBBAEBCgEBFwEBBAEBCgEBgwg?= =?us-ascii?q?sgVInnSw/AQEBAQEHl3OCER2FKIRhQRYBAQEBAQEBAQEBAWoogjgkgm9SgVGIB?= =?us-ascii?q?oIQDao7Oop+ATGDLoIHgQyHIgGEFIUqBaIDlG8NkysCl0kmAi+BaCoKAh8IIw+?= =?us-ascii?q?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: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;