Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 473d5d2 in mainline


Ignore:
Timestamp:
2011-05-19T16:44:47Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
bcaca55
Parents:
9c757820
Message:

add magic value to THE structure for better stack/memory corruption detection
rename (security) contexts to containers (a slightly less overloaded term within SPARTAN kernel)

Location:
kernel/generic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/arch.h

    r9c757820 r473d5d2  
    4141#include <mm/as.h>
    4242
    43 #define DEFAULT_CONTEXT  0
     43/*
     44 * THE is not an abbreviation, but the English definite article written in
     45 * capital letters. It means the current pointer to something, e.g. thread,
     46 * processor or address space. Kind reader of this comment shall appreciate
     47 * the wit of constructs like THE->thread and similar.
     48 */
     49#define THE  ((the_t * )(get_stack_base()))
    4450
    4551#define CPU                  THE->cpu
     
    4753#define TASK                 THE->task
    4854#define AS                   THE->as
    49 #define CONTEXT              (THE->task ? THE->task->context : DEFAULT_CONTEXT)
    5055#define PREEMPTION_DISABLED  THE->preemption_disabled
     56#define MAGIC                UINT32_C(0xfacefeed)
    5157
    52 #define context_check(ctx1, ctx2)  ((ctx1) == (ctx2))
     58#define container_check(ctn1, ctn2)  ((ctn1) == (ctn2))
     59
     60#define DEFAULT_CONTAINER  0
     61#define CONTAINER \
     62        ((THE->task) ? (THE->task->container) : (DEFAULT_CONTAINER))
    5363
    5464/**
     
    6373        cpu_t *cpu;                  /**< Executing cpu. */
    6474        as_t *as;                    /**< Current address space. */
     75        uint32_t magic;              /**< Magic value */
    6576} the_t;
    66 
    67 /*
    68  * THE is not an abbreviation, but the English definite article written in
    69  * capital letters. It means the current pointer to something, e.g. thread,
    70  * processor or address space. Kind reader of this comment shall appreciate
    71  * the wit of constructs like THE->thread and similar.
    72  */
    73 #define THE  ((the_t * )(get_stack_base()))
    7477
    7578extern void the_initialize(the_t *);
  • kernel/generic/src/ddi/ddi.c

    r9c757820 r473d5d2  
    224224        task_t *task = task_find_by_id(id);
    225225       
    226         if ((!task) || (!context_check(CONTEXT, task->context))) {
     226        if ((!task) || (!container_check(CONTAINER, task->container))) {
    227227                /*
    228228                 * There is no task with the specified ID
  • kernel/generic/src/debug/panic.c

    r9c757820 r473d5d2  
    9595        printf("\n");
    9696       
    97         printf("THE=%p", THE);
     97        printf("THE=%p: ", THE);
    9898        if (THE != NULL) {
    99                 printf(": pe=%" PRIun " thr=%p task=%p cpu=%p as=%p",
     99                printf("pe=%" PRIun " thr=%p task=%p cpu=%p as=%p magic=%#x\n",
    100100                    THE->preemption_disabled, THE->thread, THE->task,
    101                     THE->cpu, THE->as);
    102         }
    103         printf("\n");
     101                    THE->cpu, THE->as, THE->magic);
     102        } else
     103                printf("invalid\n");
    104104       
    105105        if (istate) {
  • kernel/generic/src/proc/task.c

    r9c757820 r473d5d2  
    190190        str_cpy(task->name, TASK_NAME_BUFLEN, name);
    191191       
    192         task->context = CONTEXT;
     192        task->container = CONTAINER;
    193193        task->capabilities = 0;
    194194        task->ucycles = 0;
     
    211211       
    212212        if ((ipc_phone_0) &&
    213             (context_check(ipc_phone_0->task->context, task->context)))
     213            (container_check(ipc_phone_0->task->container, task->container)))
    214214                ipc_phone_connect(&task->phones[0], ipc_phone_0);
    215215       
     
    584584                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %10p %10p"
    585585                    " %9" PRIu64 "%c %9" PRIu64 "%c\n", task->taskid,
    586                     task->name, task->context, task, task->as,
     586                    task->name, task->container, task, task->as,
    587587                    ucycles, usuffix, kcycles, ksuffix);
    588588#endif
     
    595595        else
    596596                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %18p %18p\n",
    597                     task->taskid, task->name, task->context, task, task->as);
     597                    task->taskid, task->name, task->container, task, task->as);
    598598#endif
    599599       
     
    625625                printf("[id    ] [threads] [calls] [callee\n");
    626626        else
    627                 printf("[id    ] [name        ] [ctx] [address ] [as      ]"
     627                printf("[id    ] [name        ] [ctn] [address ] [as      ]"
    628628                    " [ucycles ] [kcycles ]\n");
    629629#endif
     
    634634                    " [callee\n");
    635635        else
    636                 printf("[id    ] [name        ] [ctx] [address         ]"
     636                printf("[id    ] [name        ] [ctn] [address         ]"
    637637                    " [as              ]\n");
    638638#endif
  • kernel/generic/src/proc/the.c

    r9c757820 r473d5d2  
    5858        the->task = NULL;
    5959        the->as = NULL;
     60        the->magic = MAGIC;
    6061}
    6162
     
    7071NO_TRACE void the_copy(the_t *src, the_t *dst)
    7172{
     73        ASSERT(src->magic == MAGIC);
    7274        *dst = *src;
    7375}
  • kernel/generic/src/security/cap.c

    r9c757820 r473d5d2  
    9292        task_t *task = task_find_by_id(taskid);
    9393       
    94         if ((!task) || (!context_check(CONTEXT, task->context))) {
     94        if ((!task) || (!container_check(CONTAINER, task->container))) {
    9595                irq_spinlock_unlock(&tasks_lock, true);
    9696                return (sysarg_t) ENOENT;
     
    121121       
    122122        task_t *task = task_find_by_id(taskid);
    123         if ((!task) || (!context_check(CONTEXT, task->context))) {
     123        if ((!task) || (!container_check(CONTAINER, task->container))) {
    124124                irq_spinlock_unlock(&tasks_lock, true);
    125125                return (sysarg_t) ENOENT;
Note: See TracChangeset for help on using the changeset viewer.