set_fs() fixes for 5.10

set_fs() is being deprecated in 5.10 on account of some security
problems (https://lwn.net/Articles/832121) and thus causes build
problems. This replaces set_fs() with kernel_read() and kernel_write()
to r&w to kernel's address space.

(build & runtime tested on 5.10.0-rc4)
This commit is contained in:
bhavay grover 2020-11-22 15:58:17 -05:00
parent c48292877c
commit e2873668ab

View File

@ -1548,7 +1548,6 @@ static int isFileReadable(char *path)
{ {
struct file *fp; struct file *fp;
int ret = 0; int ret = 0;
mm_segment_t oldfs;
char buf; char buf;
fp=filp_open(path, O_RDONLY, 0); fp=filp_open(path, O_RDONLY, 0);
@ -1556,13 +1555,8 @@ static int isFileReadable(char *path)
ret = PTR_ERR(fp); ret = PTR_ERR(fp);
} }
else { else {
oldfs = get_fs(); set_fs(KERNEL_DS); ret = kernel_read(fp, &buf, 1, NULL);
closeFile(fp);
if(1!=readFile(fp, &buf, 1))
ret = PTR_ERR(fp);
set_fs(oldfs);
filp_close(fp,NULL);
} }
return ret; return ret;
} }
@ -1584,9 +1578,7 @@ static int retriveFromFile(char *path, u8* buf, u32 sz)
if( 0 == (ret=openFile(&fp,path, O_RDONLY, 0)) ){ if( 0 == (ret=openFile(&fp,path, O_RDONLY, 0)) ){
DBG_871X("%s openFile path:%s fp=%p\n",__FUNCTION__, path ,fp); DBG_871X("%s openFile path:%s fp=%p\n",__FUNCTION__, path ,fp);
oldfs = get_fs(); set_fs(KERNEL_DS); ret = kernel_read(fp, buf, sz, NULL);
ret=readFile(fp, buf, sz);
set_fs(oldfs);
closeFile(fp); closeFile(fp);
DBG_871X("%s readFile, ret:%d\n",__FUNCTION__, ret); DBG_871X("%s readFile, ret:%d\n",__FUNCTION__, ret);
@ -1618,9 +1610,7 @@ static int storeToFile(char *path, u8* buf, u32 sz)
if( 0 == (ret=openFile(&fp, path, O_CREAT|O_WRONLY, 0666)) ) { if( 0 == (ret=openFile(&fp, path, O_CREAT|O_WRONLY, 0666)) ) {
DBG_871X("%s openFile path:%s fp=%p\n",__FUNCTION__, path ,fp); DBG_871X("%s openFile path:%s fp=%p\n",__FUNCTION__, path ,fp);
oldfs = get_fs(); set_fs(KERNEL_DS); ret = kernel_write(fp, buf, sz, NULL);
ret=writeFile(fp, buf, sz);
set_fs(oldfs);
closeFile(fp); closeFile(fp);
DBG_871X("%s writeFile, ret:%d\n",__FUNCTION__, ret); DBG_871X("%s writeFile, ret:%d\n",__FUNCTION__, ret);