From patchwork Thu Dec 19 18:32:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182159 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp854555iln; Thu, 19 Dec 2019 10:39:51 -0800 (PST) X-Google-Smtp-Source: APXvYqywFCD5N0ba6Z8zDTvEEkOP3vXmhuIVLiAKcxbFMtyXnYoIInPf17jpZwBJgWs6syXHkwtW X-Received: by 2002:a05:6830:1407:: with SMTP id v7mr10527059otp.58.1576780791837; Thu, 19 Dec 2019 10:39:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576780791; cv=none; d=google.com; s=arc-20160816; b=na0hE0S8cOVzFwsuk9TtphLgW6tb2+rVE1jMtwkFZQywiaAdmowDbv0NpjBr6vU8jS +/GSmitN8uLw2Ez2LA2cQoVqlO54c5LGXaCzTriRnpm0QoLPD7IKyF1GEKd3VU8nmVve bYQmu2o1HZMeAj/3/luawnrYReKtIHuBoQjjoEOVmtWIg1+ipPoiXU3N5/QCuC2TUJyY 1xHmc2WUPjmrs5/SRsIjfbiDkb3KUgfGSwmJN9sotCDm/kAPUp5me0I0imsG6QCQ48Ps z+MdD4Sf4y+h1Kc5G4V5I05/lhXS2/LgzO4Fdn2UOuWTW+VsrBzxR6YgDB/m1D8w0ljf vvxA== 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=uoI4mqxO34JfjyRcGxhFETEW1g5pwlPHhXJ1MLDALforVNXx0ghOJT1DYoQkQRuk0X vIZ8IfYlPTQA1u0a3uiweDrOCE8S18J46+t+XhECKigLHJ/2VPso1ZxQX9DhztQVNmL6 U0Q4KvMPzEMgxoUwQKX/mwdZlqOvdb48xTUvTy7vt966cArwik4VvFJB2qNeF5/hvPi3 qHNm39aSVTDbBTwV2jfMM2r8WJAL8m+fLXwwHEj3HGmMyACXGyG0AYvXSU0j8YBDiMr0 LhSlUDzeqWfSU3TWnMDaYzyChZ/na8IM5AG787eGMmqXhhzVg8hYCFJN5s6Ahc6Gv8vg TFGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SsJkkgju; 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 j16si3603869otr.69.2019.12.19.10.39.51; Thu, 19 Dec 2019 10:39:51 -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=SsJkkgju; 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 S1728288AbfLSSju (ORCPT + 27 others); Thu, 19 Dec 2019 13:39:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:58272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727980AbfLSSjs (ORCPT ); Thu, 19 Dec 2019 13:39:48 -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 D51BA206D7; Thu, 19 Dec 2019 18:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780787; bh=bMEM8CgX/6uIErmN9B5ttGlNi4wBwVVcAmuXfFf4Z8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SsJkkgjuVbytuqrCY0aDQ3JHaMQ50TPjldHBU3AyLaJpAOJuoi5P0Nkp62OBVtCvI BVmai9aiV+S/NeNCYs/Y+wKOvZY+OXH2rejdMQDBOVvpbk4qJJ9SQbHVAey9F41uRh dpaER00qXLA/mlvRGyjL2WUTnUa2jyGUWDUt4MJ4= 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 4.4 069/162] RDMA/qib: Validate ->show()/store() callbacks before calling them Date: Thu, 19 Dec 2019 19:32:57 +0100 Message-Id: <20191219183212.021314208@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@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); }