From patchwork Tue Apr 13 07:09:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Johansen X-Patchwork-Id: 50037 X-Patchwork-Delegate: apw@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 61E9BB7C67 for ; Tue, 13 Apr 2010 17:10:08 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1O1aG2-0005lt-O1; Tue, 13 Apr 2010 08:10:02 +0100 Received: from adelie.canonical.com ([91.189.90.139]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1O1aFt-0005dr-63 for kernel-team@lists.ubuntu.com; Tue, 13 Apr 2010 08:09:53 +0100 Received: from hutte.canonical.com ([91.189.90.181]) by adelie.canonical.com with esmtp (Exim 4.69 #1 (Debian)) id 1O1aFt-00036r-4p; Tue, 13 Apr 2010 08:09:53 +0100 Received: from [96.225.230.137] (helo=canonical.com) by hutte.canonical.com with esmtpsa (TLS-1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1O1aFs-0002aX-Or; Tue, 13 Apr 2010 08:09:53 +0100 From: john.johansen@canonical.com To: kernel-team@lists.ubuntu.com Subject: [PATCH 03/11] AppArmor: Take refcount on cxt->profile to ensure it remains a valid reference Date: Tue, 13 Apr 2010 00:09:32 -0700 Message-Id: <1271142580-26555-4-git-send-email-john.johansen@canonical.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1271142580-26555-1-git-send-email-john.johansen@canonical.com> References: <1271142580-26555-1-git-send-email-john.johansen@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: John Johansen OriginalAuthor: John Johansen OriginalLocation: git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparm$ commit: ea35fcdcec2316aa57f2d9d5c9ed9002d90b9607 BugLink: http://bugs.launchpad.net/bugs/367499 A reference for a profile is not obtained from aa_newest_version(cxt->profile) this would normally be valid as cxt->profile will hold a reference keeping the profile valid, however cxt->profiles reference is replaced with the new_profile reference aa_put_profile(cxt->profile); /* transfer new profile reference will be released when cxt is freed */ cxt->profile = new_profile; before we are done referencing profile in aa_audit_file(profile, so obtain a reference to profile for the duration of the function. Signed-off-by: John Johansen Acked-by: Andy Whitcroft --- security/apparmor/domain.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c index 2721fcb..7af454f 100644 --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c @@ -350,7 +350,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm) cxt = bprm->cred->security; BUG_ON(!cxt); - profile = aa_newest_version(cxt->profile); + profile = aa_get_profile(aa_newest_version(cxt->profile)); /* * get the namespace from the replacement profile as replacement * can change the namespace @@ -480,6 +480,7 @@ audit: sa.base.error = aa_audit_file(profile, &sa); cleanup: + aa_put_profile(profile); kfree(buffer); return sa.base.error;