Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3328183imu; Sun, 11 Nov 2018 12:28:45 -0800 (PST) X-Google-Smtp-Source: AJdET5eyXMHorLh6vSQv9XBMht6l5dW7GAGeFnHIOUL37dz4apDidM7WTxEvoHfME2IIaZgK3IzD X-Received: by 2002:a63:2109:: with SMTP id h9mr14991130pgh.277.1541968125508; Sun, 11 Nov 2018 12:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968125; cv=none; d=google.com; s=arc-20160816; b=fLcT4srgV9Fl4053Zvmvo2gBH6OcGT9A/+nWYqR8CFEIzKRQoO6vZqw85PCfhBqJlX CZurZzVACwWDTvEgk/zlCyvM0Qo/0D5bFIXKlO1DoYsIEC2F898W9rcV4ru78xLP0JhC V+C7738SLj2w5HOIW9TZGaQaOU4CnTXRDeRtq+DTWoLGzBBM6tBP5CUByW//kYcCjWa1 1ukE4h0EHya/Sl1w1YHFBzKhJmcVBS0G5O0Zt2LLUyeXUuHK8SC0zMCnJqvaNcR0nVDP mOZ60wmyqFtX29Ao4AxuNNXCoV/ih9DerNrdDQuZrqYZ6fYbyQjByX9MhqLNfApmlVfG Hotw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=ZnAtuWudu4h1a8kkHn7JZxA9ZbFkul3yL1t+6txvIMo=; b=0mWqWBftwB3Jy50MPdlhQUrDxsp7k9scjVsegYBay8QK4flcWb7cSXqVVHw2aFV0RQ /mtEW5IqH52P67ksUzXmuRXlgEg88Cnp2LVToVVHxrhys6/EsuT9yBa32/5fr+Os2RrK 4400S36HywmXD9alaE83Jc7W3aUVBYVxnHE7KNzqViad+g/ZeedCMwMY+eHVzws9prP3 /YbUjd//fsNmke/JHyvMNGbRpJensh7UPh7SN4c+1ArUzBgZEISAWe0RiexnuRb3tlzO KC6/Ho93kxud1nz/BKqQe8q+YX6vJZ/g0I/Vgeb14/CD1u9QobmniH5VDmakTOjzVXnZ Pu5Q== ARC-Authentication-Results: i=1; mx.google.com; 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 z126-v6si16380687pfb.280.2018.11.11.12.28.30; Sun, 11 Nov 2018 12:28:45 -0800 (PST) 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; 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 S1730681AbeKLGRm (ORCPT + 99 others); Mon, 12 Nov 2018 01:17:42 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50678 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730523AbeKLFsY (ORCPT ); Mon, 12 Nov 2018 00:48:24 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsi-0000oU-Mz; Sun, 11 Nov 2018 19:58:52 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsZ-0001qk-VK; Sun, 11 Nov 2018 19:58:43 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jacek Anaszewski" , "Zach Brown" , "Vlastimil Babka" , "Nathan Sullivan" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 331/366] leds: do not overflow sysfs buffer in led_trigger_show In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Nathan Sullivan commit 3b9b95363c45365d606ad4bbba16acca75fdf6d3 upstream. Per the documentation, use scnprintf instead of sprintf to ensure there is never more than PAGE_SIZE bytes of trigger names put into the buffer. Signed-off-by: Nathan Sullivan Signed-off-by: Zach Brown Signed-off-by: Jacek Anaszewski Cc: Vlastimil Babka Signed-off-by: Ben Hutchings --- drivers/leds/led-triggers.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -78,21 +78,23 @@ ssize_t led_trigger_show(struct device * down_read(&led_cdev->trigger_lock); if (!led_cdev->trigger) - len += sprintf(buf+len, "[none] "); + len += scnprintf(buf+len, PAGE_SIZE - len, "[none] "); else - len += sprintf(buf+len, "none "); + len += scnprintf(buf+len, PAGE_SIZE - len, "none "); list_for_each_entry(trig, &trigger_list, next_trig) { if (led_cdev->trigger && !strcmp(led_cdev->trigger->name, trig->name)) - len += sprintf(buf+len, "[%s] ", trig->name); + len += scnprintf(buf+len, PAGE_SIZE - len, "[%s] ", + trig->name); else - len += sprintf(buf+len, "%s ", trig->name); + len += scnprintf(buf+len, PAGE_SIZE - len, "%s ", + trig->name); } up_read(&led_cdev->trigger_lock); up_read(&triggers_list_lock); - len += sprintf(len+buf, "\n"); + len += scnprintf(len+buf, PAGE_SIZE - len, "\n"); return len; } EXPORT_SYMBOL_GPL(led_trigger_show);