Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2845909yba; Mon, 22 Apr 2019 14:09:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzc5Nt8ghyp5nzin6kh7wj1569rAVXY9O/ZvDPeWTjWMy/LMiV4RyfDvKI1Sdu76uOafzpj X-Received: by 2002:a63:c746:: with SMTP id v6mr20998715pgg.401.1555967365600; Mon, 22 Apr 2019 14:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967365; cv=none; d=google.com; s=arc-20160816; b=dZUF3oQsJ9j7mvEKRdacTvaalp5CHNJ5XJxGmU5+0qSy+lkpI8gZ4C9Xoiti2bGS/D /4LX3Ag0UIVB13RWdyJ7JPmgea2BUC570TZppelWt1znqy69Z8M4Q2dTSeZlG+FBD5RB czzb9l32L8OhIKT10mZgXgr1d6338q8Llls6YHLRmzYvYVL6tpEbEK2R+vjVa/M4iCRa 00I7aESd1dLbQKP8YAVxBIOh2jOlZjIQ1dMAG/Oa3iq3nKPm+iQy3yJrGAat5g0Y5vMg eDQClN38K5GhNZ8RcBseJydpmD6QedOFf1s/CblkV5J9FUBZGl57qm/V0wRsyvzFtAXZ i6tQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8+yboBVU7H3A1F+Oan55PSg3xkbqnXkD5SnDQ6gPaAY=; b=rFJNXrlHCGWqX3BWMZxKtDDC/nNMeV3GBC58DI1q5n7AJZCwHMU7qdXoHw3pwGtJ6G TezCJZhDOTF42e2lKYfG8TvNmGNt4T8tywVxxpqGLR0ZFC5znnAnRSztKvIgiZIGL555 /YaLc+V3Uf3PLWROCtGm71WHeKcVHsHmPAK9sz8qQTfpEE2FscfNCrW6ZiiUG9k33dOC VgcY5iy1ySxlodKvlwt8xiiozARo3J7lxi7tQZ21ws54dE8+VL8j27ohctjfCPZvFsmq V9IDX3JEFN+Cg4oVSaumuqYXGWcBuWDH3RR3HIOWoVdz7ZIxwhcH52Qm43g0oXDBOQao AURg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qeXvDGoD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e19si13037254pgv.63.2019.04.22.14.09.10; Mon, 22 Apr 2019 14:09:25 -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=qeXvDGoD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730286AbfDVTra (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:50238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730276AbfDVTr2 (ORCPT ); Mon, 22 Apr 2019 15:47:28 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5A6C521904; Mon, 22 Apr 2019 19:47:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962447; bh=3thwNhU9wWzxyaOnplzcDqjz1+lmuPcL/tkQJ0lATxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qeXvDGoDvRICXEc2p1A7T45SmrC7qznd77EoaB7I/IWg34UK76WeeuF32EFZaVchs nx//57eKqOeZpIev6ZgRImEuBPhpKiLq7TvxcNTzk7qW8tyZScRw0h64QdEy7Axvyw cvK/uEnszdmJ3PpsuDgmtDPERhmWok1FVdgEYePA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rasmus Villemoes , Jacek Anaszewski , Sasha Levin , linux-leds@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 68/68] leds: trigger: netdev: use memcpy in device_name_store Date: Mon, 22 Apr 2019 15:45:16 -0400 Message-Id: <20190422194516.11634-68-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rasmus Villemoes [ Upstream commit 909346433064b8d840dc82af26161926b8d37558 ] If userspace doesn't end the input with a newline (which can easily happen if the write happens from a C program that does write(fd, iface, strlen(iface))), we may end up including garbage from a previous, longer value in the device_name. For example # cat device_name # printf 'eth12' > device_name # cat device_name eth12 # printf 'eth3' > device_name # cat device_name eth32 I highly doubt anybody is relying on this behaviour, so switch to simply copying the bytes (we've already checked that size is < IFNAMSIZ) and unconditionally zero-terminate it; of course, we also still have to strip a trailing newline. This is also preparation for future patches. Fixes: 06f502f57d0d ("leds: trigger: Introduce a NETDEV trigger") Signed-off-by: Rasmus Villemoes Acked-by: Pavel Machek Signed-off-by: Jacek Anaszewski Signed-off-by: Sasha Levin (Microsoft) --- drivers/leds/trigger/ledtrig-netdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 167a94c02d05..136f86a1627d 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -122,7 +122,8 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = NULL; } - strncpy(trigger_data->device_name, buf, size); + memcpy(trigger_data->device_name, buf, size); + trigger_data->device_name[size] = 0; if (size > 0 && trigger_data->device_name[size - 1] == '\n') trigger_data->device_name[size - 1] = 0; -- 2.19.1