Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2231857ybi; Thu, 20 Jun 2019 11:16:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfd9prSuKrYt0uY8IXr82sqqc7Aq5QUl1bD4nUWcjW05OdXlXW46nkleEaK/houxblAXwX X-Received: by 2002:a63:c03:: with SMTP id b3mr2873935pgl.68.1561054612898; Thu, 20 Jun 2019 11:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561054612; cv=none; d=google.com; s=arc-20160816; b=Px1rY4IO3pt9cfrtJ6IYIDos2xlpWFbOyfQlXHwCCqe4UCKfUesl6S0rSAV7NgXdQi 4RFicvN+6yfDNi/xWN2tu5IptvJyTfKx1c4caYSVQ1UMxg6GNt/rx0hY8L38Nsibw++v xyd4v8S8IZrs9o1k9K/b88WpyV7+Cm8Oav58M72lcRgo5SmYJkoqXAQoPVBRnOmoOrYO 70ir0kDYbAEGeVLvxJqtzK81XMVHSXfdPiu7AB4x/mkpgsoU2Bo80J/zUI6LuGhkBfvm G0HBs8YIlNq2Co2P8vVUS3u+gSHCtfh8Ckq82+RnmlwTwTJCOiAcP6VcnVn4QgVy561J 1peg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yN0MYUSJ3VghyLSK0BprA4d4XMyDAZuggLGwTSw4Zpk=; b=JaR68+/h0VMQb+953hzlICbzdKFO8ohzDkchOba1hT7y9j3i7SPs/Ixh7VoCBmgd1z QxKAsMIRQFOy18KYVguELVsmUe7gYGks3FSSqO8Whoy8Z/4ANtiG9vqXMb/tMvHd88/t DyulvjqXEvQP0iNi268FgtMrcJo5chYpNBU2ienmw2hTEP7/s8O2q4Y8eHTSobPP089Z 45MAQ50S+fbIqrFU3Lb/ILSiHy5TC/UECdMt5EtK9iEtZ7ocVMvVokUFqmzyZXDAlB2g 0pybwz5o0i4dD8qceDj00DOjRPMfVfVYmEHMSN57R2sGNRPk9jJ0wqGmTeU9j4PrjrcO 5puQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rSmEfku/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si412868pjq.46.2019.06.20.11.16.37; Thu, 20 Jun 2019 11:16:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rSmEfku/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729563AbfFTSPR (ORCPT + 99 others); Thu, 20 Jun 2019 14:15:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:43846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728734AbfFTSPL (ORCPT ); Thu, 20 Jun 2019 14:15:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43FF8205F4; Thu, 20 Jun 2019 18:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054510; bh=50bSpiPB+3y8lu4ANYQ0JDtfg3smk3IlAvksqKPAm5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rSmEfku/6KL30rs507La2Dqg3I583XCvbzgCr7Dy9J8CEv5q005qGr6XSV7iA50/R ne4j43O9tNF5r5mfUJWwZnF4/U/nhPosrU/rj0yCFWp176gWOA5w5Sq63SHisizQww KbY/lcSdr3wjxUbxzIZ6pNPjNBYPRDVHD1gXLCZo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "David S. Miller" , Sasha Levin Subject: [PATCH 5.1 46/98] mISDN: make sure device name is NUL terminated Date: Thu, 20 Jun 2019 19:57:13 +0200 Message-Id: <20190620174351.255536460@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174349.443386789@linuxfoundation.org> References: <20190620174349.443386789@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit ccfb62f27beb295103e9392462b20a6ed807d0ea ] The user can change the device_name with the IMSETDEVNAME ioctl, but we need to ensure that the user's name is NUL terminated. Otherwise it could result in a buffer overflow when we copy the name back to the user with IMGETDEVINFO ioctl. I also changed two strcpy() calls which handle the name to strscpy(). Hopefully, there aren't any other ways to create a too long name, but it's nice to do this as a kernel hardening measure. Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/isdn/mISDN/socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c index a14e35d40538..84e1d4c2db66 100644 --- a/drivers/isdn/mISDN/socket.c +++ b/drivers/isdn/mISDN/socket.c @@ -393,7 +393,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) memcpy(di.channelmap, dev->channelmap, sizeof(di.channelmap)); di.nrbchan = dev->nrbchan; - strcpy(di.name, dev_name(&dev->dev)); + strscpy(di.name, dev_name(&dev->dev), sizeof(di.name)); if (copy_to_user((void __user *)arg, &di, sizeof(di))) err = -EFAULT; } else @@ -676,7 +676,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) memcpy(di.channelmap, dev->channelmap, sizeof(di.channelmap)); di.nrbchan = dev->nrbchan; - strcpy(di.name, dev_name(&dev->dev)); + strscpy(di.name, dev_name(&dev->dev), sizeof(di.name)); if (copy_to_user((void __user *)arg, &di, sizeof(di))) err = -EFAULT; } else @@ -690,6 +690,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) err = -EFAULT; break; } + dn.name[sizeof(dn.name) - 1] = '\0'; dev = get_mdevice(dn.id); if (dev) err = device_rename(&dev->dev, dn.name); -- 2.20.1