Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp816590ybl; Wed, 11 Dec 2019 07:58:19 -0800 (PST) X-Google-Smtp-Source: APXvYqzN/N0Gg1mlZXzyvc/r5qokoKvtw04zvLkWLasApNf+oycfZlPBXzH8ksbGbnwHQxvvjden X-Received: by 2002:a9d:22a8:: with SMTP id y37mr2699124ota.359.1576079899685; Wed, 11 Dec 2019 07:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079899; cv=none; d=google.com; s=arc-20160816; b=d3adFNNsiUdJjUBcac3PfLCDxGIEwrfppJmAeRjVIVs0Hua8sq1xn1iyNAeCa87krt JhhFYvTHFgJdZuyfyXrw/Wd+A79Ox6SuKPOkEGqCyOgORZbKDTDIgUNLpoPGLdXoy4WV vPb1cObcsFWZI3euinRDc6jbJXROra5DLUobvJBIA08njrD31x69/4Z0WIT37Ycp7tfC hZxad7ePuz0DmeRr337eIrvVLVFhNQQ8APPU8imeo+fk+1ZMQiATvgkJRoeVD/P6/8B4 v1f4Td/UG+21cBpwHnRGnbgK+NIxtm0tI9mBoOkBdEW9Z9SaZZGYLTvorwkinZ1GzsJY R9RQ== 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=0ToqGGcLZNOLLqpWj23s2jj5N5J2NrI6HEWaU3n6hX+C5y2LeAGTJNKMaYatgPFEQ5 z/FWfcCL2RpNbZ5vkkeWlgaknwlkBEpMypPbFqIowakBo035c5HlNVVTVQKdrZM6VGBi IcvQFFWjDTCdQZ2bmWDiK7XpEFBR6IunJoX0CV7t9jAp0hSuF67ZuZHgaTk7mGKhkCWC DqPYMYTgnqeZOiALJPXje7bBqKyMFuj/xetal/SgaNL2cS9cy7mTf9ueu1UuMyb8vRHB ljRyNnaGHzhXznr9IuXK8nrmE45lNFtJOC0CutKMv05pArIdfRT0ndqQ+tAI1CzebP8Q eLvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fVzuyl3Q; 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 v9si1398308oic.251.2019.12.11.07.58.08; Wed, 11 Dec 2019 07:58:19 -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=fVzuyl3Q; 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 S1731724AbfLKP5F (ORCPT + 99 others); Wed, 11 Dec 2019 10:57:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:41284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730821AbfLKPPR (ORCPT ); Wed, 11 Dec 2019 10:15:17 -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 E0E4424654; Wed, 11 Dec 2019 15:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077316; bh=bMEM8CgX/6uIErmN9B5ttGlNi4wBwVVcAmuXfFf4Z8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fVzuyl3QbVp58nLw8ZDixxTGDWA0rigQ6sGrlPXl6MVMhpQn5FcW1V3rrDCPUsnyk k71hVPWyYOfdU8rdACZp0dAeDhjMN2QqiG/6/sMcm9jTDqfPlqcaE3GC4H8wNdUVPt Ask8T1Vrk/8nW3pNt/MCnNqHuIhStHdzo04xVQEQ= 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.3 099/105] RDMA/qib: Validate ->show()/store() callbacks before calling them Date: Wed, 11 Dec 2019 16:06:28 +0100 Message-Id: <20191211150303.441176134@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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: 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); }