From patchwork Tue Jul 14 08:15:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11661935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7532E1392 for ; Tue, 14 Jul 2020 08:15:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 591F0217D9 for ; Tue, 14 Jul 2020 08:15:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rp+JngwK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725816AbgGNIPg (ORCPT ); Tue, 14 Jul 2020 04:15:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54608 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725793AbgGNIPf (ORCPT ); Tue, 14 Jul 2020 04:15:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594714534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=f8+KnFgAxKm6sgEPySfwahianaqUhM5wZ//swhq+ahg=; b=Rp+JngwKB3WhWxOJ5AqHGIDL7G5kGgvQgV8nOm0Uv4qMBgH2ZAdTMnaAZoqcLWMmWU6tK8 qZ4TDk1giRMogvTLNDUwREF8OHuVS12oz+9Wfn3xXtRlZxUb20sbtUE7I0Wb3++4xTp740 DSDG6MBOYWVnydBFv3dQFyS80pdivDo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-mhrCMM7eMZ2cOLwZQQt1HQ-1; Tue, 14 Jul 2020 04:15:32 -0400 X-MC-Unique: mhrCMM7eMZ2cOLwZQQt1HQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 545B91800D42; Tue, 14 Jul 2020 08:15:30 +0000 (UTC) Received: from x1.localdomain.com (ovpn-114-109.ams2.redhat.com [10.36.114.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7C5760CD0; Tue, 14 Jul 2020 08:15:28 +0000 (UTC) From: Hans de Goede To: Darren Hart , Andy Shevchenko , Henrique de Moraes Holschuh Cc: Hans de Goede , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5.8 regression fix] platform/x86: thinkpad_acpi: Revert: Use strndup_user() in dispatch_proc_write() Date: Tue, 14 Jul 2020 10:15:10 +0200 Message-Id: <20200714081510.6070-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Commit 35d13c7a0512 ("platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()") cleaned up dispatch_proc_write() by replacing the code to copy the passed in data from userspae with strndup_user(). But strndup_user() expects a 0 terminated input buffer and the buffer passed to dispatch_proc_write() is NOT 0 terminated. So this change leads to strndup_user() copying some extra random bytes from userspace till it hits a 0 byte. This commit reverts the change to use strndup_user() fixing the buffer being passed to the ibm_struct.write() call back containing extra junk at the end. Fixes: 35d13c7a0512 ("platform/x86: thinkpad_acpi: Use strndup_user() in dispatch_proc_write()") Signed-off-by: Hans de Goede --- drivers/platform/x86/thinkpad_acpi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 92aad746d1f8..8ae2be5871f5 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -886,11 +886,19 @@ static ssize_t dispatch_proc_write(struct file *file, if (!ibm || !ibm->write) return -EINVAL; + if (count > PAGE_SIZE - 1) + return -EINVAL; + + kernbuf = kmalloc(count + 1, GFP_KERNEL); + if (!kernbuf) + return -ENOMEM; - kernbuf = strndup_user(userbuf, PAGE_SIZE); - if (IS_ERR(kernbuf)) - return PTR_ERR(kernbuf); + if (copy_from_user(kernbuf, userbuf, count)) { + kfree(kernbuf); + return -EFAULT; + } + kernbuf[count] = 0; ret = ibm->write(kernbuf); if (ret == 0) ret = count;