Re: Re: Zeroing data blocks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Avinash....

A small idea from non-fs expert...

> I am trying to zero data blocks whenever an unlink is invoked as part
> of a secure delete filesystem.

I checked your attached code and I tried to inspect how ext2-fs does 
file write (it is just my assumption that you're using ext2). I hit on 
generic_file_write(). From there, I hit __generic_file_write_nolock(), 
followed by __generic_file_aio_write_nolock() (mm/filemap.c). 

Interesting check happen here:
--------------------------------------------------------------------------
if (access_ok(VERIFY_READ, iv->iov_base, iv->iov_len))
                        continue;
--------------------------------------------------------------------------

>From the access_ok() macro's comment:
"Note that, depending on architecture, this function probably just
checks that the pointer is in the user space range - after calling
this function, memory access functions may still return -EFAULT."

I see that you're using memory block allocated by kmalloc(GFP_KERNEL). 
For a moment, I thought this won't be a problem since you already did :
set_fs(KERNEL_DS);

But.... in include/asm-i386/uaccess.h, looks like it is checking 
directly to thread_info for the segment limit, not in GDT or anything 
else:
------------------------------------------------------------------------------
 asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0" \
                :"=&r" (flag), "=r" (sum) \
                :"1" (addr),"g" ((int)(size)),"rm" 
(current_thread_info()->addr_limit.seg)); \
        flag; })

------------------------------------------------------------------------------

Thus, it violates access_ok...and AFAIK, seems like write will return 
with -EFAULT.

So, my suggestion is, either use kmalloc(GFP_USER) or simply use "shred" 
to avoid this low level complexity.

As always, CMIIW anyone.

regards,

Mulyadi


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux