Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5977015ybc; Wed, 27 Nov 2019 12:45:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwSU+HQ63m4tGRyjkRCsKREkDLcSEAqL2HePrBmbSWteG/B9mgl5NSwXtmrW5/XirsxTep9 X-Received: by 2002:a17:906:b7c4:: with SMTP id fy4mr22819596ejb.139.1574887521391; Wed, 27 Nov 2019 12:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887521; cv=none; d=google.com; s=arc-20160816; b=atmNaK0mPbaDaKwPYSqK7y3bQ5oOptsSo/eoMPKIyIF2vm43c0o1HqIkd0VVBDv8J4 ImTYbfbjAzS9hF9sTS4omOsAK0HVQgq15RgrkVBXSN/kwvQJEdqt6ppSWTMnlU606qnX kKHKaIMcZ1q49B1POBDD20sNJXjZQs8QwmdGJwgNy8o0x+1b3gO1iMUnrUpfNKaGGMgP UPl/4gqvmL72lrmiGUzWEsH2QX9uyWd+BAi63QqflC1B/1T2HC8IYFv/j9FERDGezc+Y Md8k9v7GUW1tnnG1LbvrKtcyU6TmNNe7O+9D2uMSX/vHi3Rql3M0yNlkvVzwbfV/lPQw iTeg== 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=cgc6wWmqBOsiGHnQ7lStjavSJVi+ln5PHeMA0uMXcns=; b=rfYNxooQcDcV2kKam4T7mWQ0o+nMrxssAKeKMFkvFE9v779yWQXXyD+WAaApYz2ju4 rslkbDcVRlv7PGtDRvrf3baQHXWUmm3ttVxI6MyEMMxX7zrIh4P5e6FAeBKv/58ZCpgi G/PU4l+2Hp3W+zcWa8jr9nIb7CVgq3wWVpp0AQJJtd07FWtYEbtxnYxGanQlfrqNKhaO nfBfDfan2hwe5KmppKJTzp2E/zCXKO7lpv15/YWc2bfGhb6ppDMonk3q7aQZN1vDZh4t hVYycOVSL6MXfBcZUKgO3ep0/inpfcbwaawJqlwo08XZJrMKYS9R1dNGpBMW7xBkHE2H /0WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ncqz5ZPm; 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 si11si10484778ejb.71.2019.11.27.12.44.57; Wed, 27 Nov 2019 12:45:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Ncqz5ZPm; 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 S1729291AbfK0UmG (ORCPT + 99 others); Wed, 27 Nov 2019 15:42:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:47934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729283AbfK0UmE (ORCPT ); Wed, 27 Nov 2019 15:42:04 -0500 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 0A73621781; Wed, 27 Nov 2019 20:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887323; bh=x6hLt6z0ctPoVuvek0M26yoPRBeU6LO5WwNb4a7OFWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ncqz5ZPm/kFEyZpuElx6Xh/lx+yLb7MuYaHRrhDk/zt2zrWgmkV/5BfVuWo7Gd2LW DFgcZgm8ypfhThVfxwgFmH6LzbYzw8PlP9DicR1ooNc2hqwmqur6O94043FyDvEla0 yKvzoK0Pi7kggooutelToausZxQwrOImCpZUTRcI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duncan Laurie , Vadim Bendebury , Stefan Reinauer , Furquan Shaikh , Furquan Shaikh , Aaron Durbin , Justin TerAvest , Ross Zwisler , Guenter Roeck , Sasha Levin Subject: [PATCH 4.9 024/151] gsmi: Fix bug in append_to_eventlog sysfs handler Date: Wed, 27 Nov 2019 21:30:07 +0100 Message-Id: <20191127203016.022159357@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203000.773542911@linuxfoundation.org> References: <20191127203000.773542911@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 From: Duncan Laurie [ Upstream commit 655603de68469adaff16842ac17a5aec9c9ce89b ] The sysfs handler should return the number of bytes consumed, which in the case of a successful write is the entire buffer. Also fix a bug where param.data_len was being set to (count - (2 * sizeof(u32))) instead of just (count - sizeof(u32)). The latter is correct because we skip over the leading u32 which is our param.type, but we were also incorrectly subtracting sizeof(u32) on the line where we were actually setting param.data_len: param.data_len = count - sizeof(u32); This meant that for our example event.kernel_software_watchdog with total length 10 bytes, param.data_len was just 2 prior to this change. To test, successfully append an event to the log with gsmi sysfs. This sample event is for a "Kernel Software Watchdog" > xxd -g 1 event.kernel_software_watchdog 0000000: 01 00 00 00 ad de 06 00 00 00 > cat event.kernel_software_watchdog > /sys/firmware/gsmi/append_to_eventlog > mosys eventlog list | tail -1 14 | 2012-06-25 10:14:14 | Kernl Event | Software Watchdog Signed-off-by: Duncan Laurie Reviewed-by: Vadim Bendebury Reviewed-by: Stefan Reinauer Signed-off-by: Furquan Shaikh Tested-by: Furquan Shaikh Reviewed-by: Aaron Durbin Reviewed-by: Justin TerAvest [zwisler: updated changelog for 2nd bug fix and upstream] Signed-off-by: Ross Zwisler Reviewed-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/firmware/google/gsmi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c index c463871609764..98cdfc2ee0dff 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -480,11 +480,10 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, if (count < sizeof(u32)) return -EINVAL; param.type = *(u32 *)buf; - count -= sizeof(u32); buf += sizeof(u32); /* The remaining buffer is the data payload */ - if (count > gsmi_dev.data_buf->length) + if ((count - sizeof(u32)) > gsmi_dev.data_buf->length) return -EINVAL; param.data_len = count - sizeof(u32); @@ -504,7 +503,7 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, spin_unlock_irqrestore(&gsmi_dev.lock, flags); - return rc; + return (rc == 0) ? count : rc; } -- 2.20.1