Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4882137pjb; Mon, 27 Jul 2020 07:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXL8FkyvfC2xyDSGXagdbLW95r2TnKn5ogWerwpXsabkpJT+NTfx3R3O9XmK+PUF8pi2L7 X-Received: by 2002:a17:906:cc51:: with SMTP id mm17mr1350042ejb.137.1595860258363; Mon, 27 Jul 2020 07:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860258; cv=none; d=google.com; s=arc-20160816; b=vCbjY1BJ87A/bzgYm2+WlDRXRM1wDxXA9EiGwbm6NjDi2sacvQOQ5J0uXvDQGXy2Lm ON3rdYeoOvu8AyS+S4IKeLQJ8xU25V5ouhURG6rFigFfK7UuK5figNIh0onADv4tgvBx YAu3pVLUhqR8VBJjDIvbqlFnjfEXm3p4AJG7/xa/aoIXEeV+yRnKyvB5mows1E5Ef/Ip MagMtYg8/K6pCo+cpFzmAKmbfsnSd4Nn0BT4GBmcExHrfL0G8PqB4odxNyOykzp4h78B Bi56NBrod1R3Vn98fLjJJYH3Y/9PHtt3EsIKGSo8d121WYMcP5Hg5cRLIlqkwQspGDRV S2qw== 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=DNaWhnSRRlEE1cIMpVPNqpPmvwVnElmJtjxtP4cvKKs=; b=Su8rVM3RaHpAk8g+N/ccDdtMnJA8GcJJ+pzgX8ifTyyaudlm9P7AHww8NNOLbvWnf0 PhN/DZvmq1jjEIn+Gu4P6IhUA+3oPnR6Wy3Z5yyjLI8amVrU7hk+tn9mhYc6lRE1xHvO Kx0VnVPTkKgWMTVDHUEBxEo8OtIsnFO1NOJxbvuDAJEmva0NLfWDzg+C5x4hOsPCGzF5 w/Uzbe72RYZ7Z6tU/S+/b0pHn8Mt3cIMsdk4IHxG0lSPwC7ri3c3fHSs7HwTsZ75+kmb 1ALHtKflfG6fT15m2yJQbzZwD5bIsVi+quT5HDOX5qNUX0V+o0rzwtGEyhYLk7Pdlriu zy1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xFOD3vst; 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 e10si2645488edy.274.2020.07.27.07.30.36; Mon, 27 Jul 2020 07:30:58 -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=xFOD3vst; 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 S1732187AbgG0O1X (ORCPT + 99 others); Mon, 27 Jul 2020 10:27:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:55982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732512AbgG0OZt (ORCPT ); Mon, 27 Jul 2020 10:25:49 -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 A304021D95; Mon, 27 Jul 2020 14:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859949; bh=IpPNz01uO1QjtLxilmlnsg8OVIYlMpAGWMPWTCRk9qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xFOD3vstBmEsbBLAwWUYDRnqfGDEzQoyNVvpDR5pFIdhAgKVHm/FLiT5XWNorCEcJ Pq76vU6Tjt4tzaLmatvglRIiSqFsfGa9ZwzzLqB8Mx8T8eCa2wNEW+RzSapFSrp1Mg elz1sPdvgewuvlIN2wbLVRz+f5GBX5KFC4hGMY4w= 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 5.7 167/179] drm/amdgpu: Fix NULL dereference in dpm sysfs handlers Date: Mon, 27 Jul 2020 16:05:42 +0200 Message-Id: <20200727134940.796558955@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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 @@ -775,8 +775,7 @@ static ssize_t amdgpu_set_pp_od_clk_volt tmp_str++; 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; @@ -1036,8 +1035,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) @@ -1634,8 +1632,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) return -EINVAL;