Skip to content

Commit b9b7429

Browse files
committed
pppd: Add checks to avoid out-of-bounds writes to inpacket_buf and outpacket_buf
In ipcp_reqci(), there is code that appends a CI_ADDR option to the list of options being returned as a Configure-Nak. Add a check to this code to ensure that there is sufficient space to append the option, so that a malicious peer can't cause the code to write past the end of inpacket_buf (which is what 'inp' points to). In fsm_sdata(), the code that trims the length of the outgoing packet to the peer's MRU could potentially result in the length being greater than 1500, causing the following code to write beyond the end of the outpacket_buf array if the peer has negotiated an MRU larger than 1500. To prevent this, limit the length to 1500 or the peer's MRU, whichever is smaller. These issues were found by Sebastian Eisenreich-Dietz (CyberDanube) in cooperation with A&R TECH. Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
1 parent a9fe706 commit b9b7429

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

pppd/fsm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,13 @@ void
762762
fsm_sdata(fsm *f, int code, int id, u_char *data, int datalen)
763763
{
764764
u_char *outp;
765-
int outlen;
765+
int outlen, mtu;
766766

767767
/* Adjust length to be smaller than MTU */
768768
outp = outpacket_buf;
769-
if (datalen > peer_mru[f->unit] - HEADERLEN)
770-
datalen = peer_mru[f->unit] - HEADERLEN;
769+
mtu = MIN(peer_mru[f->unit], PPP_MRU) - HEADERLEN;
770+
if (datalen > mtu)
771+
datalen = mtu;
771772
if (datalen && data != outp + PPP_HDRLEN + HEADERLEN)
772773
BCOPY(data, outp + PPP_HDRLEN + HEADERLEN, datalen);
773774
outlen = datalen + HEADERLEN;

pppd/ipcp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,13 +1709,14 @@ ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree)
17091709
/*
17101710
* If we aren't rejecting this packet, and we want to negotiate
17111711
* their address, and they didn't send their address, then we
1712-
* send a NAK with a CI_ADDR option appended. We assume the
1712+
* send a NAK with a CI_ADDR option appended. We check that the
17131713
* input buffer is long enough that we can append the extra
17141714
* option safely.
17151715
*/
17161716
if (rc != CONFREJ && !ho->neg_addr && !ho->old_addrs &&
17171717
wo->req_addr && !reject_if_disagree &&
1718-
((wo->hisaddr && !wo->accept_remote) || !noremoteip)) {
1718+
((wo->hisaddr && !wo->accept_remote) || !noremoteip) &&
1719+
(rc == CONFACK || ucp + CILEN_ADDR <= inp + PPP_MRU - HEADERLEN)) {
17191720
if (rc == CONFACK) {
17201721
rc = CONFNAK;
17211722
ucp = inp; /* reset pointer */

0 commit comments

Comments
 (0)