semop()/semtimedop() sembuf argument printing in strace

Jakub Bogusz qboosh at pld-linux.org
Wed Oct 7 20:25:10 UTC 2009


On Mon, Oct 05, 2009 at 07:39:40PM +0400, Dmitry V. Levin wrote:
> Hi,
> 
> On Wed, Sep 30, 2009 at 05:59:07PM +0200, Jakub Bogusz wrote:
> > 
> > the attached patch adds pretty printing of sembuf argument and flags to
> > semop() and semtimedop() syscalls.
> 
> Thank you for the patch.  See my comments below.
> 
> > --- strace-4.5.18/ipc.c.orig	2007-01-15 21:25:52.000000000 +0100
> > +++ strace-4.5.18/ipc.c	2009-09-30 17:48:38.080610937 +0200
> [...]
> > @@ -273,14 +279,34 @@
> >  int sys_semop(tcp)
> >  struct tcb *tcp;
> >  {
> > +	int i;
> > +
> >  	if (entering(tcp)) {
> >  		tprintf("%lu", tcp->u_arg[0]);
> >  		if (indirect_ipccall(tcp)) {
> > -			tprintf(", %#lx", tcp->u_arg[3]);
> > -			tprintf(", %lu", tcp->u_arg[1]);
> > +			tprintf(", %#lx {", tcp->u_arg[3]);
> > +			for(i = 0; i < tcp->u_arg[1]; i++) {
> > +				struct sembuf sb;
> > +				umove(tcp, tcp->u_arg[3]+i*sizeof(struct sembuf), &sb);
> 
> umove() return code usually have to be taken into account, especially
> when umove() arguments come from user input.

OK, updated patch attached.

BTW, there are unchecked umoves in already existing sys_msgsnd() and
sys_msgrcv()...


Regards,

-- 
Jakub Bogusz    http://qboosh.pl/
-------------- next part --------------
--- strace-4.5.18/ipc.c.orig	2007-01-15 21:25:52.000000000 +0100
+++ strace-4.5.18/ipc.c	2009-10-07 22:11:24.392613451 +0200
@@ -152,6 +152,12 @@
 	{ 0,		NULL		},
 };
 
+static const struct xlat semop_flags[] = {
+	{ SEM_UNDO,	"SEM_UNDO"	},
+	{ IPC_NOWAIT,	"IPC_NOWAIT"	},
+	{ 0,		NULL		},
+};
+
 int sys_msgget(tcp)
 struct tcb *tcp;
 {
@@ -273,14 +279,40 @@
 int sys_semop(tcp)
 struct tcb *tcp;
 {
+	int i;
+
 	if (entering(tcp)) {
 		tprintf("%lu", tcp->u_arg[0]);
 		if (indirect_ipccall(tcp)) {
-			tprintf(", %#lx", tcp->u_arg[3]);
-			tprintf(", %lu", tcp->u_arg[1]);
+			tprintf(", %#lx {", tcp->u_arg[3]);
+			for(i = 0; i < tcp->u_arg[1]; i++) {
+				struct sembuf sb;
+				if(i != 0)
+					tprintf(", ");
+				if (umove(tcp, tcp->u_arg[3]+i*sizeof(struct sembuf), &sb) < 0)
+					tprintf("{???}");
+				else {
+					tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
+					printflags(semop_flags, sb.sem_flg, "SEM_???");
+					tprintf("}");
+				}
+			}
+			tprintf("}, %lu", tcp->u_arg[1]);
 		} else {
-			tprintf(", %#lx", tcp->u_arg[1]);
-			tprintf(", %lu", tcp->u_arg[2]);
+			tprintf(", %#lx {", tcp->u_arg[1]);
+			for(i = 0; i < tcp->u_arg[2]; i++) {
+				struct sembuf sb;
+				if(i != 0)
+					tprintf(", ");
+				if(umove(tcp, tcp->u_arg[1]+i*sizeof(struct sembuf), &sb) < 0)
+					tprintf("{???}");
+				else {
+					tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
+					printflags(semop_flags, sb.sem_flg, "SEM_???");
+					tprintf("}");
+				}
+			}
+			tprintf("}, %lu", tcp->u_arg[2]);
 		}
 	}
 	return 0;
@@ -290,15 +322,41 @@
 int sys_semtimedop(tcp)
 struct tcb *tcp;
 {
+	int i;
+
 	if (entering(tcp)) {
 		tprintf("%lu", tcp->u_arg[0]);
 		if (indirect_ipccall(tcp)) {
-			tprintf(", %#lx", tcp->u_arg[3]);
-			tprintf(", %lu, ", tcp->u_arg[1]);
+			tprintf(", %#lx {", tcp->u_arg[3]);
+			for(i = 0; i < tcp->u_arg[1]; i++) {
+				struct sembuf sb;
+				if(i != 0)
+					tprintf(", ");
+				if(umove(tcp, tcp->u_arg[3]+i*sizeof(struct sembuf), &sb) < 0)
+					tprintf("{???}");
+				else {
+					tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
+					printflags(semop_flags, sb.sem_flg, "SEM_???");
+					tprintf("}");
+				}
+			}
+			tprintf("}, %lu, ", tcp->u_arg[1]);
 			printtv(tcp, tcp->u_arg[5]);
 		} else {
-			tprintf(", %#lx", tcp->u_arg[1]);
-			tprintf(", %lu, ", tcp->u_arg[2]);
+			tprintf(", %#lx {", tcp->u_arg[1]);
+			for(i = 0; i < tcp->u_arg[2]; i++) {
+				struct sembuf sb;
+				if(i != 0)
+					tprintf(", ");
+				if(umove(tcp, tcp->u_arg[1]+i*sizeof(struct sembuf), &sb) < 0)
+					tprintf("{???}");
+				else {
+					tprintf("{%u, %d, ", sb.sem_num, sb.sem_op);
+					printflags(semop_flags, sb.sem_flg, "SEM_???");
+					tprintf("}");
+				}
+			}
+			tprintf("}, %lu, ", tcp->u_arg[2]);
 			printtv(tcp, tcp->u_arg[3]);
 		}
 	}


More information about the Strace-devel mailing list