Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4888317pjb; Mon, 27 Jul 2020 07:39:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6oGHJnBHx1sVRp2znWcRe1Pv/osrokLzf+/NHJkSGRX5NTI/OyIr5pUeF5ET+GoAViZBR X-Received: by 2002:a17:906:80d3:: with SMTP id a19mr22249717ejx.217.1595860751824; Mon, 27 Jul 2020 07:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860751; cv=none; d=google.com; s=arc-20160816; b=gW1pxuSeeMMjGLHg+9/chFYY8C6V7VGPXRuvO2xeiwl9jgTjTAhMor6MmUr7zWuiKF ofEH1ycwRfz16RsYP6G+UPiUEWnkeeUjlkfHa4O2x/dAwFfFp8fxRL55qsQnN2FHPKkm Rbxqnltkm22NXV8ZQn3QWf4RR0o5U5so4gyGNXvAN1lzqP/2XK+MJ5Ilubr4CstbiNJg jXLwcaUAJNkZTHE4gv19Fts6ROH3HHXNe1f1ZqZurY+HZtr4dEWrOFJpsWPj+bP87lUP iq1UR51GKV5FnA8bVYQSi0LTCo1oy0i9Y+yBAa+NdhXlQw990Mfp3yQlDnBajzTRzMEQ eLpw== 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=+3cfl4bwIaw9YIXPGKrEA3r5jrW73NCXZWA1HV59/5Y=; b=GjxCaMINgVpvxDV+n9Yw4teZnGc3da4hx8Fr9QGMKu6r5AdfDo6cuIS8Bk7DpEmhOR 2lNqpKFL4lZXsX+hE6ZZ+M9L1eU4OPYWnywkSs005iF018qFXlEjY8SBLbaNLoREFY3W seJ5JqfoVKDd+y2R2OLFGQEz2yepwcVJ2Z1u3OcYOJ+OlGWnTkmhK0nHERi91+ZsDZxR mJ6a1y2KgLjaYlUI6+xHl9Ix4f9J/LFEQK7QBFRh8QuFDFW9d3B3prJQdiqvQmLGjXCL 6pVm5CY+lAQhuBYoU+a+tVbwWTTripYRomgdwDPi6Ftu1Tp4tACbo5hpdQF1VDrj119a c6fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n4q51Lxv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb10si5709397edb.420.2020.07.27.07.38.49; Mon, 27 Jul 2020 07:39:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n4q51Lxv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730176AbgG0OMP (ORCPT + 99 others); Mon, 27 Jul 2020 10:12:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:36352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730150AbgG0OMM (ORCPT ); Mon, 27 Jul 2020 10:12:12 -0400 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 0EAFF20838; Mon, 27 Jul 2020 14:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859132; bh=LtcaDP+8s7NZB4utetwwB27kehj8gYyt/QbXVd8N9X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n4q51LxvZfWUbD1V9JgvkRC8JvRh10RRmhfefdwn/B/ZUE8HiM1k5EYUspjb/QwRA ifQo9CX4GqoPToQlP3veiMTyl4s04X97JVpRO2r7fzsMP0Z63LVtqsGRby45vEE8ac ihNQUjyzPlGIc6Rn0VbNSIcSd84l9ly3eKdITAI8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pawe=C5=82=20Gronowski?= , Alex Deucher Subject: [PATCH 4.19 78/86] drm/amdgpu: Fix NULL dereference in dpm sysfs handlers Date: Mon, 27 Jul 2020 16:04:52 +0200 Message-Id: <20200727134918.314684663@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@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: PaweÅ‚ Gronowski commit 38e0c89a19fd13f28d2b4721035160a3e66e270b upstream. NULL dereference occurs when string that is not ended with space or newline is written to some dpm sysfs interface (for example pp_dpm_sclk). This happens because strsep replaces the tmp with NULL if the delimiter is not present in string, which is then dereferenced by tmp[0]. Reproduction example: sudo sh -c 'echo -n 1 > /sys/class/drm/card0/device/pp_dpm_sclk' Signed-off-by: PaweÅ‚ Gronowski Signed-off-by: Alex Deucher Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c @@ -529,8 +529,7 @@ static ssize_t amdgpu_set_pp_od_clk_volt while (isspace(*++tmp_str)); - while (tmp_str[0]) { - sub_str = strsep(&tmp_str, delimiter); + while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) { ret = kstrtol(sub_str, 0, ¶meter[parameter_size]); if (ret) return -EINVAL; @@ -630,8 +629,7 @@ static ssize_t amdgpu_read_mask(const ch memcpy(buf_cpy, buf, bytes); buf_cpy[bytes] = '\0'; tmp = buf_cpy; - while (tmp[0]) { - sub_str = strsep(&tmp, delimiter); + while ((sub_str = strsep(&tmp, delimiter)) != NULL) { if (strlen(sub_str)) { ret = kstrtol(sub_str, 0, &level); if (ret) @@ -882,8 +880,7 @@ static ssize_t amdgpu_set_pp_power_profi i++; memcpy(buf_cpy, buf, count-i); tmp_str = buf_cpy; - while (tmp_str[0]) { - sub_str = strsep(&tmp_str, delimiter); + while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) { ret = kstrtol(sub_str, 0, ¶meter[parameter_size]); if (ret) { count = -EINVAL;