Skip to content

Commit 509c5a8

Browse files
Jiamin Maakiernan
Jiamin Ma
authored andcommitted
security: fix security issues about mem corruption and info leakage
PD#150578: kernel4.9 secure review issues 1. Kernel Debugging Options Enabled 2. Exploit Mitigations (KASLR, Stack Protector) Not Enabled In Kernel Config 3. Buffer Overflow in Amvideo Driver file_name SysFS Attribute 4. Memory Corruption in VFM Driver SysFS Attribute 5. Kernel Syslog Accessible To Unprivileged Users 6. Kernel Memory Corruption in EFuse Driver 7. Kernel Memory Corruption in Unifykey IOCTL Change-Id: I277c449f4cb14141bf37f90fd66764b8dccaaee0 Signed-off-by: Jiamin Ma <jiamin.ma@amlogic.com>
1 parent 63aca01 commit 509c5a8

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

arch/arm64/configs/meson64_defconfig

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ CONFIG_CGROUP_CPUACCT=y
1818
CONFIG_CGROUP_SCHED=y
1919
CONFIG_RT_GROUP_SCHED=y
2020
CONFIG_BLK_DEV_INITRD=y
21+
CONFIG_KALLSYMS_ALL=y
2122
CONFIG_EMBEDDED=y
2223
# CONFIG_COMPAT_BRK is not set
2324
CONFIG_PROFILING=y
2425
CONFIG_JUMP_LABEL=y
26+
CONFIG_CC_STACKPROTECTOR_STRONG=y
2527
CONFIG_MODULES=y
2628
CONFIG_MODULE_UNLOAD=y
2729
CONFIG_PCI=y
@@ -515,8 +517,7 @@ CONFIG_DEBUG_ATOMIC_SLEEP=y
515517
CONFIG_FTRACE_SYSCALLS=y
516518
CONFIG_STACK_TRACER=y
517519
CONFIG_FUNCTION_PROFILER=y
518-
CONFIG_KGDB=y
519-
CONFIG_KGDB_TESTS=y
520+
CONFIG_SECURITY_DMESG_RESTRICT=y
520521
CONFIG_SECURITY_PERF_EVENTS_RESTRICT=y
521522
CONFIG_SECURITY=y
522523
CONFIG_SECURITYFS=y

drivers/amlogic/efuse/efuse.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,30 @@ loff_t efuse_llseek(struct file *filp, loff_t off, int whence)
101101
static long efuse_unlocked_ioctl(struct file *file, unsigned int cmd,
102102
unsigned long arg)
103103
{
104-
struct efuseinfo_item_t *info;
104+
void __user *argp = (void __user *)arg;
105+
struct efuseinfo_item_t info;
106+
int ret;
107+
105108

106109
switch (cmd) {
107110
case EFUSE_INFO_GET:
108-
info = (struct efuseinfo_item_t *)arg;
109-
if (efuse_getinfo_byTitle(info->title, info) < 0)
111+
ret = copy_from_user(&info, argp, sizeof(info));
112+
if (ret != 0) {
113+
pr_err("%s:%d,copy_from_user fail\n",
114+
__func__, __LINE__);
115+
return ret;
116+
}
117+
118+
if (efuse_getinfo_byTitle(info.title, &info) < 0)
110119
return -EFAULT;
120+
121+
ret = copy_to_user(argp, &info, sizeof(info));
122+
if (ret != 0) {
123+
pr_err("%s:%d,copy_to_user fail\n",
124+
__func__, __LINE__);
125+
return ret;
126+
}
127+
111128
break;
112129

113130
default:

drivers/amlogic/efuse/efuse64.c

+19-4
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,30 @@ loff_t efuse_llseek(struct file *filp, loff_t off, int whence)
169169
static long efuse_unlocked_ioctl(struct file *file, unsigned int cmd,
170170
unsigned long arg)
171171
{
172-
struct efusekey_info *info;
172+
void __user *argp = (void __user *)arg;
173+
struct efusekey_info info;
174+
int ret;
175+
173176

174177
switch (cmd) {
175178
case EFUSE_INFO_GET:
176-
info = (struct efusekey_info *)arg;
177-
if (efuse_getinfo(info->keyname, info) < 0) {
178-
pr_err("%s if not found\n", info->keyname);
179+
ret = copy_from_user(&info, argp, sizeof(info));
180+
if (ret != 0) {
181+
pr_err("%s:%d,copy_from_user fail\n",
182+
__func__, __LINE__);
183+
return ret;
184+
}
185+
if (efuse_getinfo(info.keyname, &info) < 0) {
186+
pr_err("%s if not found\n", info.keyname);
179187
return -EFAULT;
180188
}
189+
190+
ret = copy_to_user(argp, &info, sizeof(info));
191+
if (ret != 0) {
192+
pr_err("%s:%d,copy_to_user fail\n",
193+
__func__, __LINE__);
194+
return ret;
195+
}
181196
break;
182197

183198
default:

drivers/amlogic/media/common/vfm/vfm.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ int vfm_map_add(char *id, char *name_chain)
170170
return -ENOMEM;
171171
}
172172
memset(p, 0, sizeof(struct vfm_map_s));
173-
memcpy(p->id, id, strlen(id));
173+
if (strlen(id) >= sizeof(p->id)) {
174+
memcpy(p->id, id, sizeof(p->id));
175+
p->id[sizeof(p->id)-1] = '\0';
176+
} else
177+
memcpy(p->id, id, strlen(id));
174178
p->valid = 1;
175179
ptr = name_chain;
176180

@@ -180,7 +184,13 @@ int vfm_map_add(char *id, char *name_chain)
180184
break;
181185
if (*token == '\0')
182186
continue;
183-
memcpy(p->name[p->vfm_map_size], token, strlen(token));
187+
if (strlen(token) >= sizeof(p->name[p->vfm_map_size])) {
188+
memcpy(p->name[p->vfm_map_size], token,
189+
sizeof(p->name[p->vfm_map_size]));
190+
p->name[p->vfm_map_size][
191+
sizeof(p->name[p->vfm_map_size])-1] = '\0';
192+
} else
193+
memcpy(p->name[p->vfm_map_size], token, strlen(token));
184194
p->vfm_map_size++;
185195
} while (token && cnt--);
186196

drivers/amlogic/media/video_sink/video.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -7884,7 +7884,13 @@ static ssize_t video_filename_store(struct class *cla,
78847884
{
78857885
size_t r;
78867886

7887-
r = sscanf(buf, "%s", file_name);
7887+
/* check input buf to mitigate buffer overflow issue */
7888+
if (strlen(buf) >= sizeof(file_name)) {
7889+
memcpy(file_name, buf, sizeof(file_name));
7890+
file_name[sizeof(file_name)-1] = '\0';
7891+
r = 1;
7892+
} else
7893+
r = sscanf(buf, "%s", file_name);
78887894
if (r != 1)
78897895
return -EINVAL;
78907896

drivers/amlogic/unifykey/unifykey.c

+35-12
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,23 @@ static long unifykey_unlocked_ioctl(struct file *file,
731731
unsigned int cmd,
732732
unsigned long arg)
733733
{
734+
void __user *argp = (void __user *)arg;
735+
734736
switch (cmd) {
735737
case KEYUNIFY_ATTACH:
736738
{
737-
struct key_item_t *appitem;
739+
struct key_item_t appitem;
738740
char initvalue[KEY_UNIFY_NAME_LEN];
739741
int ret;
740742

741-
appitem = (struct key_item_t *)arg;
742-
memcpy(initvalue, appitem->name, KEY_UNIFY_NAME_LEN);
743+
ret = copy_from_user(&appitem, argp, sizeof(appitem));
744+
if (ret != 0) {
745+
pr_err("%s:%d,copy_from_user fail\n",
746+
__func__, __LINE__);
747+
return ret;
748+
}
749+
//appitem = (struct key_item_t *)arg;
750+
memcpy(initvalue, appitem.name, KEY_UNIFY_NAME_LEN);
743751
ret = key_unify_init(initvalue, KEY_UNIFY_NAME_LEN);
744752
if (ret < 0) {
745753
pr_err("%s:%d,key unify init fail\n",
@@ -754,13 +762,20 @@ static long unifykey_unlocked_ioctl(struct file *file,
754762
unsigned int index, reallen;
755763
unsigned int keypermit, keystate;
756764
struct key_item_t *kkey;
757-
struct key_item_info_t *key_item_info;
765+
struct key_item_info_t key_item_info;
758766
char *keyname;
759767
int ret;
760768

761-
key_item_info = (struct key_item_info_t *)arg;
762-
index = key_item_info->id;
763-
keyname = key_item_info->name;
769+
ret = copy_from_user(&key_item_info,
770+
argp, sizeof(key_item_info));
771+
if (ret != 0) {
772+
pr_err("%s:%d,copy_from_user fail\n",
773+
__func__, __LINE__);
774+
return ret;
775+
}
776+
//key_item_info = (struct key_item_info_t *)arg;
777+
index = key_item_info.id;
778+
keyname = key_item_info.name;
764779
if (strlen(keyname))
765780
kkey = unifykey_find_item_by_name(keyname);
766781
else
@@ -780,10 +795,10 @@ static long unifykey_unlocked_ioctl(struct file *file,
780795
__func__, __LINE__);
781796
return -EFAULT;
782797
}
783-
key_item_info->permit = keypermit;
784-
key_item_info->flag = keystate;
785-
key_item_info->id = kkey->id;
786-
strncpy(key_item_info->name,
798+
key_item_info.permit = keypermit;
799+
key_item_info.flag = keystate;
800+
key_item_info.id = kkey->id;
801+
strncpy(key_item_info.name,
787802
kkey->name, strlen(kkey->name));
788803
ret = key_unify_size(kkey->name, &reallen);
789804
if (ret < 0) {
@@ -792,7 +807,15 @@ static long unifykey_unlocked_ioctl(struct file *file,
792807
return -EFAULT;
793808
}
794809
/* set key info */
795-
key_item_info->size = reallen;
810+
key_item_info.size = reallen;
811+
812+
ret = copy_to_user(argp,
813+
&key_item_info, sizeof(key_item_info));
814+
if (ret != 0) {
815+
pr_err("%s:%d,copy_to_user fail\n",
816+
__func__, __LINE__);
817+
return ret;
818+
}
796819

797820
return 0;
798821
}

0 commit comments

Comments
 (0)