From patchwork Wed Dec 11 15:06:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181248 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp921045och; Wed, 11 Dec 2019 07:26:26 -0800 (PST) X-Google-Smtp-Source: APXvYqweHzrkjxcdJToTaAZ9rypjkoY5QpvnqobxIRaeYM6YF8ie2isOIU7OulZILWs/B00EtVV8 X-Received: by 2002:a9d:6396:: with SMTP id w22mr2738355otk.364.1576077986351; Wed, 11 Dec 2019 07:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077986; cv=none; d=google.com; s=arc-20160816; b=IvoeDyOR64Ug1c9BOZ8xI9h8Wyz4T2okQQyHhGh04veS9IinJN9ztPy2GZcpS8PM7z OSha6QYXS4Ng1WaG0rBGiZav7irt/8ME67MqCdhbUcdMyFrGaN+m/smmfSqVranb4byg 4gZj2nx8HQ1uIZDfaWqdTJVrtoSHj68+PEwNFa1U1i+JYssrQX1h2IILpH194cA0/+Oc cv48QJx85LsdsWLFGA+w9fZf7UbrG9xSj5PwyUjGWXYjUN9u085B9qOeXZOzYFvlE0zR L8hg/yeqgF0j1gLPAUNqf6Pjw7o7E13GM6sM3M3+zmTgyk1JKApXTqaCFPn5+ba21GWe GFew== 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=iRrQ7XyIsuHNKGSQz3kvubZ0jarX3LFpFNvIERf/CVd4zP5Bt2FfNUNJ6awzHTBUMe u/zo07r4d/+pF0Sm456h+0VhztoNRtJmAqPa9oEpLcfOOasGHNOj8cv11mBzzUn6/0Ed 0ORMcmg+cqH00hZpD4kG8EpXYa1qCWhOqLRK5ImiGQ86eeSaDuDC1pZGAEjRE8LuLqup OSJBIu25C5kn4sHWmzL8vjEX5fvNI1TQ16UAM8d+rjU7IVScQC6CgwiPX8KYdpF21FXc LzamIyPzI8eDhhZA1hfHm/A2OxyFUPr+G0jIVcmIr3MHTLYtv2PmK3ZFvO0QsIcYgA3a YFFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ugZx38xq; 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 z25si1303201oto.211.2019.12.11.07.26.23; Wed, 11 Dec 2019 07:26:26 -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=ugZx38xq; 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 S1733081AbfLKP0L (ORCPT + 27 others); Wed, 11 Dec 2019 10:26:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:58924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731095AbfLKP0D (ORCPT ); Wed, 11 Dec 2019 10:26:03 -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 4683E2077B; Wed, 11 Dec 2019 15:26:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077962; bh=bMEM8CgX/6uIErmN9B5ttGlNi4wBwVVcAmuXfFf4Z8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ugZx38xqhotAWnWlB+tyu8dyndm9NgE3kvSkaWua2yhlxBWRAEm3zuBFgQ3Hd5/jz lmVeVHz8kgY+R1LCh4N+GLOMu9ZhrIXXg3ZbS1LMqmT/zrrPQHgrZGLG2oRQHD/JI1 3EDKk69blEzD4jz0svYXk/+7SoDBcGkMpj4dp3eE= 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.19 238/243] RDMA/qib: Validate ->show()/store() callbacks before calling them Date: Wed, 11 Dec 2019 16:06:40 +0100 Message-Id: <20191211150355.402771505@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150339.185439726@linuxfoundation.org> References: <20191211150339.185439726@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); }