Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp778351ybc; Sat, 16 Nov 2019 08:31:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz6dQqZw5P/UnyFxrsBmurgop3PqI/JSHY6r2EnxjZ7BJrnR2I4i75pXPNANNEbr0ouizdq X-Received: by 2002:adf:f651:: with SMTP id x17mr16320142wrp.114.1573921899717; Sat, 16 Nov 2019 08:31:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921899; cv=none; d=google.com; s=arc-20160816; b=th4xBeUg87kuV34u1kzuEU48MyWi58WVxBdP+rwnYNLinDKJ2IaJsynVELHPICsaLO biz+PCI/sjXLtGB/HVH7eoXVY2f5DURNboAFFCcXas0BHDat71lhAiM7oXX7yFi3iebX fRDfT4VfqqV1nFiJts39k+kCVGjMQVk7oehs8rSpx/alji1LVwgwav3TB7aoscJV5tIc ccZR5MfihJpKehLLcYpjPAC5pMe0uVtxZQ0eiaJRS3+iptuLtVel4KiRfv3IkLWrChlk BPiYNvmW/CMjYhWlWcB7gFyRntx0LJ1qG4uhMvkmWFoHNXUeInPLNnDkzuf8W4YNSPLH y9Og== 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=uCY9Bg39yesPNMX74BwDzJIzenazJ5TBxu2lhrlJIGs=; b=Px/8gCZDDYoUFa7eUr8zQJ1ZYjvzbGgZyrziyqES9MkcuFtn0ODxpbcHRku30IwnY6 SNhc4zZqL6bchpqKkXSjFd2cKErN80v4haQaWObRybi5taudApk0Od2uyrYfyomrk8Rp cP0iLfouVv/B2qIWD3yzHBHvj5Myy6eIUmI+wRqNFLfAbJviQ0lZdVLbEH2wcPpc9xFi inA1O5BDWFvULl10XUI4F43dvPE7Ih3pjXvGdTxhsZpqe4vQ4ziDelkdn9nB+mUWTSHb L3oCruKvEexDQDHrUYPKSTqxxu8NcnlpfX8IzEcP6odzYzq8ZGblxNkVl2ShLws2BtrR 8wFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QbJbyd3f; 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 b5si7967999edj.310.2019.11.16.08.31.15; Sat, 16 Nov 2019 08:31:39 -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=QbJbyd3f; 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 S1729707AbfKPQ05 (ORCPT + 99 others); Sat, 16 Nov 2019 11:26:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:44972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727988AbfKPPlo (ORCPT ); Sat, 16 Nov 2019 10:41:44 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (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 7EBC020740; Sat, 16 Nov 2019 15:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918903; bh=Mjp9Ayi7gHDEl4RyIz4743czz+ZO/l4kYbTirM1WaXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QbJbyd3fZTAYvMsY04GNxVF52FMaT1Wjs2RTZHy3qvE+exyHM+JajwN3VruJCjJDi ao0izyynkKviFg0BSogXy26Fz0yumR2JrbQCYYsT0Unrv/fpNNcfnHNZ7j9WLeKGbh REBQbUXDgU+kMGG/TCfTmINeXG5ZHIX2pDXyKtLA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Duncan Laurie , Vadim Bendebury , Stefan Reinauer , Furquan Shaikh , Furquan Shaikh , Aaron Durbin , Justin TerAvest , Ross Zwisler , Guenter Roeck , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.19 030/237] gsmi: Fix bug in append_to_eventlog sysfs handler Date: Sat, 16 Nov 2019 10:37:45 -0500 Message-Id: <20191116154113.7417-30-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-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: 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