Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2036748ybb; Fri, 29 Mar 2019 17:18:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpSGlPeby0PLH0xHNGzhpfHgEF+TlxcpcmC9KTC/fEuvDOiir2+O4PFbgE6ZQMIG+qlV5c X-Received: by 2002:a63:1b1e:: with SMTP id b30mr49270804pgb.180.1553905090940; Fri, 29 Mar 2019 17:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553905090; cv=none; d=google.com; s=arc-20160816; b=D08O/ZJ6+NBlwEZbTODqml/C+bPajbUHnPiH295Ygl/z8HrmIyeOWOm/UCfmTr++VH yqP9n0GO27kOuYY1BcglkwSN3GRBhNVgsbyg3NLqbkF7K1p44RxEwpSj4LyI2maDK0nn BlLaCRYw36/f690YgolI2Y62Z1W3fsDFIdaeP0g+dRboooCx//nR91qx0N75MipQy/ht kmGmIQYNY0f7Z3AiJ5VgIKU+Vbfh8xwr/TVGEhL/+XSq55vq5wFrT/COTTfyWlFdZzWr UnVbPbHP5/jqNllVPicUwVN9aKYOoIExEj9vdJjmcYOEiubqP8YEC3kEm+kSQuA/C9+4 Otrg== 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 :message-id:date:subject:cc:to:from; bh=4BB7gmYoSY30nHaW4BEKWt5hMhe/qneoAEjYNCYpNIc=; b=HQjo8w7uQiM5vWyFp0NxOKyogOmibZIpFl6XtNWm376r93JQR2Dl5Kyf3mMGvp8C2C 0QRdp7Rb8ftAmSzvv6RBslcyifjn6XU+xbOScrM+BCpackWXSzjeYU4XDKTA1I8XmN/Q aunsL4NRXwgBBjd3Sx5+F43uPN7oBK9ZBhx37/kQ9empWY2oweFOa6Oia3XSyVMGuJ6U mU1Uci8q+cnT9QPTiRs+JwkLz0P0EdhCft0ntOFCL7+/1skS+xIbogRTWDAm3om6bxrZ AyL9ydUTunUIguGNe9asKywbfOeILoATsXbOH6HUlaB5y4SVbrZY/kXXPfaOOh56XsHd eGAw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si3047734pge.349.2019.03.29.17.17.55; Fri, 29 Mar 2019 17:18:10 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730350AbfC3ARQ (ORCPT + 99 others); Fri, 29 Mar 2019 20:17:16 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44082 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729771AbfC3ARP (ORCPT ); Fri, 29 Mar 2019 20:17:15 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hA1gP-00026s-82; Sat, 30 Mar 2019 00:17:13 +0000 From: Colin King To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] platform/x86: alienware-wmi: fix kfree on potentially uninitialized pointer Date: Sat, 30 Mar 2019 00:17:12 +0000 Message-Id: <20190330001712.8923-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 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: Colin Ian King Currently the kfree of output.pointer can be potentially freeing an uninitalized pointer in the case where out_data is NULL. Fix this by reworking the case where out_data is not-null to perform the ACPI status check and also the kfree of outpoint.pointer in one block and hence ensuring the pointer is only freed when it has been used. Also replace the if (ptr != NULL) idiom with just if (ptr). Fixes: ff0e9f26288d ("platform/x86: alienware-wmi: Correct a memory leak") Signed-off-by: Colin Ian King --- drivers/platform/x86/alienware-wmi.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c index f10af5c383c5..c0d1555735cd 100644 --- a/drivers/platform/x86/alienware-wmi.c +++ b/drivers/platform/x86/alienware-wmi.c @@ -522,23 +522,22 @@ static acpi_status alienware_wmax_command(struct wmax_basic_args *in_args, input.length = (acpi_size) sizeof(*in_args); input.pointer = in_args; - if (out_data != NULL) { + if (out_data) { output.length = ACPI_ALLOCATE_BUFFER; output.pointer = NULL; status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, command, &input, &output); - } else + if (ACPI_SUCCESS(status)) { + obj = (union acpi_object *)output.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + *out_data = (u32)obj->integer.value; + } + kfree(output.pointer); + } else { status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, command, &input, NULL); - - if (ACPI_SUCCESS(status) && out_data != NULL) { - obj = (union acpi_object *)output.pointer; - if (obj && obj->type == ACPI_TYPE_INTEGER) - *out_data = (u32) obj->integer.value; } - kfree(output.pointer); return status; - } /* -- 2.20.1