NetBSD Problem Report #7386

Received: (qmail 16230 invoked from network); 14 Apr 1999 17:56:15 -0000
Message-Id: <199904141755.CAA15509.vifam@futatuki.fureai.or.jp>
Date: Thu, 15 Apr 1999 02:55:18 +0900 (JST)
From: futatuki@fureai.or.jp
Reply-To: futatuki@fureai.or.jp
To: gnats-bugs@NetBSD.org
Subject: msgrcv(3) will cause buffer over-run in a certain condition 
X-Send-Pr-Version: 3.2

>Number:         7386
>Category:       kern
>Synopsis:       msgrcv(3) will cause buffer over-run in a certain condition
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 14 11:05:00 +0000 1999
>Closed-Date:    Wed Apr 21 02:31:15 +0000 1999
>Last-Modified:  Wed Apr 21 02:32:05 +0000 1999
>Originator:     Yasuhito FUTATSUKI
>Release:        FreeBSD 2.2.7-RELEASE i386
>Organization:
>Environment:

Those NetBSD system which uses 

/*      $NetBSD: sysv_msg.c,v 1.24 1998/10/21 22:24:28 tron Exp $       */

version of src/sys/kern/sysv_msg.c

>Description:

msgrcv(msqid, msgp, msgsz, msgtyp, msgflg) will copy larger size of
message data than specified by msgsz if

  1. msgsz is larger than `msgssz', and
  2. msgsz is not multiples of `msgssz'

where msgssz is the size of message segment in bytes.

I found this problem on FreeBSD, but the code for system V message
handling derived from NetBSD, so I read the code for this feature
and found there is the problem on NetBSD also.

>How-To-Repeat:

Assume msgssz is 8, message que of id msgid is accessable,
a message of type msgtype and size 20 bytes was sent, then

  struct {
    long mtype;
    char mtext[20];
    long some_data;
  } mymsg;

  msgrcv(msqid, (void*)mymsg, 20, msgtype, 0);

will crash mymsg.some_data .

>Fix:

Apply following patch to src/sys/kern/sysv_msg.c :

BEGIN --- cut here --- --- cut here --- --- cut here ---
*** sysv_msg.c.dist	Wed Apr 14 16:49:14 1999
--- sysv_msg.c	Wed Apr 14 16:57:25 1999
***************
*** 847,856 ****
  	for (len = 0; len < msgsz; len += msginfo.msgssz) {
  		size_t tlen;

! 		if (msgsz > msginfo.msgssz)
  			tlen = msginfo.msgssz;
  		else
! 			tlen = msgsz;
  		if (next <= -1)
  			panic("next too low #3");
  		if (next >= msginfo.msgseg)
--- 847,856 ----
  	for (len = 0; len < msgsz; len += msginfo.msgssz) {
  		size_t tlen;

! 		if (msgsz - len > msginfo.msgssz)
  			tlen = msginfo.msgssz;
  		else
! 			tlen = msgsz - len;
  		if (next <= -1)
  			panic("next too low #3");
  		if (next >= msginfo.msgseg)
END --- cut here --- --- cut here --- --- cut here ---
>Release-Note:
>Audit-Trail:

From: Yasuhito FUTATSUKI <futatuki@fureai.or.jp>
To: gnats-bugs@netbsd.org
Cc:  Subject: kern/7386
Date: Thu, 15 Apr 1999 15:59:57 +0900

 I'm sorry, let me correct a typo.

 > > How-To-Repeat:
 >
 > Assume msgssz is 8, message que of id msgid is accessable,
 > a message of type msgtype and size 20 bytes was sent, then
 > 
 >   struct {
 >     long mtype;
 >     char mtext[20];
 >     long some_data;
 >   } mymsg;
 > 
 > 
 >   msgrcv(msqid, (void*)mymsg, 20, msgtype, 0);
                          ^^^^^

     msgrcv(msqid, (void*)&mymsg, 20, msgtype, 0);                           

 >
 > will crash mymsg.some_data .

   -- Yasuhito FUTATSUKI

From: futatuki@fureai.or.jp (Yasuhito FUTATSUKI)
To: gnats-bugs@netbsd.org
Cc:  Subject: kern/7386
Date: Mon, 19 Apr 1999 15:50:41 +0900 (JST)

 OpenBSD had the same probrem, so I sent probrem report and
 patch was applied (OpenBSD GNATS DB kernel/803).

 Cf. Probrem report on FreeBSD is ID kern/10765. It is
   still left in state `open'.
State-Changed-From-To: open->closed 
State-Changed-By: mrg 
State-Changed-When: Tue Apr 20 19:31:15 PDT 1999 
State-Changed-Why:  
i have applied this patch. thanks. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.