Received: by 10.223.176.5 with SMTP id f5csp1055947wra; Fri, 2 Feb 2018 10:24:14 -0800 (PST) X-Google-Smtp-Source: AH8x225t1aLd9thfwuLaEQyP953GWddqWYanu/dijqWywUn5AVchcCGmBjkaJ6O+at/rRdAuYPgj X-Received: by 2002:a17:902:6881:: with SMTP id i1-v6mr36466890plk.323.1517595854580; Fri, 02 Feb 2018 10:24:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517595854; cv=none; d=google.com; s=arc-20160816; b=K2EJfqaEebrvt+K7vkmbCyrBCLRG7L6tR6h1fZY4V1hqBFOIdHLbKOddRjmrpoEzj2 qQ+A2VDrSr/ToCxEdUMSz4tJB+g7pFkFT7BeefFIpMoaTaZuutdI1fmH1dU0iYhCTpIx HodiWpNWWRW48gHTX1TgvNbROSKIFlq9SbX3aZ6ixXvlMtT5Zbmu44cMbgLvxmr9KCNA 8Qc6XmYuqeklOPA16MyoGfpROYGvrOxnc/hSBtb9yD6kWnYABUgwQqrUSs45mfRpThBP tj7G5HrQZ5qyUTT+GM95fMGkfutU1f6zU1aibDCf4fa+PZ7Jk172UBrj8+15IPUXwbVq Upbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=im57/zET/AGtk/weamzhHC7t9VjaC8u/HsYs5Fsd52c=; b=Jk3CKyxCQtZ8Tm4gEk7tTUHkWA2A9TZFse9M5s+1FEJfXGnV74jODsz8oCqTNpxW83 VpeqrLQS2sgp1ZInqHH5drWEzChQRKOVoJX5S9LCkrdVSCnx9a7PuZR54/T3c1ktbLx+ +6Xt0c61VRfYnHHn1dysQM5J+ajlot/9LucQA1E+0+9EXCwW5qRNX/ukC/2rdqOWO+ax xjw2aPwc5cmw4MVbmSnia3KleL1O0Hp3nKlDcwPS/4mfACuVviKTCUEosxW/aZeCA2cJ OjB+BgDpUxQ0LYYMdsNo0gXb+yZBZ/l/r+2kHC/MYLkwz9/zqKe/PVHc4PUzEejVuv6f J51w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si1713793pgo.189.2018.02.02.10.23.59; Fri, 02 Feb 2018 10:24:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754493AbeBBSXA (ORCPT + 99 others); Fri, 2 Feb 2018 13:23:00 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35480 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752534AbeBBRCk (ORCPT ); Fri, 2 Feb 2018 12:02:40 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 73DF6E5E; Fri, 2 Feb 2018 17:02:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Salyzyn , Paul Moore , Eric Dumazet , Stephen Smalley , selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, Eric Paris , "Serge E. Hallyn" Subject: [PATCH 4.4 65/67] selinux: general protection fault in sock_has_perm Date: Fri, 2 Feb 2018 17:58:34 +0100 Message-Id: <20180202140822.373416996@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Salyzyn In the absence of commit a4298e4522d6 ("net: add SOCK_RCU_FREE socket flag") and all the associated infrastructure changes to take advantage of a RCU grace period before freeing, there is a heightened possibility that a security check is performed while an ill-timed setsockopt call races in from user space. It then is prudent to null check sk_security, and if the case, reject the permissions. Because of the nature of this problem, hard to duplicate, no clear path, this patch is a simplified band-aid for stable trees lacking the infrastructure for the series of commits leading up to providing a suitable RCU grace period. This adjustment is orthogonal to infrastructure improvements that may nullify the needed check, but could be added as good code hygiene in all trees. general protection fault: 0000 [#1] PREEMPT SMP KASAN CPU: 1 PID: 14233 Comm: syz-executor2 Not tainted 4.4.112-g5f6325b #28 task: ffff8801d1095f00 task.stack: ffff8800b5950000 RIP: 0010:[] [] sock_has_perm+0x1fe/0x3e0 security/selinux/hooks.c:4069 RSP: 0018:ffff8800b5957ce0 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: 1ffff10016b2af9f RCX: ffffffff81b69b51 RDX: 0000000000000002 RSI: 0000000000000000 RDI: 0000000000000010 RBP: ffff8800b5957de0 R08: 0000000000000001 R09: 0000000000000001 R10: 0000000000000000 R11: 1ffff10016b2af68 R12: ffff8800b5957db8 R13: 0000000000000000 R14: ffff8800b7259f40 R15: 00000000000000d7 FS: 00007f72f5ae2700(0000) GS:ffff8801db300000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000a2fa38 CR3: 00000001d7980000 CR4: 0000000000160670 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Stack: ffffffff81b69a1f ffff8800b5957d58 00008000b5957d30 0000000041b58ab3 ffffffff83fc82f2 ffffffff81b69980 0000000000000246 ffff8801d1096770 ffff8801d3165668 ffffffff8157844b ffff8801d1095f00 ffff880000000001 Call Trace: [] selinux_socket_setsockopt+0x4d/0x80 security/selinux/hooks.c:4338 [] security_socket_setsockopt+0x7d/0xb0 security/security.c:1257 [] SYSC_setsockopt net/socket.c:1757 [inline] [] SyS_setsockopt+0xe8/0x250 net/socket.c:1746 [] entry_SYSCALL_64_fastpath+0x16/0x92 Code: c2 42 9b b6 81 be 01 00 00 00 48 c7 c7 a0 cb 2b 84 e8 f7 2f 6d ff 49 8d 7d 10 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e 83 01 00 00 41 8b 75 10 31 RIP [] sock_has_perm+0x1fe/0x3e0 security/selinux/hooks.c:4069 RSP ---[ end trace 7b5aaf788fef6174 ]--- Signed-off-by: Mark Salyzyn Acked-by: Paul Moore Cc: Eric Dumazet Cc: Stephen Smalley Cc: selinux@tycho.nsa.gov Cc: linux-security-module@vger.kernel.org Cc: Eric Paris Cc: Serge E. Hallyn Cc: linux-kernel@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- security/selinux/hooks.c | 2 ++ 1 file changed, 2 insertions(+) --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4032,6 +4032,8 @@ static int sock_has_perm(struct task_str struct lsm_network_audit net = {0,}; u32 tsid = task_sid(task); + if (!sksec) + return -EFAULT; if (sksec->sid == SECINITSID_KERNEL) return 0;