From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751391AbdIRUZ6 (ORCPT ); Mon, 18 Sep 2017 16:25:58 -0400 Received: from sonic312-28.consmr.mail.ne1.yahoo.com ([66.163.191.209]:36107 "EHLO sonic312-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210AbdIRUZ5 (ORCPT ); Mon, 18 Sep 2017 16:25:57 -0400 X-YMail-OSG: Vhi8OksVM1mL5Gjawb0Dzt5VpIFmWycWUlpix8UBSu1sGk_7C6RnkGvSggUMzvN 2d1oZoHcbvRwHSavIyRqIOTW0ZadsdxcSjauoKMuX2qsYl1A__XvlRuHs5lUCwZAlpzaZ93kw74p TIQCHgeSR12mbvwFzEEaVrWBB4mZ2lYarKvd_4avWDDSsC98gBKuUW5hENWlYCPDoQSgQyiBw6Zw mcqv5s5OCEvwW7hTNLSpDS3RmgQu8kw4ZlGEjC.igvOx0c1wN70ggj4SOXbtQKZGIsSdHXZsTJjx AFXvIRp0kLs.KVNNfc.ocrucnVGcONtfsSovhlnMfVBwZUliLnoe2JAia36mXMrCmaz1d7xfIWHW SAQiV07dwPPa8Mn54suJcX6rA8fld84wscriX93LTkNpez34gXnCTmy.5D2qarb2AcBZdduUOAmu 95lsBww3vpQ5LZ8mW1Sjvx0nXL.kH2vUMRcgxLYepTO0pV2ol.TkBWa4lczsgh8QARYdEcXPU5t5 k6n5gFPKveeX7boPacg-- X-Yahoo-Newman-Id: 661469.39773.bm@smtp220.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Vhi8OksVM1mL5Gjawb0Dzt5VpIFmWycWUlpix8UBSu1sGk_ 7C6RnkGvSggUMzvN2d1oZoHcbvRwHSavIyRqIOTW0ZadsdxcSjauoKMuX2qs Yl1A__XvlRuHs5lUCwZAlpzaZ93kw74pTIQCHgeSR12mbvwFzEEaVrWBB4mZ 2lYarKvd_4avWDDSsC98gBKuUW5hENWlYCPDoQSgQyiBw6Zwmcqv5s5OCEvw W7hTNLSpDS3RmgQu8kw4ZlGEjC.igvOx0c1wN70ggj4SOXbtQKZGIsSdHXZs TJjxAFXvIRp0kLs.KVNNfc.ocrucnVGcONtfsSovhlnMfVBwZUliLnoe2JAi a36mXMrCmaz1d7xfIWHWSAQiV07dwPPa8Mn54suJcX6rA8fld84wscriX93L TkNpez34gXnCTmy.5D2qarb2AcBZdduUOAmu95lsBww3vpQ5LZ8mW1Sjvx0n XL.kH2vUMRcgxLYepTO0pV2ol.TkBWa4lczsgh8QARYdEcXPU5t5k6n5gFPK veeX7boPacg-- X-Yahoo-SMTP: OIJXglSswBDfgLtXluJ6wiAYv6_cnw-- Subject: Re: [BUG] security_release_secctx seems broken To: Konstantin Khlebnikov , linux-kernel Cc: Serge Hallyn , James Morris , LSM List , Casey Schaufler References: From: Casey Schaufler Message-ID: Date: Mon, 18 Sep 2017 13:25:50 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/16/2017 11:18 AM, Konstantin Khlebnikov wrote: > I've got this kmemleak splat > > unreferenced object 0xffff880f687ff6a8 (size 32): >   comm "cp", pid 4279, jiffies 4295784487 (age 2866.296s) >   hex dump (first 32 bytes): >     01 00 00 02 02 00 08 00 00 00 00 00 00 00 00 00  ................ >     00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5  .....kkkkkkkkkk. >   backtrace: >     [] kmemleak_alloc+0x4a/0xa0 >     [] __kmalloc_track_caller+0x171/0x280 >     [] krealloc+0xa7/0xc0 >     [] vfs_getxattr_alloc+0xbd/0x110 >     [] cap_inode_getsecurity+0x79/0x200 >     [] security_inode_getsecurity+0x52/0x80 >     [] xattr_getsecurity+0x3a/0xa0 >     [] vfs_getxattr+0x74/0xa0 >     [] getxattr+0x9e/0x170 >     [] SyS_fgetxattr+0x5a/0x90 >     [] entry_SYSCALL_64_fastpath+0x1e/0xae >     [] 0xffffffffffffffff > > allocated in  xattr_getsecurity() security_inode_getsecurity() -> cap_inode_getsecurity() > should be freed by security_release_secctx() but there is no release_secctx hook. There is a bug here, but the fix suggested is not correct. security_inode_getsecurity() provides the security attribute with a specified name. In the past there would be exactly one use for this call, which was to return the value of the attribute that happened to match the security "context" of the inode. Freeing the value with security_release_secctx() works coincidentally. Because security_inode_getsecurity() is called with the "true" value for the alloc parameter the correct fix is: - fix smack_inode_getsecurity() to honor the alloc flag - change the security_release_secctx() to kfree here. I can provide a patch in a day or so. > > I don't know details about modern security models stack but it > seems security_release_secctx() have to know which layer owns > secdata to free it property: selinux just calls kfree, > capability_hooks should do the same, but other modules returns > non-freeable pointers. Currently security_release_secctx() calls > release_secctx for all models, this is obviously wrong. > . From mboxrd@z Thu Jan 1 00:00:00 1970 From: casey@schaufler-ca.com (Casey Schaufler) Date: Mon, 18 Sep 2017 13:25:50 -0700 Subject: [BUG] security_release_secctx seems broken In-Reply-To: References: Message-ID: To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org On 9/16/2017 11:18 AM, Konstantin Khlebnikov wrote: > I've got this kmemleak splat > > unreferenced object 0xffff880f687ff6a8 (size 32): > ? comm "cp", pid 4279, jiffies 4295784487 (age 2866.296s) > ? hex dump (first 32 bytes): > ??? 01 00 00 02 02 00 08 00 00 00 00 00 00 00 00 00? ................ > ??? 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5? .....kkkkkkkkkk. > ? backtrace: > ??? [] kmemleak_alloc+0x4a/0xa0 > ??? [] __kmalloc_track_caller+0x171/0x280 > ??? [] krealloc+0xa7/0xc0 > ??? [] vfs_getxattr_alloc+0xbd/0x110 > ??? [] cap_inode_getsecurity+0x79/0x200 > ??? [] security_inode_getsecurity+0x52/0x80 > ??? [] xattr_getsecurity+0x3a/0xa0 > ??? [] vfs_getxattr+0x74/0xa0 > ??? [] getxattr+0x9e/0x170 > ??? [] SyS_fgetxattr+0x5a/0x90 > ??? [] entry_SYSCALL_64_fastpath+0x1e/0xae > ??? [] 0xffffffffffffffff > > allocated in? xattr_getsecurity() security_inode_getsecurity() -> cap_inode_getsecurity() > should be freed by security_release_secctx() but there is no release_secctx hook. There is a bug here, but the fix suggested is not correct. security_inode_getsecurity() provides the security attribute with a specified name. In the past there would be exactly one use for this call, which was to return the value of the attribute that happened to match the security "context" of the inode. Freeing the value with security_release_secctx() works coincidentally. Because security_inode_getsecurity() is called with the "true" value for the alloc parameter the correct fix is: - fix smack_inode_getsecurity() to honor the alloc flag - change the security_release_secctx() to kfree here. I can provide a patch in a day or so. > > I don't know details about modern security models stack but it > seems security_release_secctx() have to know which layer owns > secdata to free it property: selinux just calls kfree, > capability_hooks should do the same, but other modules returns > non-freeable pointers. Currently security_release_secctx() calls > release_secctx for all models, this is obviously wrong. > . -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html