kernel: kill proc with bogus ipc address
[minix.git] / kernel / system / do_copy.c
blob52b535b74c603f8033fa511f6bc5e4cd5240f48b
1 /* The kernel call implemented in this file:
2 * m_type: SYS_VIRCOPY, SYS_PHYSCOPY
4 * The parameters for this kernel call are:
5 * m5_l1: CP_SRC_ADDR source offset within segment
6 * m5_i1: CP_SRC_ENDPT source process number
7 * m5_l2: CP_DST_ADDR destination offset within segment
8 * m5_i2: CP_DST_ENDPT destination process number
9 * m5_l3: CP_NR_BYTES number of bytes to copy
12 #include "kernel/system.h"
13 #include <minix/type.h>
15 #if (USE_VIRCOPY || USE_PHYSCOPY)
17 /*===========================================================================*
18 * do_copy *
19 *===========================================================================*/
20 int do_copy(struct proc * caller, message * m_ptr)
22 /* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
23 * physical addressing. Although a single handler function is used, there
24 * are two different kernel calls so that permissions can be checked.
26 struct vir_addr vir_addr[2]; /* virtual source and destination address */
27 phys_bytes bytes; /* number of bytes to copy */
28 int i;
30 #if 0
31 if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR &&
32 caller->p_endpoint != RS_PROC_NR && caller->p_endpoint != MEM_PROC_NR &&
33 caller->p_endpoint != VM_PROC_NR)
35 static int first=1;
36 if (first)
38 first= 0;
39 printf(
40 "do_copy: got request from %d (source %d, destination %d)\n",
41 caller->p_endpoint,
42 m_ptr->CP_SRC_ENDPT,
43 m_ptr->CP_DST_ENDPT);
46 #endif
48 /* Dismember the command message. */
49 vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
50 vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
52 vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
53 vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
54 bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
56 /* Now do some checks for both the source and destination virtual address.
57 * This is done once for _SRC_, then once for _DST_.
59 for (i=_SRC_; i<=_DST_; i++) {
60 int p;
61 /* Check if process number was given implictly with SELF and is valid. */
62 if (vir_addr[i].proc_nr_e == SELF)
63 vir_addr[i].proc_nr_e = caller->p_endpoint;
64 if (vir_addr[i].proc_nr_e != NONE) {
65 if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
66 printf("do_copy: %d: %d not ok endpoint\n", i, vir_addr[i].proc_nr_e);
67 return(EINVAL);
72 /* Check for overflow. This would happen for 64K segments and 16-bit
73 * vir_bytes. Especially copying by the PM on do_fork() is affected.
75 if (bytes != (phys_bytes) (vir_bytes) bytes) return(E2BIG);
77 /* Now try to make the actual virtual copy. */
78 return( virtual_copy_vmcheck(caller, &vir_addr[_SRC_],
79 &vir_addr[_DST_], bytes) );
81 #endif /* (USE_VIRCOPY || USE_PHYSCOPY) */