linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* IMA & truncate
@ 2014-05-06 13:32 Dmitry Kasatkin
  2014-05-06 13:47 ` Javier González
  2014-05-06 16:59 ` Al Viro
  0 siblings, 2 replies; 7+ messages in thread
From: Dmitry Kasatkin @ 2014-05-06 13:32 UTC (permalink / raw)
  To: linux-security-module, Mimi Zohar; +Cc: viro, Linux Kernel Mailing List

Hi,

I have discovered one IMA related issue.

IMA file hash is re-calculate if needed on file close.

It works with ftruncate(fd, length) syscall, because it operates on
"opened" file.
Recalculation is happening on file close.

truncate(path, length) syscall works with path and no file open/close
takes place.
Recalculation does not happen.
IMA denies file access later.

It looks like vfs_truncate() should possibly call IMA to recalculate the
hash.

- Dmitry


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 13:32 IMA & truncate Dmitry Kasatkin
@ 2014-05-06 13:47 ` Javier González
  2014-05-06 16:59 ` Al Viro
  1 sibling, 0 replies; 7+ messages in thread
From: Javier González @ 2014-05-06 13:47 UTC (permalink / raw)
  To: Dmitry Kasatkin
  Cc: linux-security-module, Mimi Zohar, viro,
	Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2162 bytes --]

Hi,

> I have discovered one IMA related issue.
> 
> IMA file hash is re-calculate if needed on file close.
> 
> It works with ftruncate(fd, length) syscall, because it operates on
> "opened" file.
> Recalculation is happening on file close.
> 
> truncate(path, length) syscall works with path and no file open/close
> takes place.
> Recalculation does not happen.
> IMA denies file access later.
> 
> It looks like vfs_truncate() should possibly call IMA to recalculate the
> hash.

I have had the same issue in an integrity module I am working on to move the hash (and generally encryption) operations to a secure processor (e.g., TrustZone).
After a discussion with Al Viro I was convinced that file_close is not the right place to associate a hook in order to recalculate the hash.

I am now using the LSM hook associated with vfs_truncate to recalculate the hash and it seems to work good. I am still running some performance tests to calculate the overhead of attacking an operation here, so I don’t have data yet. 

Best,

-------------------------------------------------/--
Javier González

IT University of Copenhagen
Rued Langgaards Vej 7, 2300
København S, Danmark 
Office: 4D23

http://javigon.com/
Skype: javigon.napster
(+45)31376927

-------------------------------------------------/--

On 6 May 2014, at 15:32, Dmitry Kasatkin <d.kasatkin@samsung.com> wrote:

> Hi,
> 
> I have discovered one IMA related issue.
> 
> IMA file hash is re-calculate if needed on file close.
> 
> It works with ftruncate(fd, length) syscall, because it operates on
> "opened" file.
> Recalculation is happening on file close.
> 
> truncate(path, length) syscall works with path and no file open/close
> takes place.
> Recalculation does not happen.
> IMA denies file access later.
> 
> It looks like vfs_truncate() should possibly call IMA to recalculate the
> hash.
> 
> - Dmitry
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 496 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 13:32 IMA & truncate Dmitry Kasatkin
  2014-05-06 13:47 ` Javier González
@ 2014-05-06 16:59 ` Al Viro
  2014-05-06 18:39   ` Mimi Zohar
  2014-05-07  5:45   ` Dmitry Kasatkin
  1 sibling, 2 replies; 7+ messages in thread
From: Al Viro @ 2014-05-06 16:59 UTC (permalink / raw)
  To: Dmitry Kasatkin
  Cc: linux-security-module, Mimi Zohar, Linux Kernel Mailing List

On Tue, May 06, 2014 at 04:32:27PM +0300, Dmitry Kasatkin wrote:
> Hi,
> 
> I have discovered one IMA related issue.
> 
> IMA file hash is re-calculate if needed on file close.
> 
> It works with ftruncate(fd, length) syscall, because it operates on
> "opened" file.
> Recalculation is happening on file close.
> 
> truncate(path, length) syscall works with path and no file open/close
> takes place.
> Recalculation does not happen.
> IMA denies file access later.
> 
> It looks like vfs_truncate() should possibly call IMA to recalculate the
> hash.

Who said that it has permissions to read the file?  Reread truncate(2)
manpage; it requires the file to be *writable* for caller, but it doesn't
need it to be readable.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 16:59 ` Al Viro
@ 2014-05-06 18:39   ` Mimi Zohar
  2014-05-06 19:11     ` Al Viro
  2014-05-07  5:45   ` Dmitry Kasatkin
  1 sibling, 1 reply; 7+ messages in thread
From: Mimi Zohar @ 2014-05-06 18:39 UTC (permalink / raw)
  To: Al Viro; +Cc: Dmitry Kasatkin, linux-security-module, Linux Kernel Mailing List

On Tue, 2014-05-06 at 17:59 +0100, Al Viro wrote: 
> On Tue, May 06, 2014 at 04:32:27PM +0300, Dmitry Kasatkin wrote:
> > Hi,
> > 
> > I have discovered one IMA related issue.
> > 
> > IMA file hash is re-calculate if needed on file close.
> > 
> > It works with ftruncate(fd, length) syscall, because it operates on
> > "opened" file.
> > Recalculation is happening on file close.
> > 
> > truncate(path, length) syscall works with path and no file open/close
> > takes place.
> > Recalculation does not happen.
> > IMA denies file access later.
> > 
> > It looks like vfs_truncate() should possibly call IMA to recalculate the
> > hash.
> 
> Who said that it has permissions to read the file?  Reread truncate(2)
> manpage; it requires the file to be *writable* for caller, but it doesn't
> need it to be readable.

Al, you're not going to like this, but ima_calc_file_hash() calls
ima_calc_file_hash_tfm(), which already sets/unsets FMODE_READ in order
to calculate the file hash.

Mimi


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 18:39   ` Mimi Zohar
@ 2014-05-06 19:11     ` Al Viro
  2014-05-07  5:46       ` Dmitry Kasatkin
  0 siblings, 1 reply; 7+ messages in thread
From: Al Viro @ 2014-05-06 19:11 UTC (permalink / raw)
  To: Mimi Zohar
  Cc: Dmitry Kasatkin, linux-security-module, Linux Kernel Mailing List

On Tue, May 06, 2014 at 02:39:17PM -0400, Mimi Zohar wrote:

> Al, you're not going to like this, but ima_calc_file_hash() calls
> ima_calc_file_hash_tfm(), which already sets/unsets FMODE_READ in order
> to calculate the file hash.

And if it happens to be on NFS and server says "no reads for you"?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 16:59 ` Al Viro
  2014-05-06 18:39   ` Mimi Zohar
@ 2014-05-07  5:45   ` Dmitry Kasatkin
  1 sibling, 0 replies; 7+ messages in thread
From: Dmitry Kasatkin @ 2014-05-07  5:45 UTC (permalink / raw)
  To: Al Viro
  Cc: Dmitry Kasatkin, linux-security-module, Mimi Zohar,
	Linux Kernel Mailing List

On 6 May 2014 19:59, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Tue, May 06, 2014 at 04:32:27PM +0300, Dmitry Kasatkin wrote:
>> Hi,
>>
>> I have discovered one IMA related issue.
>>
>> IMA file hash is re-calculate if needed on file close.
>>
>> It works with ftruncate(fd, length) syscall, because it operates on
>> "opened" file.
>> Recalculation is happening on file close.
>>
>> truncate(path, length) syscall works with path and no file open/close
>> takes place.
>> Recalculation does not happen.
>> IMA denies file access later.
>>
>> It looks like vfs_truncate() should possibly call IMA to recalculate the
>> hash.
>
> Who said that it has permissions to read the file?  Reread truncate(2)
> manpage; it requires the file to be *writable* for caller, but it doesn't
> need it to be readable.

Sorry for repost. Lousy Android gmail client is not able to send with
plain text, even with reply.

This is the same case as for normal file close.
IMA will do file reading for the purpose of calculating a hash, even
file was opened for writing only. File reading is done when the last
writer closes the file and it is protected by mutex. Subsequent file
open is delayed by the mutex.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Thanks,
Dmitry

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: IMA & truncate
  2014-05-06 19:11     ` Al Viro
@ 2014-05-07  5:46       ` Dmitry Kasatkin
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Kasatkin @ 2014-05-07  5:46 UTC (permalink / raw)
  To: Al Viro
  Cc: Mimi Zohar, Dmitry Kasatkin, linux-security-module,
	Linux Kernel Mailing List

On 6 May 2014 22:11, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Tue, May 06, 2014 at 02:39:17PM -0400, Mimi Zohar wrote:
>
>> Al, you're not going to like this, but ima_calc_file_hash() calls
>> ima_calc_file_hash_tfm(), which already sets/unsets FMODE_READ in order
>> to calculate the file hash.
>
> And if it happens to be on NFS and server says "no reads for you"?

Sorry for repost. Lousy Android gmail client is not able to send with
plain text, even with reply.

IMA works by policy. It ignores non-local file systems by default.

But if someone still tries to enable nfs in the custom policy, it
might get into such situation. But then there are other issues like
security xattrs. Anyone using ima needs to be aware what he does.


> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 
Thanks,
Dmitry

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-05-07  5:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-06 13:32 IMA & truncate Dmitry Kasatkin
2014-05-06 13:47 ` Javier González
2014-05-06 16:59 ` Al Viro
2014-05-06 18:39   ` Mimi Zohar
2014-05-06 19:11     ` Al Viro
2014-05-07  5:46       ` Dmitry Kasatkin
2014-05-07  5:45   ` Dmitry Kasatkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).