lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9fb8de9d-3a9a-706b-50a9-11e768f72851@schaufler-ca.com>
Date:   Thu, 31 May 2018 14:08:14 -0700
From:   Casey Schaufler <casey@...aufler-ca.com>
To:     "Eric W. Biederman" <ebiederm@...ssion.com>
Cc:     CHANDAN VN <chandan.vn@...sung.com>, gregkh@...uxfoundation.org,
        tj@...nel.org, bfields@...ldses.org, jlayton@...nel.org,
        linux-kernel@...r.kernel.org, linux-nfs@...r.kernel.org,
        cpgs@...sung.com, sireesha.t@...sung.com,
        Casey Schaufler <casey@...aufler-ca.com>
Subject: Re: [PATCH 1/1] Fix memory leak in kernfs_security_xattr_set and
 kernfs_security_xattr_set

On 5/31/2018 1:57 PM, Eric W. Biederman wrote:
> Casey Schaufler <casey@...aufler-ca.com> writes:
>
>> On 5/31/2018 2:28 AM, CHANDAN VN wrote:
>>> From: "sireesha.t" <sireesha.t@...sung.com>
>>>
>>> Leak is caused because smack_inode_getsecurity() is allocating memory
>>> using kstrdup(). Though the security_release_secctx() is called, it
>>> would not free the allocated memory. Calling security_release_secctx is
>>> not relevant for this scenario as inode_getsecurity() does not provide a
>>> "secctx".
>>>
>>> Similar fix has been mainlined:
>>> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?id=57e7ba04d422c3d41c8426380303ec9b7533ded9
>>>
>>> The fix is to replace the security_release_secctx() with a kfree()
>>>
>>> Below is the KMEMLEAK dump:
>>> unreferenced object 0xffffffc025e11c80 (size 64):
>>>   comm "systemd-tmpfile", pid 2452, jiffies 4294894464 (age 235587.492s)
>>>   hex dump (first 32 bytes):
>>>     53 79 73 74 65 6d 3a 3a 53 68 61 72 65 64 00 00  System::Shared..
>>>     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>>>   backtrace:
>>>     [<ffffff80081be770>] __save_stack_trace+0x28/0x34
>>>     [<ffffff80081bedb8>] create_object+0x130/0x25c
>>>     [<ffffff80088c82f8>] kmemleak_alloc+0x30/0x5c
>>>     [<ffffff80081b3ef0>] __kmalloc_track_caller+0x1cc/0x2a8
>>>     [<ffffff800818673c>] kstrdup+0x3c/0x6c
>>>     [<ffffff80082d78b0>] smack_inode_getsecurity+0xcc/0xec
>>>     [<ffffff80082d78f4>] smack_inode_getsecctx+0x24/0x44
>>>     [<ffffff80082d5ea0>] security_inode_getsecctx+0x50/0x70
>>>     [<ffffff800823bbcc>] kernfs_security_xattr_set+0x74/0xe0
>>>     [<ffffff80081eafec>] __vfs_setxattr+0x74/0x90
>>>     [<ffffff80081eb088>] __vfs_setxattr_noperm+0x80/0x1ac
>>>     [<ffffff80081eb238>] vfs_setxattr+0x84/0xac
>>>     [<ffffff80081eb374>] setxattr+0x114/0x178
>>>     [<ffffff80081eb44c>] path_setxattr+0x74/0xb8
>>>     [<ffffff80081ebdcc>] SyS_lsetxattr+0x10/0x1c
>>>     [<ffffff800808310c>] __sys_trace_return+0x0/0x4
>>>
>>> Signed-off-by: sireesha.t <sireesha.t@...sung.com>
>>> Signed-off-by: CHANDAN VN <chandan.vn@...sung.com>
>> Why not:
>>
>>  static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
>>  {
>> -	int len = 0;
>> -	len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
>> +	int len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, false);
>>
> The practical difference here is the true vs the false in the call
> to smack_inode_getsecurity?

That is correct. The author of smack_inode_getsecctx() has a SELinux
background and appears to have missed that Smack is careful not to
allocate memory and make copies of labels when it doesn't need to.

>
>>  	if (len < 0)
>>  		return len;
>>
> Eric
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ