summaryrefslogtreecommitdiff
path: root/src/lib/efl_wl/efl_wl.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2017-08-04 16:11:00 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2017-08-04 16:10:39 -0400
commit70c118fab67375b9c14a8a51521dfaca72c1d215 (patch)
tree7b1f89e9f11602d712637a82ee75249c37ac46eb /src/lib/efl_wl/efl_wl.c
parent99b60390f49837f91fc9dcd532cdec4b2aaf3920 (diff)
efl-wl: block connection attempts from unmanaged clients
I guess posting an oom error is security @fix
Diffstat (limited to 'src/lib/efl_wl/efl_wl.c')
-rw-r--r--src/lib/efl_wl/efl_wl.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/efl_wl/efl_wl.c b/src/lib/efl_wl/efl_wl.c
index 691ae69beb..3b8729c8fe 100644
--- a/src/lib/efl_wl/efl_wl.c
+++ b/src/lib/efl_wl/efl_wl.c
@@ -118,6 +118,9 @@ typedef struct Comp
118 Evas_Object *clip; 118 Evas_Object *clip;
119 Evas_Object *events; 119 Evas_Object *events;
120 120
121 Eina_Hash *exes;
122 Ecore_Event_Handler *exe_handler;
123
121 Eina_Inlist *surfaces; 124 Eina_Inlist *surfaces;
122 unsigned int surfaces_count; 125 unsigned int surfaces_count;
123 Eina_Hash *client_surfaces; 126 Eina_Hash *client_surfaces;
@@ -427,6 +430,22 @@ array_clear(Eina_Array **arr)
427 *arr = NULL; 430 *arr = NULL;
428} 431}
429 432
433static inline Eina_Bool
434client_allowed_check(Comp *c, struct wl_client *client)
435{
436 pid_t p;
437 int32_t pid;
438 Eina_Bool err;
439
440 wl_client_get_credentials(client, &p, NULL, NULL);
441 if (p == getpid()) return EINA_TRUE;
442 pid = p;
443 err = (!c->exes) || !eina_hash_find(c->exes, &pid);
444 if (err)
445 wl_client_post_no_memory(client);
446 return !err;
447}
448
430static inline void 449static inline void
431comp_data_device_source_reader_clear(Comp_Data_Device_Source *ds) 450comp_data_device_source_reader_clear(Comp_Data_Device_Source *ds)
432{ 451{
@@ -2450,6 +2469,8 @@ comp_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2450{ 2469{
2451 struct wl_resource *res; 2470 struct wl_resource *res;
2452 2471
2472 if (!client_allowed_check(data, client)) return;
2473
2453 res = wl_resource_create(client, &wl_compositor_interface, version, id); 2474 res = wl_resource_create(client, &wl_compositor_interface, version, id);
2454 wl_resource_set_implementation(res, &comp_interface, data, NULL); 2475 wl_resource_set_implementation(res, &comp_interface, data, NULL);
2455} 2476}
@@ -2595,6 +2616,7 @@ subcomp_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id
2595{ 2616{
2596 struct wl_resource *res; 2617 struct wl_resource *res;
2597 2618
2619 if (!client_allowed_check(data, client)) return;
2598 res = wl_resource_create(client, &wl_subcompositor_interface, version, id); 2620 res = wl_resource_create(client, &wl_subcompositor_interface, version, id);
2599 wl_resource_set_implementation(res, &subcomp_interface, data, NULL); 2621 wl_resource_set_implementation(res, &subcomp_interface, data, NULL);
2600} 2622}
@@ -2932,6 +2954,7 @@ data_device_manager_bind(struct wl_client *client, void *data, uint32_t version,
2932{ 2954{
2933 struct wl_resource *res; 2955 struct wl_resource *res;
2934 2956
2957 if (!client_allowed_check(data, client)) return;
2935 res = wl_resource_create(client, &wl_data_device_manager_interface, MIN(3, version), id); 2958 res = wl_resource_create(client, &wl_data_device_manager_interface, MIN(3, version), id);
2936 wl_resource_set_implementation(res, &data_device_manager_interface, data, NULL); 2959 wl_resource_set_implementation(res, &data_device_manager_interface, data, NULL);
2937} 2960}
@@ -2980,6 +3003,7 @@ output_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2980 Comp_Surface *cs; 3003 Comp_Surface *cs;
2981 struct wl_resource *res; 3004 struct wl_resource *res;
2982 3005
3006 if (!client_allowed_check(data, client)) return;
2983 res = wl_resource_create(client, &wl_output_interface, version, id); 3007 res = wl_resource_create(client, &wl_output_interface, version, id);
2984 c->output_resources = eina_list_append(c->output_resources, res); 3008 c->output_resources = eina_list_append(c->output_resources, res);
2985 wl_resource_set_implementation(res, NULL, data, output_unbind); 3009 wl_resource_set_implementation(res, NULL, data, output_unbind);
@@ -3403,6 +3427,7 @@ shell_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3403 struct wl_resource *res; 3427 struct wl_resource *res;
3404 Shell_Data *sd; 3428 Shell_Data *sd;
3405 3429
3430 if (!client_allowed_check(data, client)) return;
3406 sd = calloc(1, sizeof(Shell_Data)); 3431 sd = calloc(1, sizeof(Shell_Data));
3407 sd->c = c; 3432 sd->c = c;
3408 c->shells = eina_inlist_append(c->shells, EINA_INLIST_GET(sd)); 3433 c->shells = eina_inlist_append(c->shells, EINA_INLIST_GET(sd));
@@ -3750,6 +3775,7 @@ seat_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
3750 struct wl_resource *res; 3775 struct wl_resource *res;
3751 Comp_Seat *s = data; 3776 Comp_Seat *s = data;
3752 3777
3778 if (!client_allowed_check(s->c, client)) return;
3753 res = wl_resource_create(client, &wl_seat_interface, version, id); 3779 res = wl_resource_create(client, &wl_seat_interface, version, id);
3754 s->resources = eina_list_append(s->resources, res); 3780 s->resources = eina_list_append(s->resources, res);
3755 if (s->c->active_surface) 3781 if (s->c->active_surface)
@@ -4962,6 +4988,8 @@ comp_smart_del(Evas_Object *obj)
4962 evas_event_callback_del_full(c->evas, EVAS_CALLBACK_RENDER_PRE, (Evas_Event_Cb)comp_render_pre, c); 4988 evas_event_callback_del_full(c->evas, EVAS_CALLBACK_RENDER_PRE, (Evas_Event_Cb)comp_render_pre, c);
4963 evas_event_callback_del_full(c->evas, EVAS_CALLBACK_RENDER_POST, (Evas_Event_Cb)comp_render_post, c); 4989 evas_event_callback_del_full(c->evas, EVAS_CALLBACK_RENDER_POST, (Evas_Event_Cb)comp_render_post, c);
4964 efl_event_callback_array_del(c->evas, comp_device_cbs(), c); 4990 efl_event_callback_array_del(c->evas, comp_device_cbs(), c);
4991 ecore_event_handler_del(c->exe_handler);
4992 eina_hash_free(c->exes);
4965 comps = eina_list_remove(comps, c); 4993 comps = eina_list_remove(comps, c);
4966 free(c); 4994 free(c);
4967 if (!comps) 4995 if (!comps)
@@ -5093,6 +5121,18 @@ comp_smart_init(void)
5093 } 5121 }
5094} 5122}
5095 5123
5124static Eina_Bool
5125exe_event_del(void *data, int t EINA_UNUSED, Ecore_Exe_Event_Del *ev)
5126{
5127 Comp *c = data;
5128 int32_t pid = ev->pid;
5129
5130 if (!eina_streq(ecore_exe_tag_get(ev->exe), "__efl_wl")) return ECORE_CALLBACK_RENEW;
5131
5132 eina_hash_del_by_key(c->exes, &pid);
5133 return ECORE_CALLBACK_RENEW;
5134}
5135
5096# ifdef __GNUC__ 5136# ifdef __GNUC__
5097# if __GNUC__ >= 4 5137# if __GNUC__ >= 4
5098__attribute__ ((visibility("hidden"))) 5138__attribute__ ((visibility("hidden")))
@@ -5153,6 +5193,11 @@ efl_wl_run(Evas_Object *obj, const char *cmd)
5153 5193
5154 if (!eina_streq(evas_object_type_get(obj), "comp")) abort(); 5194 if (!eina_streq(evas_object_type_get(obj), "comp")) abort();
5155 c = evas_object_smart_data_get(obj); 5195 c = evas_object_smart_data_get(obj);
5196 if (!c->exes)
5197 c->exes = eina_hash_int32_new(NULL);
5198 if (!c->exe_handler)
5199 c->exe_handler =
5200 ecore_event_handler_add(ECORE_EXE_EVENT_DEL, (Ecore_Event_Handler_Cb)exe_event_del, c);
5156 disp = getenv("DISPLAY"); 5201 disp = getenv("DISPLAY");
5157 if (disp) disp = strdup(disp); 5202 if (disp) disp = strdup(disp);
5158 unsetenv("DISPLAY"); 5203 unsetenv("DISPLAY");
@@ -5177,6 +5222,12 @@ efl_wl_run(Evas_Object *obj, const char *cmd)
5177 } 5222 }
5178 free(env); 5223 free(env);
5179 free(disp); 5224 free(disp);
5225 if (exe)
5226 {
5227 int32_t pid = ecore_exe_pid_get(exe);
5228 ecore_exe_tag_set(exe, "__efl_wl");
5229 eina_hash_add(c->exes, &pid, exe);
5230 }
5180 return exe; 5231 return exe;
5181} 5232}
5182 5233