From patchwork Tue Dec 12 09:33:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ma Shimiao X-Patchwork-Id: 10106551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3A124602B3 for ; Tue, 12 Dec 2017 09:32:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31D6929B66 for ; Tue, 12 Dec 2017 09:32:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2491729B69; Tue, 12 Dec 2017 09:32:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A98D429B66 for ; Tue, 12 Dec 2017 09:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751281AbdLLJcu (ORCPT ); Tue, 12 Dec 2017 04:32:50 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:30059 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750749AbdLLJcr (ORCPT ); Tue, 12 Dec 2017 04:32:47 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="31262717" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Dec 2017 17:32:44 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 9942048AE827; Tue, 12 Dec 2017 17:32:44 +0800 (CST) Received: from G08FNSTD121139.g08.fujitsu.local (10.167.225.93) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 12 Dec 2017 17:32:43 +0800 From: Ma Shimiao To: CC: , , , , Ma Shimiao Subject: [PATCH] drivers/input/misc: fix max dup length for kstrndup Date: Tue, 12 Dec 2017 17:33:48 +0800 Message-ID: <20171212093348.20786-1-mashimiao.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Originating-IP: [10.167.225.93] X-yoursite-MailScanner-ID: 9942048AE827.AA0AC X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: mashimiao.fnst@cn.fujitsu.com Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If source string longer than max, kstrndup will alloc max+1 space. So, we should make sure the result will not over limit. Signed-off-by: Ma Shimiao --- drivers/input/misc/uinput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 39ddd9a73feb..f94c6a452025 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -468,7 +468,7 @@ static int uinput_dev_setup(struct uinput_device *udev, udev->ff_effects_max = setup.ff_effects_max; kfree(dev->name); - dev->name = kstrndup(setup.name, UINPUT_MAX_NAME_SIZE, GFP_KERNEL); + dev->name = kstrndup(setup.name, UINPUT_MAX_NAME_SIZE - 1, GFP_KERNEL); if (!dev->name) return -ENOMEM; @@ -543,7 +543,7 @@ static int uinput_setup_device_legacy(struct uinput_device *udev, } kfree(dev->name); - dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE, + dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE - 1, GFP_KERNEL); if (!dev->name) { retval = -ENOMEM;