From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DDE4C433F7 for ; Mon, 27 Jul 2020 14:33:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2023D207FC for ; Mon, 27 Jul 2020 14:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595860385; bh=L4T2+3ROUy7Jc2kE2LVhOT1dUpleqA6JyPuFcdEiiDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GN+bHBq9QZR9CS8Vy52seWXg/kffkGhy3M4HNUtsIe9QlShRbVOiijeYX4a8Jt41Y 5EZN4o8P20O9LT/YcHQ+5QzvXu3A59nuFo39zacCAL5+Xl0xaHE6GLk8sx9Qi7M4Ke EpC/+2DBH41rN4BlFf4PALdRPcRXa3G1YLjvz680= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731441AbgG0OdD (ORCPT ); Mon, 27 Jul 2020 10:33:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:45730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731175AbgG0OSJ (ORCPT ); Mon, 27 Jul 2020 10:18:09 -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 178DA2177B; Mon, 27 Jul 2020 14:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859488; bh=L4T2+3ROUy7Jc2kE2LVhOT1dUpleqA6JyPuFcdEiiDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yp9EK8IMC2OXHS7rwtbmYarxXhGh6cAHWQyo5Fo5Q0inzjOPU258cDR8wlcicJncR n6R+NpjZ7roRHHhkRHb/Qs3aTAxN0B8tild9gvOmXPCUF/YYStAJ7U2gT2PW6GC6pY rDuUo2B+Vduh1sZEkNqkyBIgSrMaHpWi2gSPgtD8= 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.4 128/138] drm/amdgpu: Fix NULL dereference in dpm sysfs handlers Date: Mon, 27 Jul 2020 16:05:23 +0200 Message-Id: <20200727134931.829986832@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134925.228313570@linuxfoundation.org> References: <20200727134925.228313570@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 @@ -691,8 +691,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; @@ -883,8 +882,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) @@ -1300,8 +1298,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;