From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-119847-1516383287-2-15812329291510473406 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org' X-Spam-charsets: plain='utf-8' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1516383286; b=mgavhEKzN4fA/zBYgXdKWTiw91VlbpiA65HwrYlYqXgICzH ivzWagyTbeMM1+eala0mHqkJHZx4BRD4L54SUEMTHjtrGjRnHS0bmFLE7fnqRAcC /WJ0o3D8oJOJRCq+LpdX/WwS4kFMlglCYtLC5nEbBWZ+JHAbqYvb1KDLyTf837Ms Zr/zHAVPiCmao4KvPlEHgBJKCiVojvTZ5mWOBlyJy9CyZFC4fTUhwS9YtydGqNcy FkC8MdwQr6s5ssoAKtx33VviRnMeWQ5Lnak3M/0excwdM770N6NqYefWCE5HaReI CwCpx7g1tgpBdPAA1Im8RRr+nV08o40lBLZtJiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=subject:to:cc:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding:sender:list-id; s=arctest; t= 1516383286; bh=kEf1BGFTUg091buyPfFIZasiE7EAHJtAMsMXMfBzfhE=; b=I LCp76VUge+t65hmMVkaJRw2/Ko4LE9bRUyawXCKKwhsngQ+jhm8QLm61z/eemDyh eaXNxMvHZhsZRm4Azp95vPaXdJ5K/l25dsyL+aTmuSG3HFowZBoNS+HtzfBp6yWN q1mkJEWEhBesm3f0oTgEko2i5Ve5M8Cc4QIkETVfetPLjK6By4xXfBo7o6SguzHy iIvNiR1Pl0bnQipoFp1s9aAdGIzYlV4xpyoRYkCRUhp0duOzRScjAACjzez7ntld Xb6JiIfXzYgu+xWZYwATs2F1k42NrZflTY5mKEPQM7qDw3XZlXZYr0xSNQTfNVhV 10j4gnhvzW3XlPOHhVHEQ== ARC-Authentication-Results: i=1; mx1.messagingengine.com; arc=none (no signatures found); dkim=pass (2048-bit rsa key sha256) header.d=android.com header.i=@android.com header.b=S3eN+L0H x-bits=2048 x-keytype=rsa x-algorithm=sha256 x-selector=20161025; dmarc=pass (p=none,has-list-id=yes,d=none) header.from=android.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=fmLPqd+g; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=android.com header.result=pass header_is_org_domain=yes Authentication-Results: mx1.messagingengine.com; arc=none (no signatures found); dkim=pass (2048-bit rsa key sha256) header.d=android.com header.i=@android.com header.b=S3eN+L0H x-bits=2048 x-keytype=rsa x-algorithm=sha256 x-selector=20161025; dmarc=pass (p=none,has-list-id=yes,d=none) header.from=android.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-google-dkim=pass (2048-bit rsa key) header.d=1e100.net header.i=@1e100.net header.b=fmLPqd+g; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=android.com header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932175AbeASRen (ORCPT ); Fri, 19 Jan 2018 12:34:43 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45370 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932567AbeASRej (ORCPT ); Fri, 19 Jan 2018 12:34:39 -0500 X-Google-Smtp-Source: ACJfBosX7nmozCzBIHjBMU+u06U4znV41YOkyWZcM6h6URsCf5xQrhC/zSArKwdgOzmcCGAk5b2aZQ== Subject: Re: [PATCH] general protection fault in sock_has_perm To: Stephen Smalley , linux-kernel@vger.kernel.org Cc: Paul Moore , Eric Paris , James Morris , "Serge E. Hallyn" , selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, stable@vger.kernel.org References: <20180118215853.228182-1-salyzyn@android.com> <1516382386.2560.11.camel@tycho.nsa.gov> From: Mark Salyzyn Message-ID: Date: Fri, 19 Jan 2018 09:34:36 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1516382386.2560.11.camel@tycho.nsa.gov> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On 01/19/2018 09:19 AM, Stephen Smalley wrote: > On Thu, 2018-01-18 at 13:58 -0800, Mark Salyzyn wrote: >> general protection fault: 0000 [#1] PREEMPT SMP KASAN >> . . . >> >> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c >> index 8644d864e3c1..95d7c8143373 100644 >> --- a/security/selinux/hooks.c >> +++ b/security/selinux/hooks.c >> @@ -4342,7 +4342,7 @@ static int sock_has_perm(struct sock *sk, u32 >> perms) >> struct common_audit_data ad; >> struct lsm_network_audit net = {0,}; >> >> - if (sksec->sid == SECINITSID_KERNEL) >> + if (!sksec || sksec->sid == SECINITSID_KERNEL) >> return 0; > The patch description says "null check the sk_security, and if the > case, reject the permissions." The patch code instead has it return > 0/success, i.e. permission granted. Which one is correct? -EACCESS would be advised, yes. THANKS. > If we > return -EACCES, then we might break userspace; if we return 0, we might > be allowing an operation that should have been denied. Both seem like > losing propositions. if the sk_security is NULL, it is in-effect a form of UAF, so kernel _and_ user space is already 'sick'. I think it is a significantly larger losing proposition to panic the kernel? Reporting -EACCESS (as was proper) is a error propagation way to let user space deal with the erroneous condition. > > Could we instead have selinux_sk_free_security() defer freeing of the > sock security blob to a call_rcu(), like we did for > inode_free_security, or change the caller of it to not free it until > the sock is truly freed? AFAIK the upper issue is the premature closing on an RCU protected object, and the _right_ answer is that its call should have been properly deferred to a synchronization or grace period. Having sk_free_security be deferred by the grace period runs the risk that it is in a race with the proper deletion of a languishing read object in an RCU. It is a bug in the upper layers. My proposal in this KISS stability patch is to make security deal with those bugs gracefully until all those issues are fixed (in ToT). -- Mark From mboxrd@z Thu Jan 1 00:00:00 1970 From: salyzyn@android.com (Mark Salyzyn) Date: Fri, 19 Jan 2018 09:34:36 -0800 Subject: [PATCH] general protection fault in sock_has_perm In-Reply-To: <1516382386.2560.11.camel@tycho.nsa.gov> References: <20180118215853.228182-1-salyzyn@android.com> <1516382386.2560.11.camel@tycho.nsa.gov> Message-ID: To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org On 01/19/2018 09:19 AM, Stephen Smalley wrote: > On Thu, 2018-01-18 at 13:58 -0800, Mark Salyzyn wrote: >> general protection fault: 0000 [#1] PREEMPT SMP KASAN >> . . . >> >> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c >> index 8644d864e3c1..95d7c8143373 100644 >> --- a/security/selinux/hooks.c >> +++ b/security/selinux/hooks.c >> @@ -4342,7 +4342,7 @@ static int sock_has_perm(struct sock *sk, u32 >> perms) >> struct common_audit_data ad; >> struct lsm_network_audit net = {0,}; >> >> - if (sksec->sid == SECINITSID_KERNEL) >> + if (!sksec || sksec->sid == SECINITSID_KERNEL) >> return 0; > The patch description says "null check the sk_security, and if the > case, reject the permissions." The patch code instead has it return > 0/success, i.e. permission granted. Which one is correct? -EACCESS would be advised, yes. THANKS. > If we > return -EACCES, then we might break userspace; if we return 0, we might > be allowing an operation that should have been denied. Both seem like > losing propositions. if the sk_security is NULL, it is in-effect a form of UAF, so kernel _and_ user space is already 'sick'. I think it is a significantly larger losing proposition to panic the kernel? Reporting -EACCESS (as was proper) is a error propagation way to let user space deal with the erroneous condition. > > Could we instead have selinux_sk_free_security() defer freeing of the > sock security blob to a call_rcu(), like we did for > inode_free_security, or change the caller of it to not free it until > the sock is truly freed? AFAIK the upper issue is the premature closing on an RCU protected object, and the _right_ answer is that its call should have been properly deferred to a synchronization or grace period. Having sk_free_security be deferred by the grace period runs the risk that it is in a race with the proper deletion of a languishing read object in an RCU. It is a bug in the upper layers. My proposal in this KISS stability patch is to make security deal with those bugs gracefully until all those issues are fixed (in ToT). -- Mark -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html