From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756694AbcFAA3y (ORCPT ); Tue, 31 May 2016 20:29:54 -0400 Received: from nm32-vm3.bullet.mail.bf1.yahoo.com ([72.30.239.139]:51943 "EHLO nm32-vm3.bullet.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbcFAA3x (ORCPT ); Tue, 31 May 2016 20:29:53 -0400 X-Greylist: delayed 328 seconds by postgrey-1.27 at vger.kernel.org; Tue, 31 May 2016 20:29:52 EDT X-Yahoo-Newman-Id: 651864.31400.bm@smtp228.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: LwFOgqUVM1mT6Ffij_pDb.LXjdplDRrN8.uN.ey32kdUyeq x6CbvsLCTJQLkDZrd9noFbU1deSkBtXlHjVWYnTaHoh22STyOAYnA1fKH4_. M.MCqs5gfGyqDRYatHkDREZdLMw6JZyed_z4Lg43WAfs2LGkRbrWG7if9mPa GrymQCP9BNinuBhSDFkzJZe2fntMhxvAskW1O6vhSS.gsAEoKS0YVhi5iahr JACR0gWHP0G2kLa1i2NYT93TVP3_XOaHkKd_Yw5BrfsUxres0jSNYdn4ygcE VZxQheoMYoKer.ja3cwFL8m7F0qUH4j3ykLqjCZeNo9bUdi2WN30mzsyPGTt OZylw2hy2ubGoGVemeZdRd3IJYLwlsys.e9nwVQuih5VPxXa9RQVGllnO8LM sIi3tosngB0qpZNRvy3hzpz9d7wwgh9j0aE3UpXQOsBJVC5.3vK2FOP54tJZ 9QxlffPGDX9G7ZWzdQtGcIISyCF486jEpJ1oi9Cp6kes4L_Fu7U0dbOjSUSs eYKRRxQStfcH3xGASNrsmaceaLv1N3Agxi8dg_pzAkDMTxGaU191v7nQ4QnU - X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- From: Casey Schaufler To: LSM , James Morris Cc: "Serge E. Hallyn" , Casey Schaufler , LKLM Subject: [PATCH] LSM: Fix for security_inode_getsecurity and -EOPNOTSUPP Message-ID: Date: Tue, 31 May 2016 17:24:15 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Subject: [PATCH] LSM: Fix for security_inode_getsecurity and -EOPNOTSUPP Serge Hallyn pointed out that the current implementation of security_inode_getsecurity() works if there is only one hook provided for it, but will fail if there is more than one and the attribute requested isn't supplied by the first module. This isn't a problem today, since only SELinux and Smack provide this hook and there is (currently) no way to enable both of those modules at the same time. Serge, however, wants to introduce a capability attribute and an inode_getsecurity hook in the capability security module to handle it. This addresses that upcoming problem, will be required for "extreme stacking" and is just a better implementation. Signed-off-by: Casey Schaufler --- security/security.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/security/security.c b/security/security.c index 3644b03..5a749ed 100644 --- a/security/security.c +++ b/security/security.c @@ -699,18 +699,39 @@ int security_inode_killpriv(struct dentry *dentry) int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc) { + struct security_hook_list *hp; + int rc; + if (unlikely(IS_PRIVATE(inode))) return -EOPNOTSUPP; - return call_int_hook(inode_getsecurity, -EOPNOTSUPP, inode, name, - buffer, alloc); + /* + * Only one module will provide an attribute with a given name. + */ + list_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { + rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc); + if (rc != -EOPNOTSUPP) + return rc; + } + return -EOPNOTSUPP; } int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) { + struct security_hook_list *hp; + int rc; + if (unlikely(IS_PRIVATE(inode))) return -EOPNOTSUPP; - return call_int_hook(inode_setsecurity, -EOPNOTSUPP, inode, name, - value, size, flags); + /* + * Only one module will provide an attribute with a given name. + */ + list_for_each_entry(hp, &security_hook_heads.inode_setsecurity, list) { + rc = hp->hook.inode_setsecurity(inode, name, value, size, + flags); + if (rc != -EOPNOTSUPP) + return rc; + } + return -EOPNOTSUPP; } int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)