From patchwork Fri Oct 27 15:28:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Smalley X-Patchwork-Id: 10030169 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 7A530602D6 for ; Fri, 27 Oct 2017 15:28:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A7A528E96 for ; Fri, 27 Oct 2017 15:28:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EE3C28E9F; Fri, 27 Oct 2017 15:28:53 +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 51B6528E96 for ; Fri, 27 Oct 2017 15:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932143AbdJ0P2v (ORCPT ); Fri, 27 Oct 2017 11:28:51 -0400 Received: from ucol19pa11.eemsg.mail.mil ([214.24.24.84]:42692 "EHLO UCOL19PA11.eemsg.mail.mil" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932137AbdJ0P2v (ORCPT ); Fri, 27 Oct 2017 11:28:51 -0400 X-IronPort-AV: E=Sophos;i="5.44,304,1505779200"; d="scan'208";a="365990931" Received: from emsm-gh1-uea11.ncsc.mil ([214.29.60.3]) by UCOL19PA11.eemsg.mail.mil with ESMTP/TLS/AES256-SHA; 27 Oct 2017 15:28:34 +0000 X-IronPort-AV: E=Sophos;i="5.44,304,1505779200"; d="scan'208";a="5255673" IronPort-PHdr: =?us-ascii?q?9a23=3AZrTlCxGAV1FvXi3kfq2StZ1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ7yp8qwAkXT6L1XgUPTWs2DsrQf2rqQ6/iocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZr?= =?us-ascii?q?KeTpAI7SiNm82/yv95HJbQhFgDmwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+?= =?us-ascii?q?NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjD?= =?us-ascii?q?QhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/Vjq476dvVRTmli?= =?us-ascii?q?EJOTAk+23Tk8B8kb5XrBenqhdiwYDbfZuVOeJ+cK3DYN0US2lPUMFKWiBdHo+x?= =?us-ascii?q?dZcDAvAdMepEqYT2ulsArQG5BQmpHO7h1yNIiWHu3a06zeshFxzN0hElH90UtH?= =?us-ascii?q?TUqMv6NacPWu2y16nH0C7DYuhK2Tb99IfIchchreuKXbJra8Xd00YvFwTbjliJ?= =?us-ascii?q?r4HuIj2b1uMIs2eB7upgU/qihHU6qwF+uDSvwNkjipXRioIay1DE6SV5wJsuKt?= =?us-ascii?q?GiVEF7ZtukHZ1NvC+ZL4t7Wt4uTm5ntSogyrAKpIS3cDYFxZg53RLTdvqKeJWS?= =?us-ascii?q?7B35TuaeOzJ4iWpgeLK4mhm971Ctyvb5VsmoyFZKqTdFksXUunANyRPT7s+HR+?= =?us-ascii?q?Nh/ki7wzaP1h3T6vpeLUAolavUN54hwrkqmpoVrUvDBTP5lF/zjK+XckUo4umo?= =?us-ascii?q?6+L5bbX6vpKQKoB5hw7kPqkuh8CzG/o0PwcQU2SB5OiwzLjj8lf4QLVOgP02iK?= =?us-ascii?q?7ZsJXCKMQAu6G5GBRY0poj6hmjDzem184UnX8cLF1fYh6HgI/pO0/WLPDiEfi/?= =?us-ascii?q?m0iskCtsx/3eJr3uGIjNLnzYnbf5Z7l99kpcxBM2zdBY4JJUEK8OLOjvVU/2sd?= =?us-ascii?q?zSFgU5PBCsw+b7FNV90ZsTWWaOAq+fLaPTvkaE5vkxLOaQeY8Vojf9K+Ql5vL3?= =?us-ascii?q?iH85nkISfbSt3ZQJc324APtmLFuDYXb2gdcOD30KvgwgQ+zuklGCViRTZ3nhF5?= =?us-ascii?q?47szU6Dp+2SJzOTZ23gaCQmSK8EoBSa0hYBV2WV3TlbYOJX7ELci3WatRslj0C?= =?us-ascii?q?SKiJV54q1RboshTzjbVgMLn64Cod4Kn/2cB16uubrhQ78Th5HozJyG2WZ31llW?= =?us-ascii?q?MPATkt1eZwplIrmQTL6rRxn/ENTY8b3PhOSApvcMeEwg=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2AGAgA2T/NZ/wHyM5BcGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgwgsZG4nnStAAQEBAQeXcYIRHRCFGIRNQBcBAQEBAQEBAQEBA?= =?us-ascii?q?Woogjgkgm9SgT8SiAaCEA0QqwU6imsBAQgjBYMuggeBCYcWAYk+BaIDh2aNCQ2?= =?us-ascii?q?TKwKMX4pqIQE1gWgqCgIfCCMPgy2CXAwQggMlNokjLIIWAQEB?= Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by emsm-gh1-uea11.NCSC.MIL with ESMTP; 27 Oct 2017 15:28:34 +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 v9RFSXcf008541; Fri, 27 Oct 2017 11:28:33 -0400 From: Stephen Smalley To: linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Cc: paul@paul-moore.com, Stephen Smalley Subject: [RFC PATCH] xfrm: fix regression introduced by xdst pcpu cache Date: Fri, 27 Oct 2017 11:28:22 -0400 Message-Id: <20171027152822.16406-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 commit ec30d78c14a813db39a647b6a348b4286 ("xfrm: add xdst pcpu cache") introduced a regression in the use of labeled IPSEC. The cache was only checking that the policies are the same, but did not validate that the policy, state, and flow matched 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. This was triggering failures in the selinux-testsuite. The security_xfrm_state_pol_flow_match() hook exists for this purpose and is already called elsewhere from the xfrm state code for matching purposes. Add a call to this hook when validating the cache entry. With this change, the selinux-testsuite passes all tests again. Fixes: ec30d78c14a813db39a647b6a348b4286ba4abf5 ("xfrm: add xdst pcpu cache") Signed-off-by: Stephen Smalley --- Sending this as an RFC to lsm and selinux for comments before sending it to netdev. See https://github.com/SELinuxProject/selinux-kernel/issues/36 for earlier discussion about the bug. net/xfrm/xfrm_policy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index f062539..e7ec47f 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1820,6 +1820,8 @@ 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 && + 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;