Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6000929ybc; Wed, 27 Nov 2019 13:11:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwb3083Q2eAQYDnehjceyI9HhYWa297oSzSXFgDjrzdPrMG5THheC6IdLoEbhVKJAPbopgo X-Received: by 2002:a17:907:1102:: with SMTP id qu2mr50777445ejb.300.1574889076846; Wed, 27 Nov 2019 13:11:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889076; cv=none; d=google.com; s=arc-20160816; b=x04oMXq3T0Slm/c9no92umTtC4x6B/VWzru3mSHpUU1X2SVPL+mED2u7Ly8U2goh57 bRGB1qqUggVEED0v24kWz2YxGPEpI7ib911dXTK4LubrghlBjwY0jQ0zhOLfqttZYfhc ae1M38zH8fPP+8T4kyDjIc6hecoImedRJVepis3AUxbv4YHZm+Rc2k5eogFkiv6Tssxq wqEDeybwgLfNF7kD0ons+S1+1+LYLxgdWqW5S2FVUwcgjGHsmb5fHwOGAMMaRxhaNgvR 2A36pxjyKAhjUJpSi0ThVeV4E2MlKWKG7/uVbQPVGwo4bpYPpFh6nROfXHlPNobY4J4N jgKQ== 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=iCzxiVU+6Y6BzYS+7dEWLcn/Q1v5HFAAuwRIZBU7+Sk=; b=PvQ7rYiWo9dcCwtBBHEn6Pmqs0HUQVmHfjtPipZRz9QHpyCJnrMuR/QLh72+OwfcFO dLSv2jDrA2EAtZEuULcPuYnRB6+n9tUicAJxEpdFtM3j8faW6p8V4WHlgqiiVh1cKKqZ KKz2BFCkYqAs45WPMy2xRJVyC7l0y7NM0uaYJhNuq3zVNmU4giRvUSbsiMWqBCtvaKZf ogt8c1J86wVwedUp1SnTPifvsnhDw3lMbm3X5YxQX1OA29R5TgoIfSwouyXGKc+GTWmn CUuBtmxff7YIKTiP3HP+bEbborjsXopN+bQVezYQQY7YiVNqX2K+LdZmzqx1hgcw9Mug 8U7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UJEMbu1f; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c26si11889145edc.416.2019.11.27.13.10.53; Wed, 27 Nov 2019 13:11:16 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=UJEMbu1f; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732734AbfK0VIV (ORCPT + 99 others); Wed, 27 Nov 2019 16:08:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:34738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732109AbfK0VIS (ORCPT ); Wed, 27 Nov 2019 16:08:18 -0500 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 B166021775; Wed, 27 Nov 2019 21:08:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888897; bh=pB+3gUPuAltXfAtFIuNBs7ZGOUpl7sh6mg06gRg+cOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJEMbu1f4dpoi6PuU7EwBionYffUxLMKzaUpCd+/SqlFW23bnPatkNsVTzOhh3f4I xCScgmkRu1FC0/tw4tiDqN4BV+3EaprmOQSCA/LvuNud37d6JT3IFqDMkXTMjmHbuk fItOt08ZMGo7vBKGlOTLE/SAq6wWV4s0bEhaY+Oo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai Shen , Feilong Lin , Viresh Kumar , "Rafael J. Wysocki" Subject: [PATCH 4.19 286/306] cpufreq: Add NULL checks to show() and store() methods of cpufreq Date: Wed, 27 Nov 2019 21:32:16 +0100 Message-Id: <20191127203135.678264000@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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: Kai Shen commit e6e8df07268c1f75dd9215536e2ce4587b70f977 upstream. Add NULL checks to show() and store() in cpufreq.c to avoid attempts to invoke a NULL callback. Though some interfaces of cpufreq are set as read-only, users can still get write permission using chmod which can lead to a kernel crash, as follows: chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq This bug was found in linux 4.19. Signed-off-by: Kai Shen Reported-by: Feilong Lin Reviewed-by: Feilong Lin Acked-by: Viresh Kumar [ rjw: Subject & changelog ] Cc: All applicable Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -909,6 +909,9 @@ static ssize_t show(struct kobject *kobj struct freq_attr *fattr = to_attr(attr); ssize_t ret; + if (!fattr->show) + return -EIO; + down_read(&policy->rwsem); ret = fattr->show(policy, buf); up_read(&policy->rwsem); @@ -923,6 +926,9 @@ static ssize_t store(struct kobject *kob struct freq_attr *fattr = to_attr(attr); ssize_t ret = -EINVAL; + if (!fattr->store) + return -EIO; + /* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().