Skip to content

Commit 8ea273b

Browse files
Andrew Boiecarlescufi
authored andcommitted
net: socketpair: fix user mode access
The socketpair file descriptor context objects are heap allocated and not drawn from a static pool. Register these as kernel objects when we create them if user mode is enabled. Signed-off-by: Andrew Boie <[email protected]>
1 parent be919d3 commit 8ea273b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

subsys/net/lib/sockets/socketpair.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ static void spair_delete(struct spair *spair)
193193

194194
/* ensure no private information is released to the memory pool */
195195
memset(spair, 0, sizeof(*spair));
196-
196+
#ifdef CONFIG_USERSPACE
197+
k_object_free(spair);
198+
#else
197199
k_free(spair);
200+
#endif
198201

199202
if (remote != NULL && have_remote_sem) {
200203
k_sem_give(&remote->sem);
@@ -214,7 +217,18 @@ static struct spair *spair_new(void)
214217
{
215218
struct spair *spair;
216219

220+
#ifdef CONFIG_USERSPACE
221+
struct z_object *zo = z_dynamic_object_create(sizeof(*spair));
222+
223+
if (zo == NULL) {
224+
spair = NULL;
225+
} else {
226+
spair = zo->name;
227+
zo->type = K_OBJ_NET_SOCKET;
228+
}
229+
#else
217230
spair = k_malloc(sizeof(*spair));
231+
#endif
218232
if (spair == NULL) {
219233
errno = ENOMEM;
220234
goto out;

0 commit comments

Comments
 (0)