Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759268Ab2HHUfO (ORCPT ); Wed, 8 Aug 2012 16:35:14 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:52045 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753822Ab2HHUfM (ORCPT ); Wed, 8 Aug 2012 16:35:12 -0400 From: Paul Moore To: Eric Dumazet Cc: Eric Paris , John Stultz , "Serge E. Hallyn" , lkml , James Morris , selinux@tycho.nsa.gov, Eric Dumazet , john.johansen@canonical.com Subject: Re: NULL pointer dereference in selinux_ip_postroute_compat Date: Wed, 08 Aug 2012 16:35:08 -0400 Message-ID: <2294220.dmCbVvF3Tg@sifl> User-Agent: KMail/4.9 (Linux/3.4.7-gentoo; KDE/4.9.0; x86_64; ; ) In-Reply-To: <1344456578.28967.244.camel@edumazet-glaptop> References: <50215A7E.8000701@linaro.org> <1344456578.28967.244.camel@edumazet-glaptop> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3007 Lines: 67 On Wednesday, August 08, 2012 10:09:38 PM Eric Dumazet wrote: > On Wed, 2012-08-08 at 15:59 -0400, Eric Paris wrote: > > Seems wrong. We shouldn't ever need ifdef CONFIG_SECURITY in core > > code. > > Sure but it seems include file misses an accessor for this. > > We could add it on a future cleanup patch, as Paul mentioned. Actually, the issue is that the shared socket doesn't have an init/alloc function to do the LSM allocation like we do with other sockets so Eric's patch does it as part of ip_send_unicast_reply(). If we look at the relevant part of Eric's patch: +#ifdef CONFIG_SECURITY + if (!sk->sk_security && security_sk_alloc(sk, PF_INET, GFP_ATOMIC)) + goto out; +#endif ... if we were to remove the CONFIG_SECURITY conditional we would end up calling security_sk_alloc() each time through in the CONFIG_SECURITY=n case as sk->sk_security would never be initialized to a non-NULL value. In the CONFIG_SECURITY=y case it should only be called once as security_sk_alloc() should set sk->sk_security to a LSM blob. > > Ifndef CONF_SECURITY then security_sk_alloc() is a static > > > > inline return 0; I guess the question is "Where did the sk come > > from"? Why wasn't security_sk_alloc() called when it was allocated? > > Should it have been updated at some time and that wasn't done either? > > Seems wrong to be putting packets on the queue for a socket where the > > security data was never allocated and was never set to its proper > > state. > > IMHO it seems wrong to even care about security for internal sockets. > > They are per cpu, shared for all users on the machine. The issue, from a security point of view, is that these sockets are sending network traffic; even if it is just resets and timewait ACKs, it is still network traffic and the LSMs need to be able to enforce security policy on this traffic. After all, what would you say if your firewall let these same packets pass without any filtering? The issue I'm struggling with at present is how should we handle this traffic from a LSM perspective. The label based LSMs, e.g. SELinux and Smack, use the LSM blob assigned to locally generated outbound traffic to identify the traffic and apply the security policy, so not only do we have to resolve the issue of ensuring the traffic is labeled correctly, we have to do it with a shared socket (although the patch didn't change the shared nature of the socket). For those who are interested, I think the reasonable labeling solution here is to go with SECINITSID_KERNEL/kernel_t for SELinux and likely the ambient label for Smack as in both the TCP reset and timewait ACK there shouldn't be any actual user data present. -- paul moore www.paul-moore.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/