Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1299326pxb; Fri, 1 Oct 2021 07:48:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQYshP6j6Pi1O8XfrJFSE8S1LC8EK3AqtW6pRozflg1fjB0UIKkWK2Z39nt2VJtCkNPF3c X-Received: by 2002:a17:906:39cd:: with SMTP id i13mr6458958eje.227.1633099693789; Fri, 01 Oct 2021 07:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633099693; cv=none; d=google.com; s=arc-20160816; b=Rivk2WCz/4dz4nlteH/exHqHgaTQYCRmdn8d0OvtdliWL93nvybEp2OV9uVDpLdiFF TA3Wd1W4mu2aQ0EQMYhMyBEXmBBMA8SHlsYzcbU+hb5/PrrBagiU+LITs894JbBCeeuS by+mf8Lv1l8QnrnEmJzaVMNuGOT6UoJx1lMr8S7z+KLDy4sD3rhJ2sLh4+9Kb4mdrgV7 b0JOvYyVU+9ke2640tzqERBFv691R+L4teNJpPLxkpzr4ZovazwRAMaWIgTVKyzc41MD GjJDDUv7ha/I66UNwP4EHJRVSv6+uUYr6e5dV6/MNer11OyEzqtU5lDUVXESC8Fsy47n TmYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/H4joMu0i9PRc5y/5IfyO1O3DFiCiHeAFXYOy9MybLU=; b=RH7Co6wG33slFFSwgk3JEIqTi05O/bNEenYLd5GxzPJP4ctDuYrzN5lH1DrhHOH+HZ EU6SDcTpfLFhbohtn74cJ82eF6We/FOfiAhkUSfIMVzsquZWY8FFkS6xYqoFFtnN5tM8 2ywU/cEU71IEOpiznlfdlBS7FpOgfDVl2wvJTq2JGUdTrmBBOW6x2bD9yhirgDPQ4d+v aVljQRUqhpiBYh3EX0lcRjXOXnxlH7w/Wt1K1IjMndIRlSXCMWlWOI1mgw0er5EGYJe4 qiHRUmVqEIH8DfNgm2mx2jbEyTIxFePzW/qzaw+g3FTZKcQvC3NvwgZAWWjNWTvBcKxY YcXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=Sqtq3HVE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si7007544ejr.434.2021.10.01.07.47.49; Fri, 01 Oct 2021 07:48:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=Sqtq3HVE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354636AbhJAOqu (ORCPT + 99 others); Fri, 1 Oct 2021 10:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354642AbhJAOqt (ORCPT ); Fri, 1 Oct 2021 10:46:49 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E10ABC0613E2 for ; Fri, 1 Oct 2021 07:45:04 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id g7so34847184edv.1 for ; Fri, 01 Oct 2021 07:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/H4joMu0i9PRc5y/5IfyO1O3DFiCiHeAFXYOy9MybLU=; b=Sqtq3HVEmFqyq/iZGy3bAUBBvoIIgqDCQe03hPij1pHQ+afGQ+qW4oxzfc6+IQYFAk 8sdQMlTfSDwM/Vdd1CJBkNXlYzqUIs7kjIrH/2t+zg3ttq27VO3sQ43AlcBfvpXxKTvl LJ3PlZ6m4VGH2MQRjDVCng2EuhT9h0wVEaeNU4baqn2jFjdOfQHFiF2yKOb9Jj/nE2WT +c/MWFqDTQ0Mz7EPjLT8UhMOzISMjhG8DhpniuDVQDNev5vXymJFaLiemoBg6FM8YkNB qKOz2aScbgR3tKjPuAU54oJVPgg5Bzspd8vBSSjyF4fyOuUspQHrydXkPUbbOutVmVuA y+2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/H4joMu0i9PRc5y/5IfyO1O3DFiCiHeAFXYOy9MybLU=; b=U8p3Wq3Wk6geaUEF4Fsw3F/oX6RIS9iyAZO4if+GtkCkaODZ8oZp8BfEJw9maRWfNn rQiesM+BXuW+PeftrbP1y+PQTlrfGECWBtIGVG5LzaGOqm8EoCDHtrylXo5wEr7rzn4z QzKXU2GCvCMDTdhi5myrAx3dZaBfZ+rYGG5JpNcDR+u8Rr7ReTEgLZ5Oqe1EP7h+8/+M Fukspp7g1oS5cDKGak9q/wZHRe5vY+llVtcBZ8X5lYP65QGOqCKmikQLRxaThVWmmM1m 5QMlPe6zWNh4UqfRtOvSquMXRsDIgcP/uSc5Efsfm9S7MbApZ+9nKo66tCcnmJ/RfZnC SfAg== X-Gm-Message-State: AOAM533nehfDSTfOKCVR0W9xYXRTMK+Q0Hd1mDu2pMLIgaobdI4HMDyq zz2rCWrPhdWy4dqA+I3J5vNUvgjs2qLjH3zw+ah9 X-Received: by 2002:a50:9b06:: with SMTP id o6mr14719691edi.284.1633099502606; Fri, 01 Oct 2021 07:45:02 -0700 (PDT) MIME-Version: 1.0 References: <20211001024506.3762647-1-tkjos@google.com> In-Reply-To: From: Paul Moore Date: Fri, 1 Oct 2021 10:44:51 -0400 Message-ID: Subject: Re: [PATCH] binder: use cred instead of task for selinux checks To: Todd Kjos Cc: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, christian@brauner.io, James Morris , Serge Hallyn , Stephen Smalley , Eric Paris , keescook@chromium.org, jannh@google.com, Jeffrey Vander Stoep , zohar@linux.ibm.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, joel@joelfernandes.org, kernel-team@android.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 1, 2021 at 10:38 AM Paul Moore wrote: > On Thu, Sep 30, 2021 at 10:45 PM Todd Kjos wrote: > > > > Save the struct cred associated with a binder process > > at initial open to avoid potential race conditions > > when converting to a security ID. > > > > Since binder was integrated with selinux, it has passed > > 'struct task_struct' associated with the binder_proc > > to represent the source and target of transactions. > > The conversion of task to SID was then done in the hook > > implementations. It turns out that there are race conditions > > which can result in an incorrect security context being used. > > > > Fix by saving the 'struct cred' during binder_open and pass > > it to the selinux subsystem. > > > > Fixes: 79af73079d75 ("Add security hooks to binder and implement the > > hooks for SELinux.") > > Signed-off-by: Todd Kjos > > Cc: stable@vger.kernel.org # 5.14 (need backport for earlier stables) > > --- > > drivers/android/binder.c | 14 +++++---- > > drivers/android/binder_internal.h | 3 ++ > > include/linux/lsm_hook_defs.h | 14 ++++----- > > include/linux/security.h | 28 +++++++++--------- > > security/security.c | 14 ++++----- > > security/selinux/hooks.c | 48 +++++++++---------------------- > > 6 files changed, 52 insertions(+), 69 deletions(-) > > Thanks Todd, I'm happy to see someone with a better understanding of > binder than me pitch in to clean this up :) A couple of quick > comments/questions below ... Ooops, I was a little over zealous when trimming my response and I accidentally cut off my comment that the associated comment blocks in include/linux/lsm_hooks.h should also be updated to reflect the binder LSM hook changes. -- paul moore www.paul-moore.com