Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4084663pxb; Mon, 4 Oct 2021 17:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwje08rVjw0gQLbCSizzIJr0Kb7Pms9svtYUUEn6Qa6oSSHwlGIMHXT0TMaNSo3C5pjt92Z X-Received: by 2002:a05:6402:319a:: with SMTP id di26mr22316595edb.84.1633392521358; Mon, 04 Oct 2021 17:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633392521; cv=none; d=google.com; s=arc-20160816; b=IwQ6EmNWCcAwnhEyQRvAsGvgkkylwL27DSvO6RpDuhsl4XFt7TDySBWiZSO7nIdnrz ul6t2zeywDNlBAmHqFGJM+Kl/Ai4A3AkooHnTro+E9Kkjc9AjlBJy4TJnXqWbgePZgvm BIQHRuhYoXa4QGE7hm6W2B5ckAq9kNCxGEDGWoh25ClNz877zpaROZ19WXEQJ+AXyYfx fyqx6hjHyRgrlZNbvP/lIfsva/qnSvfoP0P2LJpm8F2wNP2I38lkUes4f+6VPqsVTSz0 OjX6pOHUIgtVGJ+y5KPzYTZq3F5JWsSBz4iT773+56qXG+CZgT16s8JoKqAiOYZAul/2 HPmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=mY7WN61pldcW5w9M+Qq0QbpFbxJpAORC0hm78GtixUY=; b=qXZ60Sqvc9llWcXfFThPG1rXpCP6nzWGMf7QVqA/rHcBK0SStyQUb/OQE296LyjUGf YS+yOwSfgn7uwEZSxngWmiLtTqUXktwbHibFBPQxqyLUHgJcNK6MGs4TWV3rTO6tGu/L b8Cp0mKVoGYaF/kf9Z46PF9ttFWxxWxxF7zTD2qaGwQE+v9RXm/SdPiEQpG4DecWd65B dqFtQ5FLSHF59fswIxrZeh9hmzBtzhn1WaQfjDn8fz4M/W2QE07hy/Y3K/dDhqGVJcmE hfMKiOwye6w5YJHUFQ7Xb8+ZLZtY+4X6bxBM5/S6SGTzLDwpnrN9j8/lkUl9J8rjubnF jjUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=awzUlRwu; 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 kl9si18553234ejc.603.2021.10.04.17.08.17; Mon, 04 Oct 2021 17:08:41 -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=@yahoo.com header.s=s2048 header.b=awzUlRwu; 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 S236610AbhJDQVA (ORCPT + 99 others); Mon, 4 Oct 2021 12:21:00 -0400 Received: from sonic307-15.consmr.mail.ne1.yahoo.com ([66.163.190.38]:43709 "EHLO sonic307-15.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236729AbhJDQU5 (ORCPT ); Mon, 4 Oct 2021 12:20:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1633364348; bh=mY7WN61pldcW5w9M+Qq0QbpFbxJpAORC0hm78GtixUY=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject:Reply-To; b=awzUlRwuRvU8ZaC+IxNKjo2uaT9qBom3JlFeXBqaEBYzXCigALfbzOPIRbGj9G4QCrtutuLYesg7wJCN55JZ8rBGsCMR76tMIJf4pr0FE8lHLW3NvT1/L/IOTuyIM/e292x61hld49hZIoqWVbRs+ydazXC0twUqWQJRNGQuEGtlVPtod/DS+ZQOhXqJrpYuGhqwfXPd2zeEZZMsH05oJkmEgyWqPu4cxK3N2EnftR7BnXGP+KZk4bFGE6HxSQmpxr40rJDiPaycPuujDb8NzqddpJ09ntoue6ndvJ/g40wSjN5RsXOMYkMW25+fLQy1IRcRUdypxx/N3N3xoc5ihQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1633364348; bh=IOyCt/jN1iZCaTXIb2MvAFsfFiY4NcJ6xUvOTOjgfzE=; h=X-Sonic-MF:Subject:To:From:Date:From:Subject; b=NRRX1CoNjzdt24zkbdU5dwx2B0LZxBFnSDSpDcWUi+3nvxAlFQMR2M/acThytn6H4fnRriZ0dWntKCQNZiaTS+T9yHADnDOPEWrq8F3vUYOIpe4hE39WOXK0TzHHu12GcNknGiRGjC/ImuvETKucEeUGvU38bPlWRn82uhTrzWvGhqQ3lSPwQ0VeTZyaRgYfMVwJp+Pqs0R5XxS396upgk12/VfCWrKu5slmH6MBscZJacwDDZaKGAerneAeOMCITy/aSGbhubdoj+NsadLABgp3OAaPJm7heo3PmQq0mdsZrEcRAN4DMfDZ4ioyhzeABIK2QLUhdaFj2a3+Y5V7Lw== X-YMail-OSG: _YNEJFkVM1nLkTKq0WW1nyHy3k1soK5D6P.ap7q9A9gzAgbb1Zhu7Rd4A.xp2an c5I15VhYweUie8GFh4hEVeIdYUJnAm8NriYarnm9O.9Asxmu9qVtQrA0P4QoP2nWBaumkcsfSqEN Gw1rkL8oqhanK9CTOvQw5ElCT_kFje3ZJvr51_5gHUVL_kN0kfYdDr_NoCxkHiMCj7kjF7aRg5VR IOb5FxgoJCwY81nOcTjXH8IC9I_Z_UzMFa_jdf..r62xmwZv4JvgleWv8d6B_kKSJKKmM0uk4yg. 2c.deQ8Zx.zbqjJDC4o2_GjZMmSmXo27jN.W.0rmd.nBWSGXGorWDMvXr7AliqMy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5QncOhCMq08fR9eG2.WWVq2_lIwUymt.orYVgHjRtm1rcgQjoiCzA3DzGB_uB5Vz2ro8Douc VPOdk3jBr9VJKpe4A1aXYFs3tDpdlYAuGsil0Wqa.d4sorlQWWxhWM1O.V05tbGJfReaBHmDslE3 scXnJ.0yTnESd7HOpa9GVhMWuFznQY0eiYLxSeP2cfGF6N.GzVEbXUaenWOSPIE21JdVf04.akCe d_oTRCfx.VNQsslRAQaUXwIEo6ukX67sXfI46kgvIKFc10U7_MbnULmn6YQsh8R0JjshFm4J03rh u2TRZ9C4bNyYYfm9pxtsCnGdAdN3lnAtnM5XcXFpfU6j9KC7te9n9BssbleEfOcVBQDDXMeNPMwQ QDQRuILlodAcA0TwTZAab2xMxiq0eF9xdjrN27vIxmEMfjNtEjMFbw5Q4mhWj9i7da__p9RVhBxw vbMwLERCneDeuFmDfow_BAFLimSjvvCx_XHbFalJUOyhWGPw9apKTUlEw9SjCg9vle4f4RO_VWzU 57lCJgcTWsgqTQrXmaGE1Lxi32gq.Yp1ugKvNZBVSWPi.NXLK7sn_JEIeqLImPdUrt71fXzk.sQI Mo22dQqO_1SxerIZZjkiUF7kZLW9wuGhWacL1U5fzEkZHHCqZ8jHMywMrDUYdiV4ohT9w1gJyBh7 v.gUx3D8ovVaiV7AJ2AxZdCfs7pHE322O7OlbT3rGTeGjxWo4vrRK1IwUUQ8wqgo95p0m26LpTdH FrYJKGFZiVu2GT3JPfZVlatKjyLR82Vna_bkDS5LcNWRrJBwVWa.M2V6uJ.GYAPdm9j_8C4aUNz7 4h1z47jEbpBLyWMHdebfzol1RjO3dytFmvnzSgUYwXk21Rm1SG_VEyrSg9ljqadDaZ363VQ9IMXk JshWuyXr5sfA7slk6eyPxFhkzWcZnVJTIFEx7f6wcBIs- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Mon, 4 Oct 2021 16:19:08 +0000 Received: by kubenode510.mail-prod1.omega.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 6372976e85edb1cbbbfc2c0ba5be9d7a; Mon, 04 Oct 2021 16:19:03 +0000 (UTC) Subject: Re: [PATCH v2] binder: use cred instead of task for selinux checks To: Jann Horn Cc: Todd Kjos , gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, christian@brauner.io, jmorris@namei.org, serge@hallyn.com, paul@paul-moore.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, keescook@chromium.org, jeffv@google.com, 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, Casey Schaufler References: <20211001175521.3853257-1-tkjos@google.com> From: Casey Schaufler Message-ID: Date: Mon, 4 Oct 2021 09:19:02 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Mailer: WebService/1.1.19076 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Content-Length: 2999 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/1/2021 3:58 PM, Jann Horn wrote: > On Fri, Oct 1, 2021 at 10:10 PM Casey Schaufler wrote: >> On 10/1/2021 12:50 PM, Jann Horn wrote: >>> On Fri, Oct 1, 2021 at 9:36 PM Jann Horn wrote: >>>> On Fri, Oct 1, 2021 at 8:46 PM Casey Schaufler wrote: >>>>> On 10/1/2021 10:55 AM, 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. >>>>> In the LSM stacking patch set I've been posting for a while >>>>> (on version 29 now) I use information from the task structure >>>>> to ensure that the security information passed via the binder >>>>> interface is agreeable to both sides. Passing the cred will >>>>> make it impossible to do this check. The task information >>>>> required is not appropriate to have in the cred. >>>> Why not? Why can't you put the security identity of the task into th= e creds? >>> Ah, I get it now, you're concerned about different processes wanting >>> to see security contexts formatted differently (e.g. printing the >>> SELinux label vs printing the AppArmor label), right? >> That is correct. >> >>> But still, I don't think you can pull that information from the >>> receiving task. Maybe the easiest solution would be to also store tha= t >>> in the creds? Or you'd have to manually grab that information when >>> /dev/binder is opened. >> I'm storing the information in the task security blob because that's >> the appropriate scope. Today the LSM hook is given both task_struct's.= > Which is wrong, because you have no idea who the semantic "recipient > task" is - any task that has a mapping of the binder fd can > effectively receive transactions from it. > > (And the current "sender task" is also wrong, because binder looks at > the task that opened the binder device, not the task currently > performing the action.) I'm confused. Are you saying that the existing binder code is completely broken? Are you saying that neither "task" is correct? How does passing the creds from the wrong tasks "fix" the problem? >> It's easy to compare to make sure the tasks are compatible. > It would be, if you actually had a pair of tasks that accurately > represent the sender and the recipient. > >> Adding the >> information to the cred would be yet another case where the scope of >> security information is wrong. > Can you elaborate on why you think that? The information identifies how the task is going to display the security "context". It isn't used in access checks.