From patchwork Wed Dec 11 15:06:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181228 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp901528och; Wed, 11 Dec 2019 07:11:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyy4kVX4Q1LiO7JzmeZp01JXg39V1xxCz8bFkwI1fVn9crx2rfonVDHugshKmxHI80MWQ+s X-Received: by 2002:a9d:7593:: with SMTP id s19mr2478625otk.219.1576077065785; Wed, 11 Dec 2019 07:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077065; cv=none; d=google.com; s=arc-20160816; b=ImdKLaw9EQD+dSLNQakun7o+zFdiXiioyU/EDpWF+TP2jUhR3otFNeFH951yq/8q13 FUci5lgyyASeILVyuhIs2CUWE44QLMnh30GI+1hNs6X9VCnWNEehOG5Vx1KsMaU6pvB5 sQygnuUwlEpfjVn+uMYOr07+SOSakYWSmouG8K7Tp/7V8N6u017J9IjCWCbROJWfScJX DOnFw+p+7+FuPcxTjy+aumRF14xmEgs3cpk15jwrjLluGmvmGyiir4tz+HPqtSXvn9b+ Dmx8ukJdHSk+ghLfLaElBC6xOjBnJe8lRT7hInQS96GM5uIsjKoD2lySKEpVQKiOdKYd sXWg== 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=UhOp/l3ujFqz6RAm/8VTdFIsvCu9tVGgETC5hzpHcUo=; b=oaQuPuEuM4v4xXhNXdiKr9L0Ac3zYg4ZTQDP6cJeRvMIzCd6l2SQjY9mJ2XHjcuhf7 S1lDjE1fF3f7IbwIrjdIDW94voA3aWl7SmUWGMqzpjtlOHkqU1ORTysQCEBNZBIx8FI9 ippumAhgwBlz/NI4adyWBoxrxYRp1RKite+ombFU5yGocp7fGhOMszBipvrAzo4Qm53Z 9JBh0q3DAfibG5O7a+4acJpUPg4l1FomI6gDJMFrqW6X1ZzQHYOfj8Mp++z/emcJ+SOK /AAl6Fpt41JEpCnmP+F/exuKnIvYFBfHlUi6ph4ihTTmNCW4feJpYjOBsKqiXwi65pmN feUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zR38MCXq; 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 r6si1225337otn.216.2019.12.11.07.11.05; Wed, 11 Dec 2019 07:11:05 -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=zR38MCXq; 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 S1730237AbfLKPLD (ORCPT + 27 others); Wed, 11 Dec 2019 10:11:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:59482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730862AbfLKPLB (ORCPT ); Wed, 11 Dec 2019 10:11:01 -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 D2DE124656; Wed, 11 Dec 2019 15:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077061; bh=bMEM8CgX/6uIErmN9B5ttGlNi4wBwVVcAmuXfFf4Z8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zR38MCXqQRVg8vMJ0vx3RJB8EYorFw7AVeg9JexgvLwNLKf3vEEhANg6ZLjBH0guI dYqqs/0Xd/bnOTsoxF6PR9Cnnv+OM3x/zZ5JvoWKdg9gBG+Ke3QW+zfm5hSca1dcW6 Fqm1jYq3LV749v5s8qGJnDJLePX9Tt/eWQk1gR8o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Viresh Kumar , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 82/92] RDMA/qib: Validate ->show()/store() callbacks before calling them Date: Wed, 11 Dec 2019 16:06:13 +0100 Message-Id: <20191211150300.723842793@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.977775294@linuxfoundation.org> References: <20191211150221.977775294@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viresh Kumar commit 7ee23491b39259ae83899dd93b2a29ef0f22f0a7 upstream. The permissions of the read-only or write-only sysfs files can be changed (as root) and the user can then try to read a write-only file or write to a read-only file which will lead to kernel crash here. Protect against that by always validating the show/store callbacks. Link: https://lore.kernel.org/r/d45cc26361a174ae12dbb86c994ef334d257924b.1573096807.git.viresh.kumar@linaro.org Signed-off-by: Viresh Kumar Reviewed-by: Greg Kroah-Hartman Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/qib/qib_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/infiniband/hw/qib/qib_sysfs.c +++ b/drivers/infiniband/hw/qib/qib_sysfs.c @@ -301,6 +301,9 @@ static ssize_t qib_portattr_show(struct struct qib_pportdata *ppd = container_of(kobj, struct qib_pportdata, pport_kobj); + if (!pattr->show) + return -EIO; + return pattr->show(ppd, buf); } @@ -312,6 +315,9 @@ static ssize_t qib_portattr_store(struct struct qib_pportdata *ppd = container_of(kobj, struct qib_pportdata, pport_kobj); + if (!pattr->store) + return -EIO; + return pattr->store(ppd, buf, len); }