<div dir="ltr"><div><div><div><div><div><div><div><div>hello<br></div>I am working on adding a simple encryption to file contents in ext4 driver (for learning purposes) I added simple XOR encryption to aio_read and aio_write functions and it worked until I faced this problem:<br><br></div>when I open a file in encrypted filesystem using VIM text editor and when I try to save it it gives me this error:<br><br></div>&gt;&gt;pointer block id wrong<br></div>&gt;&gt;can not find line 1<br></div><br></div>and it just corrupts the entire file! <br><br></div>this is my aio_write function:<br><br>aio_write_enc(struct kiocb *iocb, const struct iovec *iov,<br>        unsigned long nr_segs, loff_t pos)<br>{<br>    size_t i;<br>    ssize_t ret;<br>    char *data=vmalloc(sizeof(char)*iov-&gt;iov_len);<br>    copy_from_user(data,iov-&gt;iov_base,iov-&gt;iov_len);<br><br>    for(i=0;i&lt;iov-&gt;iov_len;i++)<br>    {<br>        data[i]^=5;<br>    }<br>    struct iovec iov_enc= { .iov_base = iov-&gt;iov_base, .iov_len = iov-&gt;iov_len };<br><br>    copy_to_user(iov_enc.iov_base,data,iov-&gt;iov_len);<br>    ret=ext4_file_write(iocb,&amp;iov_enc,nr_segs,pos);<br>    vfree(data);<br>    return ret;<br>}<br><br></div><div>this just changes the data and then calls original function.<br></div><div><br></div>is there anything wrong with this function? can anyone help me?<br></div>