Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4232220ybb; Tue, 7 Apr 2020 03:29:05 -0700 (PDT) X-Google-Smtp-Source: APiQypKfc2bG57wMf+LXkk+qwYxMFFB5q4OEWcVMnD+bWIkakJ7kv/BcGxCKOyqpINjR8bS6YFwA X-Received: by 2002:a54:4711:: with SMTP id k17mr1128415oik.104.1586255344897; Tue, 07 Apr 2020 03:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586255344; cv=none; d=google.com; s=arc-20160816; b=zU+Z0cP7q4R6eSVEqzk5HrsipqLfiF9NQu352vtNoLpSMh9QEaeWNG7oViBJQIaKhp Bird/uGHrTar2KnWBO7S3FIpMhAXoCMM7q+rxoUmZArGkHK9NYqW8crF7s2DuJ1jkMNu 3xOZqfzSJq3fJQDkPlbWPBjRlDbvNYc38pbIGwWxe/A8R8HHEKKnQuAYEAWyM6VHESct VL31TpnAGqoOyPqQPiHYqNmYORDH63mL2sOFc7lJXfXqMd9CKeBgu5nhEKO/S1DozA6O L/irU7axyzh6z4xQOKWuYemRqg2KYTQ2crNgZB9U65KMCo1d0OZv53WOp+Ja9tiXBODS aLMQ== 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=UBpEiyiTi6ndGYVbJ4NPCs5a/8XqveZV2uEeKiuXCzU=; b=GpLsEiXgfBPO2xUxseuVtzxmV1+J/S7KZpRtlCU/ht5FTCX/31RNuDKDEHbVdp6h3R ryUD1N/SD121fUPElahYLyGYoTlw9F9kpLhZmEzS7A6y7elJTdcNomiifI/Kq77TyE1M DhVbPuztA6cHRXmQH0cp12HU6PGX6/SL8Ywtq7KE0dwL6Ius6E4ieq8MOkiR8VIU++FQ Em31kdEVppVr+ikala6M9GlbfUWkPdfj/m+KvOAPtGPE+mmfwRVFjQyYi2aDhbNp1KWj BQJ26hcfyUP9iqZ89PqRESXoDBgBOK5nEeGKKyB9rzBcRFXEOb1odMt7pdhUlvAd/ujE wI4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=prSI+ab1; 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 w24si1023846ooj.34.2020.04.07.03.28.53; Tue, 07 Apr 2020 03:29:04 -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; dkim=pass header.i=@kernel.org header.s=default header.b=prSI+ab1; 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 S1728728AbgDGK0F (ORCPT + 99 others); Tue, 7 Apr 2020 06:26:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:36862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbgDGK0C (ORCPT ); Tue, 7 Apr 2020 06:26:02 -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 4A49F2082D; Tue, 7 Apr 2020 10:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586255161; bh=TorpH4uEST+U3yxKOkCZL/m53n9xz2lDBNqCEdKUsyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=prSI+ab112bbw4dTnIPAXRWID7LqEeq8w1y44QgJnsxtTUqVm2GBxYxxE30p+3Lch FJ2FXftIukuLnP9wy11gHya54ztFJ4H/lIk9OAxoOiU4rpIEwrgWeiKnz/T9m6f+61 qOvhx2mLemAdYAAabFdx7QAiDbVYyhj7I9DP7l2U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Johnson , Srinivas Kandagatla Subject: [PATCH 5.5 27/46] nvmem: check for NULL reg_read and reg_write before dereferencing Date: Tue, 7 Apr 2020 12:21:58 +0200 Message-Id: <20200407101502.416106818@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200407101459.502593074@linuxfoundation.org> References: <20200407101459.502593074@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: Nicholas Johnson commit 3c91ef69a3e94f78546b246225ed573fbf1735b4 upstream. Return -EPERM if reg_read is NULL in bin_attr_nvmem_read() or if reg_write is NULL in bin_attr_nvmem_write(). This prevents NULL dereferences such as the one described in 03cd45d2e219 ("thunderbolt: Prevent crash if non-active NVMem file is read") Signed-off-by: Nicholas Johnson Cc: stable Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20200310132257.23358-10-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/nvmem-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/nvmem/nvmem-sysfs.c +++ b/drivers/nvmem/nvmem-sysfs.c @@ -56,6 +56,9 @@ static ssize_t bin_attr_nvmem_read(struc count = round_down(count, nvmem->word_size); + if (!nvmem->reg_read) + return -EPERM; + rc = nvmem->reg_read(nvmem->priv, pos, buf, count); if (rc) @@ -90,6 +93,9 @@ static ssize_t bin_attr_nvmem_write(stru count = round_down(count, nvmem->word_size); + if (!nvmem->reg_write) + return -EPERM; + rc = nvmem->reg_write(nvmem->priv, pos, buf, count); if (rc)