Received: by 10.223.176.46 with SMTP id f43csp1170726wra; Fri, 19 Jan 2018 07:52:18 -0800 (PST) X-Google-Smtp-Source: ACJfBotDb+eNXvkoJHGRkEHoR33rpUVlkdTV4974c3lXBcax03L8h/GvP+/2yscAMxyhD4R7/eJ+ X-Received: by 10.98.163.131 with SMTP id q3mr37551077pfl.87.1516377137917; Fri, 19 Jan 2018 07:52:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516377137; cv=none; d=google.com; s=arc-20160816; b=CCwJY9roPseI9bwtDLTtNTnXzr205fdLT/kRatS0nmPOQOTJ9tu4LDvCtgSRT4UC8x +6Wdcez9r2bp8DNYtDaATMCD+bbnXPGbGT4+v6UMk2ls41sblQjI9YJvfnWzUmnpNpL9 U5KWTU2Rbm8jRYOoXJdtQh6Mj7wEqtFD+IcVJgoWzdHMP1JXSR0FR+gdOxy9oDFtl1rP HHgcwEobuq17aS+uHBO9KRWTWTx1i9PscrTM6aWjaxxmyTwtScpa4nNCqWIrOzPG46wC egA/EPtd753W/1Dvvo/ut1A1tS1nPP+I4ZzCYAkBRDiQr3kGIQ9ZqyCCp24CLpqE6MkJ BOcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=DhC/BQ2Svxg7cie0nISExRx0JImxfR7/QPEBM3xXt5g=; b=I73EH13J5BtVUSpthNspunsVvvWOpGcQv9LsETrTez+rPkDXFLa+2yVdawi4PSSC6h 5vvD83xsobfGCwiFE8D/VG8DyUQYoK29D4lCSsFBP0a9iCzLVz+TXZ+r3hAqS20rozcK /xdmjN2ivfa3OBIqLD2FulpTU4ZmlIvuPKW7yfcWvPbcDxq8BvEf8L9636NXJYtEgZKo 8zNehz1VbTec2urlwE90EAb8KMTAoUVGf4rKR9kge+vf1GvcudZhtog3k2wkn7Fg5/L9 fl/I49OxZrTri4XphwdqOh4MloToJCeU2UdN9OGuRNal8kdwNUnCzrrVNKg5MnmLyU29 O0fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=rsE1B+SR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x11-v6si911231plm.734.2018.01.19.07.52.03; Fri, 19 Jan 2018 07:52:17 -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; dkim=pass header.i=@android.com header.s=20161025 header.b=rsE1B+SR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755956AbeASPuO (ORCPT + 99 others); Fri, 19 Jan 2018 10:50:14 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:39045 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755910AbeASPuC (ORCPT ); Fri, 19 Jan 2018 10:50:02 -0500 Received: by mail-pf0-f175.google.com with SMTP id e11so1636668pff.6 for ; Fri, 19 Jan 2018 07:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=DhC/BQ2Svxg7cie0nISExRx0JImxfR7/QPEBM3xXt5g=; b=rsE1B+SRcUXyDiTuoAg5asPPVVipsI68kjuoNsJFq/tSY89JAUR3u/TwtzjujCTlym Vdw1/w838RGDQoKzR4SalTL9DJfKZ6PSdbWtkRBsPezMGg1DniSjdC3RpJm7YJ+IIxMu HdNtVuN9/xnY9hbilPCe3Kb15HQrzCNfLDortzH6uenX0m1UlI8UIoQnSIsyAme8JNY9 zAB+PIdiGVO4kuTU7BDv+nFKFc7huKYBcM163lOobAAcZJ3KFust682weohBbEcGzdyA J/QVh2/2e9Qm7U5SiDS1kH1dh41W1eryXJW8qPmhIRoEjPzBg7aMYPD61tVbPP52YE0y elDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=DhC/BQ2Svxg7cie0nISExRx0JImxfR7/QPEBM3xXt5g=; b=I2AlqUkfqSj/5+EKgLF4JBrxKH77fZ1+kRHE8Yi135v5dPLFU3GWuIwoL5n4GFh2zB Sn8zQA0aQI10d0MLq6E4Qlx3xBOXaSKlDGwHJzoj+2BNVHWGfbOdhmJxPcKOTZPV5tK+ ehRv9hoFOPNnrI8ATt5vw/B56j+awxLTt3IQFSOlER+UPmcMSgpc79Fa8z1/6ZiLO42M vCjkYOKiXz/NKCKpb/geHqpLOWbaNFyo1gd1fNatxf94o4PSwlP5lkAlioRZVDWb5rdH JByYzcwFKWLy2ZAY2AbU7Lu66xJwIP2olsrnq827u3Ki2hQadbiAIfAfDk+cSf89PgMK OnCg== X-Gm-Message-State: AKwxytdPXO2hyGUBiggZhkQVlkibLgdGSqwMYJslKnEgAPgOhjpXsGEv wFCFW1Oc2QEhpKwhvE3SzwMyWw== X-Received: by 2002:a17:902:860b:: with SMTP id f11-v6mr1854829plo.135.1516377001151; Fri, 19 Jan 2018 07:50:01 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([2620:0:1000:1612:b4fb:6752:f21f:3502]) by smtp.googlemail.com with ESMTPSA id e185sm20375883pfg.155.2018.01.19.07.49.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 07:50:00 -0800 (PST) Subject: Re: [PATCH] general protection fault in sock_has_perm To: Paul Moore Cc: linux-kernel@vger.kernel.org, Stephen Smalley , 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> From: Mark Salyzyn Message-ID: <1f185712-9136-be88-02c0-5613a7683619@android.com> Date: Fri, 19 Jan 2018 07:49:58 -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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/18/2018 02:36 PM, Paul Moore wrote: > On Thu, Jan 18, 2018 at 4:58 PM, Mark Salyzyn wrote: >> general protection fault: 0000 [#1] PREEMPT SMP KASAN >> CPU: 1 PID: 14233 Comm: syz-executor2 Not tainted 4.4.112-g5f6325b #28 >> . . . >> [] 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 ]--- >> >> 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. >> >> This adjustment is orthogonal to infrastructure improvements that may >> nullify the needed check, but should be added as good code hygiene. > I'm skeptical that this is the full solution for systems that lack the > SOCK_RCU_FREE protection. Is this really limited to just > setsockopt()? Maybe overstepped in my analysis and assumptions? This is a result of a fuzzer hitting an android 4.4 KASAN kernel. We (so far) have _not_ seen this with an android 4.9 KASAN kernel (which has the SOCK_RCU_FREE adjustments). There is no standalone duplication or PoC _except_ via the fuzzer. The rest of the statements stands based on this tidbit (statements of general good code hygiene, not 100% sure SOCK_RCU_FREE usage is completely covered, KISS solution etc). To be honest, yes, this may be a layer in the onion (swat this NULL check does not by itself solve the _problem_), I'd prefer kernel continuing on in a rational manner rather than panic ... and I have a gut feeling this could be a gratuitous NULL check if all the bugs in the network layer have been solved . Programming to solve a problem with one's gut is not a good practice, but hygiene is. This is 10 characters, and an estimated 1.2ns of added hygiene. No, I do not think this is limited to setsockopt, but would be willing to believe a multithreaded attack of any socket functions or ioctl would drop down to the check with sock_has_perm at possibly the wrong time in socket teardown. Sincerely -- Mark Salyzyn