Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp26105imm; Fri, 21 Sep 2018 17:20:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV60utg6eGKs+lDRD+suBPg1zVw8YM4ZFiG+n+2nTiArcTUmASHihjXP89mDXQSZAQY3jkDHG X-Received: by 2002:a63:bd41:: with SMTP id d1-v6mr96254pgp.309.1537575612568; Fri, 21 Sep 2018 17:20:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575612; cv=none; d=google.com; s=arc-20160816; b=t/jF6mmaMoBsrEvqtL9sbTDc1iHu1ebFGxdNwG1XUVhEB4+cgWSIJ6agz1HPmbbOfM pUvkZgURuLRGRekoCWD2KMAYHOnR5CNb6PuI5I1VpgW0diLrcL+4HrsquW/yL6IrNCbd MW6dqXpCda7rSiLqHHJjDpMF388Jexufl7a5K/KHiBJ7Ex8UBkuuX5+qIi01JD03//ih Wc3nmY2KS5XAOmnhkXeAX02QgyFyNwzRV+lJG0VbspASBNaiI1/CdZU+J6++zL4YLBGo qJzSp0XmX6f9jbQGqKJ7a2L/1m4/b2hZhisFxmyBUKuDwZk3Tomf1dvlsG9cMldqp/eh Y1Dg== 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:to:subject:dkim-signature; bh=moeYvcwDz4aHiI88+2oNPpuMjK4sdeV0qJVQV11wnek=; b=JG7Uln6su8btpM5JsdZAgi/ZsHsYKEKhTZp8S7YayjPeUkB3p6sLvS9jZ9NUQRD23l 9T1aCcX4FSxvjltXypSZec5+snGWDCkB31MuYiVYX6EqqX4585oQNBMYw2RQkcHZCct5 U4RRq1w095POiey2YHlB5GmGR/1ZFsSLuuD8utepEivIheSOu42PoTH2SePiDUKxE4M+ VxQ5+SrhzOTL0Ljo5/+tMfTX4N/gX9TMms0lUeS/OrVvLZ7OLNjPT8LhReOHfL9JQout ZXMk116JDhFBzx6eFno/MWZISvGO5S1r82BPEEC9g7ezOugwgKqC+gz5vWRzswX6pSu7 o40w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=NCRyCMWs; 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 f62-v6si31273127pfb.218.2018.09.21.17.19.57; Fri, 21 Sep 2018 17:20:12 -0700 (PDT) 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=@yahoo.com header.s=s2048 header.b=NCRyCMWs; 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 S2391776AbeIVGJY (ORCPT + 99 others); Sat, 22 Sep 2018 02:09:24 -0400 Received: from sonic304-18.consmr.mail.bf2.yahoo.com ([74.6.128.41]:33427 "EHLO sonic304-18.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391751AbeIVGJX (ORCPT ); Sat, 22 Sep 2018 02:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1537575486; bh=moeYvcwDz4aHiI88+2oNPpuMjK4sdeV0qJVQV11wnek=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=NCRyCMWsfPCupQl75/PsQ9NYMrF2sRyV0BJIs40t4oxmrmoU9uFeTKXsqSwjE5kSdzXcRgKz9Ts8+x7WZ0+NTVgZMsAUWotfTNC0KHPwPJrdQKGVblBvyq/1k7ojgvoZ+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dHQkROfgd9K6PLsFyNSL13FLIWvoKpY0ew3v2lLhBCJJ2oG_qKU_I2bQ18nXiZLCLZfk9as6 qlPDh.FFd14Vi_ef7zkGOJ78qqd41Szn8ppKXEBqEX4yzWGyaz3dv5HHpDi2yutIin1a8Xf7IcuP m5Arr6g1xodbfWE2I3FRx3TJi9shakEeLJRFTkYHNoJSCnWzxQ.5oJJnajFfcXJxqqP6R95iEukr EX0InN3zrfbqZU2ZVyzYh3ZcRQBAMlWKx Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.bf2.yahoo.com with HTTP; Sat, 22 Sep 2018 00:18:06 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.102]) ([67.169.65.224]) by smtp420.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 2cf301e387c71a2550cd07cc03f04e49; Sat, 22 Sep 2018 00:18:04 +0000 (UTC) Subject: [PATCH v4 06/19] AppArmor: Abstract use of cred security blob To: LSM , James Morris , SE Linux , LKLM , John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , Stephen Smalley , "linux-fsdevel@vger.kernel.org" , Alexey Dobriyan , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Salvatore Mesoraca References: From: Casey Schaufler Message-ID: Date: Fri, 21 Sep 2018 17:17:59 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 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 Don't use the cred->security pointer directly. Provide a helper function that provides the security blob pointer. Signed-off-by: Casey Schaufler --- security/apparmor/domain.c | 2 +- security/apparmor/include/cred.h | 16 +++++++++++++++- security/apparmor/lsm.c | 10 +++++----- security/apparmor/task.c | 6 +++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c index 08c88de0ffda..726910bba84b 100644 --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c @@ -975,7 +975,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm) } aa_put_label(cred_label(bprm->cred)); /* transfer reference, released when cred is freed */ - cred_label(bprm->cred) = new; + set_cred_label(bprm->cred, new); done: aa_put_label(label); diff --git a/security/apparmor/include/cred.h b/security/apparmor/include/cred.h index e287b7d0d4be..a90eae76d7c1 100644 --- a/security/apparmor/include/cred.h +++ b/security/apparmor/include/cred.h @@ -23,8 +23,22 @@ #include "policy_ns.h" #include "task.h" -#define cred_label(X) ((X)->security) +static inline struct aa_label *cred_label(const struct cred *cred) +{ + struct aa_label **blob = cred->security; + + AA_BUG(!blob); + return *blob; +} +static inline void set_cred_label(const struct cred *cred, + struct aa_label *label) +{ + struct aa_label **blob = cred->security; + + AA_BUG(!blob); + *blob = label; +} /** * aa_cred_raw_label - obtain cred's label diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 8b8b70620bbe..4f51705c3c71 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -57,7 +57,7 @@ DEFINE_PER_CPU(struct aa_buffers, aa_buffers); static void apparmor_cred_free(struct cred *cred) { aa_put_label(cred_label(cred)); - cred_label(cred) = NULL; + set_cred_label(cred, NULL); } /* @@ -65,7 +65,7 @@ static void apparmor_cred_free(struct cred *cred) */ static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp) { - cred_label(cred) = NULL; + set_cred_label(cred, NULL); return 0; } @@ -75,7 +75,7 @@ static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp) static int apparmor_cred_prepare(struct cred *new, const struct cred *old, gfp_t gfp) { - cred_label(new) = aa_get_newest_label(cred_label(old)); + set_cred_label(new, aa_get_newest_label(cred_label(old))); return 0; } @@ -84,7 +84,7 @@ static int apparmor_cred_prepare(struct cred *new, const struct cred *old, */ static void apparmor_cred_transfer(struct cred *new, const struct cred *old) { - cred_label(new) = aa_get_newest_label(cred_label(old)); + set_cred_label(new, aa_get_newest_label(cred_label(old))); } static void apparmor_task_free(struct task_struct *task) @@ -1455,7 +1455,7 @@ static int __init set_init_ctx(void) if (!ctx) return -ENOMEM; - cred_label(cred) = aa_get_label(ns_unconfined(root_ns)); + set_cred_label(cred, aa_get_label(ns_unconfined(root_ns))); task_ctx(current) = ctx; return 0; diff --git a/security/apparmor/task.c b/security/apparmor/task.c index c6b78a14da91..4551110f0496 100644 --- a/security/apparmor/task.c +++ b/security/apparmor/task.c @@ -81,7 +81,7 @@ int aa_replace_current_label(struct aa_label *label) */ aa_get_label(label); aa_put_label(cred_label(new)); - cred_label(new) = label; + set_cred_label(new, label); commit_creds(new); return 0; @@ -138,7 +138,7 @@ int aa_set_current_hat(struct aa_label *label, u64 token) return -EACCES; } - cred_label(new) = aa_get_newest_label(label); + set_cred_label(new, aa_get_newest_label(label)); /* clear exec on switching context */ aa_put_label(ctx->onexec); ctx->onexec = NULL; @@ -172,7 +172,7 @@ int aa_restore_previous_label(u64 token) return -ENOMEM; aa_put_label(cred_label(new)); - cred_label(new) = aa_get_newest_label(ctx->previous); + set_cred_label(new, aa_get_newest_label(ctx->previous)); AA_BUG(!cred_label(new)); /* clear exec && prev information when restoring to previous context */ aa_clear_task_ctx_trans(ctx); -- 2.17.1