Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6029343ybc; Wed, 27 Nov 2019 13:41:51 -0800 (PST) X-Google-Smtp-Source: APXvYqzu5/2NkjosZNpYlEzn+jfAseMJodzstAaiBkfCxJBdvDU3TVMKe02mhLMf/Ci3ZWVKugmk X-Received: by 2002:a17:906:5256:: with SMTP id y22mr795168ejm.192.1574890911499; Wed, 27 Nov 2019 13:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890911; cv=none; d=google.com; s=arc-20160816; b=c+2bu64BNyU8fEbY1OVPSkUVc5bVCGpbDJvzuMnkS2f5j/f+ykZpe+k5jMDmauAan3 vpQS0LfxUorkOxsmDW2qIl/vOtmUsXNa+bKdN74XUy/qLDj9LWdrJmXfB7yt2x59DY0E dFkI62SDHfwLH9Z+wV2seJUbMdd4bhnBEu2Bs//od8/F57W/7WCnOKpcd2vXEFrBMegS 7wPnkRbgY+GbkMkZLzRSxn6CcyblKP4RFOK8Wzoil611lUQ0TwaBREPwDpUrkFtF6L5y 3lVHNoUn5hxq+3XKehBmxJLtxm8d6SPgvTNbDIVLPPHksKl831NUy6CvY5PkyVUA9JU5 6txA== 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=uCY9Bg39yesPNMX74BwDzJIzenazJ5TBxu2lhrlJIGs=; b=XC/miq7R9n+uhSKpMkloFqpA9JB9QwqpH2dNnpfB+EF3J5NpiOZwC3MMSTgVJS2x2U 0bGkBBeDA9dn71QyJZnbFVL6gfdeMwoMg6vxZHykINRfTMPvefRhL1EAzpyMLYdPEpEG zK02iOco/t8C/Ogv+MwIMobQc+mvvF0lVbRYhr5i57CvGwUAYwBoUZzxVbWJnty1xDJQ tln2lUT64Y1VhNpnEQCdbt/n6kf5cG/7RMzK2VXETQ7Gx4g5/0pUWQz/gS6CbAldzD7g hKFUWT1RXNmyba891NPkNNf3Fr99YhTjG78bads9Ox5v3GMyxjCza1ETPJOFkMLH26SA 4TZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JaT8oQ0A; 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 s35si11430662edd.261.2019.11.27.13.41.27; Wed, 27 Nov 2019 13:41:51 -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=JaT8oQ0A; 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 S1729898AbfK0VhO (ORCPT + 99 others); Wed, 27 Nov 2019 16:37:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:59926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729484AbfK0UrP (ORCPT ); Wed, 27 Nov 2019 15:47:15 -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 74C0021843; Wed, 27 Nov 2019 20:47:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887634; bh=Mjp9Ayi7gHDEl4RyIz4743czz+ZO/l4kYbTirM1WaXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JaT8oQ0AdNBkD9AweTvRgIqaTXK6CZax+VDmx89lzt3mv3AeFhBtyln9m/BRkcs6S 98S4PEeAuHTpsWH8as73LxKXG04boXJG1Fftd6CZ3Qx7eVlOZuMuNaDVTJA2FgI3++ 0wAWqXHISgK634q5VSp92O26/K0W5e2Y6i4hRnS8= 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.14 034/211] gsmi: Fix bug in append_to_eventlog sysfs handler Date: Wed, 27 Nov 2019 21:29:27 +0100 Message-Id: <20191127203055.133291477@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@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 c8f169bf2e27d..62337be07afcb 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