Fwd: [[email protected]: sredird vulnerabilities]
sercd seems to have the same issues.
---------- Forwarded Message ----------
Subject: [[email protected]: sredird vulnerabilities]
Date: Sat, 31 Jul 2004 20:54
From: Max Vozeler <[email protected]>
To: [email protected]
Hi Russell,
my mail server has problems with connections to the MX of your coker.com.au domain (smtp.sws.net.au[61.95.69.6]), yielding 100% packet loss, so I'm resending this to @d.o.
(Strangely the host is reachable from a different subnet. Have you blackholed 83.137.99.0/24 or broader by any chance?)
Greets,
Max
----- Forwarded message from Max Vozeler <[email protected]> -----
From: Max Vozeler <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: sredird vulnerabilities
Date: Fri, 30 Jul 2004 14:52:24 +0200
User-Agent: Mutt/1.5.6+20040523i
Hi Russell,
[ CCing Security Team for vulns in the testing version ]
there are two bugs in sredird that can introduce security problems, potentially leading to a remote root compromise. Affected in Debian is the testing/unstable sredird 2.2.1-1.
Feel free to forward this info as you like. Unless you want me to delay disclosure to the BTS for some reason, or the fixed package has already entered testing by then, I'll file +security bugs in 10 days or so.
There are two bugs:
LogMsg() format string bug
--------------------------
sredird-2.2.1/sredird.c:
458 /* Generic log function with log level control. Uses the same log
levels 459 of the syslog(3) system call */
460 void LogMsg(int LogLevel, const char * const Msg)
461 {
462 if (LogLevel <= MaxLogLevel)
463 syslog(LogLevel,Msg);
464 }
The log buffer in Msg is given to syslog() as format control string. This can lead to overwriting of any memory locations in case the content of Msg is controllable by an attacker. There is in fact one such place where the input to LogMsg() is constructed from data as supplied by the client:
1365 /* Handling of COM Port Control specific commands */
1366 void HandleCPCCommand(BufferType *SockB, int PortFd, unsigned char *
Command, size_t CSize) 1367 {
1368 char LogStr[TmpStrLen];
1369 char SigStr[TmpStrLen];
..
1376 /* Check wich command has been requested */
1377 switch (Command[3])
1378 {
1379 /* Signature */
1380 case TNCAS_SIGNATURE:
..
1391 /* Received client signature */ 1392 strncpy(SigStr,(char *) &Command[4],CSize - 6); 1393 sprintf(LogStr,"Received client signature: %s",SigStr); 1394 LogMsg(LOG_INFO,LogStr);
The canonical fix would be to add an explicit "%s" format string to the syslog() call in LogMsg(). (See attached sredird-log-fmt.diff)
HandleCPCCommand() stack overflow
---------------------------------
Affected is the last chunk of code in HandleCPCCommand() shown above. LogStr is not large enough to store the largest possible output from sprintf(). CSize is limited to 254 by the caller, minus 6, makes a max. SigStr length of 248 bytes. After the sprintf() with 27 or so non-format characters, the output can grow to
27 + 248 = 275 bytes
.. which is too much for LogStr[255], by 20 bytes or so. This may be enough to overwrite precious stuff on the stack like saved eip depending on stack layout.
Why not just replace it with snprintf()? This would solve this problem for good. See attached patch sredird-hcpcc-bof.diff for example.
(There should be a LogStr[sizeof(LogStr)-1] = 0; after the snprintf in the patch which I forgot to add)
Cheers,
Max
--
308E81E7B97963BCA0E6ED889D5BD511B7CDA2DC
sredird.c renamed from sredird.c.orig +1 -1
@@ -460,7 +460,7 @@void LogMsg (int LogLevel,const char *const Msg) {if (LogLevel <= MaxLogLevel) -syslog (LogLevel,Msg); +syslog (LogLevel,"%s" ,Msg); }/* Try to lock the file given in LockFile as pid LockPid using the classical
sredird.c renamed from sredird.c.orig +1 -1
@@ -1390,7 +1390,7 @@ {/* Received client signature */ strncpy (SigStr,(char *) &Command[4 ],CSize -6 ); -sprintf (LogStr,"Received client signature: %s" ,SigStr); + snprintf(LogStr,sizeof(LogStr)-1,"Received client signature: %s",SigStr); LogMsg(LOG_INFO,LogStr); }break ;
----- End forwarded message -----
--
308E81E7B97963BCA0E6ED889D5BD511B7CDA2DC
-------------------------------------------------------
Signature · 4 lines
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark http://www.coker.com.au/postal/ Postal SMTP/POP benchmark http://www.coker.com.au/~russell/ My home page
Quoted 3 lines
LogMsg()format string bug
--------------------------
...
Quoted 2 lines
The canonical fix would be to add an explicit "%s" format string to the
syslog()call inLogMsg(). (See attached sredird-log-fmt.diff)
Thanks for pointing this out.
Quoted 7 lines
HandleCPCCommand()stack overflow
---------------------------------Affected is the last chunk of code in
HandleCPCCommand()shown above. LogStr is not large enough to store the largest possible output fromsprintf(). CSize is limited to 254 by the caller, minus 6, makes a max. SigStr length of 248 bytes.
Since CSize is a size_t, it can be larger than 254. I'd rather not depend on the caller calling with max 254. Therefore, I've added an explicit check to make sure we are not copying more than SigStr can hold:
strncpy(SigStr, (char *) &Command[4],
MAX(CSize - 6, sizeof(SigStr) - 1));
Quoted 11 lines
After the
sprintf()with 27 or so non-format
characters, the output can grow to27 + 248 = 275 bytes
.. which is too much for LogStr[255], by 20 bytes or so. This may be enough to overwrite precious stuff on the stack like saved eip depending on stack layout.
Why not just replace it with
snprintf()? This would solve this problem for good.
Good idea. This is the patch I've committed to the sercd CVS:
sercd.c 1 Aug 2004 15:36:04 -0000 renamed from sercd.c 1 Aug 2004 15:03:17 -0000 1.8 +0 -0
@@ -144,6 +144,11 @@ /* Default modem state polling in milliseconds (100 msec should be
enough) */
#define ModemStatePolling 100
+/* macros */
+#ifndef MAX
+#define MAX(x,y) (((x) > (y)) ? (x) : (y))
+#endif
+
/* Standard boolean definition */
typedef enum
{ False, True } Boolean;
@@ -420,7 +425,7 @@
LogMsg(int LogLevel, const char *const Msg)
{
if (LogLevel <= MaxLogLevel)
- syslog(LogLevel, Msg);
+ syslog(LogLevel, "%s", Msg);
}
/* Try to lock the file given in LockFile as pid LockPid using the
classical
@@ -1339,8 +1344,11 @@
}
else {
/* Received client signature */
- strncpy(SigStr, (char *) &Command[4], CSize - 6);
- sprintf(LogStr, "Received client signature: %s", SigStr);
+ strncpy(SigStr, (char *) &Command[4],
+ MAX(CSize - 6, sizeof(SigStr) - 1));
+ snprintf(LogStr, sizeof(LogStr) - 1,
+ "Received client signature: %s", SigStr);
+ LogStr[sizeof(LogStr) - 1] = '\0';
LogMsg(LOG_INFO, LogStr);
}
break;As soon as I've been able to test-run the latest CVS, I'll make a new release. This should happen later today or tomorrow.
Signature · 9 lines
Peter Åstrand Chief Developer Cendio www.thinlinc.com Teknikringen 3 www.cendio.se 583 30 Linköping Phone: +46-13-21 46 00 - To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Peter Astrand
As soon as I've been able to test-run the latest CVS, I'll make a new release. This should happen later today or tomorrow.
sercd 2.3.1 has now been released.
Signature · 9 lines
Peter Åstrand Chief Developer Cendio www.thinlinc.com Teknikringen 3 www.cendio.se 583 30 Linköping Phone: +46-13-21 46 00 - To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html