From owner-svn-src-head@freebsd.org Fri Sep 29 15:53:27 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6CBDCE2F8CD; Fri, 29 Sep 2017 15:53:27 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3C5396B29E; Fri, 29 Sep 2017 15:53:27 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8TFrQFZ022221; Fri, 29 Sep 2017 15:53:26 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8TFrQbu022220; Fri, 29 Sep 2017 15:53:26 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201709291553.v8TFrQbu022220@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Fri, 29 Sep 2017 15:53:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324102 - head/sys/netsmb X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/netsmb X-SVN-Commit-Revision: 324102 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Sep 2017 15:53:27 -0000 Author: cem Date: Fri Sep 29 15:53:26 2017 New Revision: 324102 URL: https://svnweb.freebsd.org/changeset/base/324102 Log: netsmb: Fix buggy/racy smb_strdupin() smb_strdupin() tried to roll a copyin() based strlen to allocate a buffer and then blindly copyin that size. Of course, a malicious user program could simultaneously manipulate the buffer, resulting in a non-terminated string being copied. Later assumptions in the code rely upon the string being nul-terminated. Just use copyinstr() and drop the racy sizing. PR: 222687 Reported by: Meng Xu Security: possible local DoS Sponsored by: Dell EMC Isilon Modified: head/sys/netsmb/smb_subr.c Modified: head/sys/netsmb/smb_subr.c ============================================================================== --- head/sys/netsmb/smb_subr.c Fri Sep 29 15:13:28 2017 (r324101) +++ head/sys/netsmb/smb_subr.c Fri Sep 29 15:53:26 2017 (r324102) @@ -110,22 +110,11 @@ smb_strdup(const char *s) char * smb_strdupin(char *s, size_t maxlen) { - char *p, bt; + char *p; int error; - size_t len; - len = 0; - for (p = s; ;p++) { - if (copyin(p, &bt, 1)) - return NULL; - len++; - if (maxlen && len > maxlen) - return NULL; - if (bt == 0) - break; - } - p = malloc(len, M_SMBSTR, M_WAITOK); - error = copyin(s, p, len); + p = malloc(maxlen + 1, M_SMBSTR, M_WAITOK); + error = copyinstr(s, p, maxlen + 1, NULL); if (error) { free(p, M_SMBSTR); return (NULL);