From patchwork Mon Apr 24 07:11:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mera X-Patchwork-Id: 9695703 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1396360113 for ; Mon, 24 Apr 2017 07:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 015D2223A6 for ; Mon, 24 Apr 2017 07:14:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA37B26B41; Mon, 24 Apr 2017 07:14:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D1C30223A6 for ; Mon, 24 Apr 2017 07:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=cfaUx9bC5nn3ANz8SyjVqTJ3Dq0zLzbS5iWsu/maC2Y=; b=XEJ D28KonpZkYuUtUDxwQ5V0upVl+TDEWGSx82l6VLvyVh81FBWhqCvN009AYqGJcMZtt0IT4wq2WSiV +1oSFmtkpZxa/cSBNFlt3vgHiC8fWVH+Abgm1VYdCDWq8vfgCF+wa9SdEdBVe1GhybKhYbhLJbjHb eb+/9jeAH9QUKbRj7D5Hve/HvQ8IgrDAn0y3nDvxNmzFx2+QJzr6ZmnT3DIWcvR+FdVj90T2ORAUr jC6V52vBsEisUMMGLST5gRIaX3dPKdI40X1jlBbOLsUlIBN1EI04TUZCVW9S0dzv0CKyvAhSaOhX6 YvB/lxQOWQupWJIcYjHpp7cikEYndJw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d2YCb-00059U-Tl; Mon, 24 Apr 2017 07:14:29 +0000 Received: from mail.parvient.jabatus.fr ([109.234.163.53]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2YBt-0004Wn-VE for ath10k@lists.infradead.org; Mon, 24 Apr 2017 07:13:48 +0000 X-MailPropre-MailScanner-From: dev@michaelmera.com X-MailPropre-MailScanner-SpamScore: s X-MailPropre-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=1.901, required 5, autolearn=disabled, BAYES_40 2.00, DKIM_SIGNED 0.10, DKIM_VALID -0.10, DKIM_VALID_AU -0.10, URIBL_BLOCKED 0.00) X-MailPropre-MailScanner: Not scanned: please contact your Internet E-Mail Service Provider for details X-MailPropre-MailScanner-ID: CE214688D2FE2.AF829 X-MailPropre-MailScanner-Information: Message sortant - Serveurs o2switch DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=michaelmera.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pnZhEWCNkislo1scVY/cX8Vh3do97QeHfRDXEwNnkRQ=; b=ZtEiZGMIeZ+Xrd1io5pPUKig5c tWR1nG5VWCmLXZMwrjVl/XB5Ooo99jCvZNPRPu92MvFvkW/j7qa06flFS1WpA5XXBnSpLlPqTalhN nKB9sm7ltM3gb1cOp6UEF0q3q2n0jqoWyHOys7/3XgdsIGwLs4xUcSfmvXJbOscrfJMR6AVAAQJHP 2ZQKenLl+VLONLj06xQO1yfeCHOZygEMVmyyU1OxVPGcZZH0sVw4272vKctV/2+t+gScy3eLAvZYC l9mRJslJxAb7FPyfP4jjU6BOJvYB6zoKO1azvUY+z/hlniQLYCf0mbek3743zo3LJawwdOP7g3OS+ ric93xaw==; From: Michael Mera To: ath10k@lists.infradead.org Subject: [PATCH RESEND] ath10k: fix out of bounds access to local buffer Date: Mon, 24 Apr 2017 16:11:57 +0900 Message-Id: <20170424071157.6979-1-dev@michaelmera.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - citrus.o2switch.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - michaelmera.com X-Get-Message-Sender-Via: citrus.o2switch.net: authenticated_id: dev@michaelmera.com X-Authenticated-Sender: citrus.o2switch.net: dev@michaelmera.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170424_001346_167520_3598A68F X-CRM114-Status: UNSURE ( 7.08 ) X-CRM114-Notice: Please train this message. X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kalle Valo , linux-wireless@vger.kernel.org, Michael Mera MIME-Version: 1.0 Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP During write to debugfs file simulate_fw_crash, fixed-size local buffer 'buf' is accessed and modified at index 'count-1', where 'count' is the size of the write (so potentially out of bounds). This patch fixes this problem. Signed-off-by: Michael Mera --- drivers/net/wireless/ath/ath10k/debug.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c index fb0ade3adb07..7f3c17e55693 100644 --- a/drivers/net/wireless/ath/ath10k/debug.c +++ b/drivers/net/wireless/ath/ath10k/debug.c @@ -628,17 +628,21 @@ static ssize_t ath10k_write_simulate_fw_crash(struct file *file, size_t count, loff_t *ppos) { struct ath10k *ar = file->private_data; - char buf[32]; + char buf[32] = {0}; + ssize_t rc; int ret; - simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); + /* filter partial writes and invalid commands */ + if (*ppos != 0 || count >= sizeof(buf) || count == 0) + return -EINVAL; - /* make sure that buf is null terminated */ - buf[sizeof(buf) - 1] = 0; + rc = simple_write_to_buffer(buf, sizeof(buf)-1, ppos, user_buf, count); + if (rc < 0) + return rc; /* drop the possible '\n' from the end */ - if (buf[count - 1] == '\n') - buf[count - 1] = 0; + if (buf[*ppos - 1] == '\n') + buf[*ppos - 1] = '\0'; mutex_lock(&ar->conf_mutex);