From patchwork Mon Dec 16 17:47:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181763 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp4621844och; Mon, 16 Dec 2019 09:58:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw4p1PIXh4twUpw9DA/hPM4fVEpGH8/260svLVe2CL6K2IxGKBMD7DtviB9hu1C5I6dPc7Q X-Received: by 2002:a9d:6d10:: with SMTP id o16mr33987087otp.28.1576519089232; Mon, 16 Dec 2019 09:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576519089; cv=none; d=google.com; s=arc-20160816; b=pnq1cyzTGHmsFGJliyL+jhPyc4EHdb6boWbnBHxznCBlkjzTUTF7ro+ii3bGuLAiVm J7k7A76WYcLYXH2Cw9afm5043MQ2OjYRP4RznhZJebJPUommajln3Sumiv6SXWmueTsZ jPjlZGPMHdRrOsawPaJsXKAOBIdeqSg4deZHy8lwAwhHjvT3SygwJH8h1Lzi9Bk2Kz0l 3V/rDPfosFhqPnTmZSaeOZgBJv6FjDz9iVyoON5XQGWtjLdkS+GBnf+ZZ06llGxI0G5F xaCjjivHwAs6GvnK2mHXylpV093g7fzya9Zot5mopBfbmxtaG9O5XeKIzLcD6XTNsDAf ikjg== 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=SalyEWaDFgUqFpu6bM6C+eGLpnFa8VO+XY2lK/sE6HE7N1T1NCp2qEDDMrrlreYJrz 3gFcwhrfJUtsWP3v+9y16dSnX5CezKCmW6OnwEAfT6pN8yQujjw6w/MDGtuncaUJXPBY YXHcK9G9QOuNbiWw1pTR/yEw70UXUUXaQlvqHE7S6RaDAA99to2Cfn7ONxs8P1uNnmSG iH/wkXj0JXuRvAZSimvfl6Vxm3vykAMs4LenzI0g1ws2hkvNxJH/bd0TV76JqhoCFSUa ASJkA4BsGYuxXCvBEjTZs+4rwK+RkHEDePKumkDM4fxa3yLSXNOigdgQ3jUbruRRBH9p bJZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2Vv/OV4i"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 f60si11353393otf.119.2019.12.16.09.58.09; Mon, 16 Dec 2019 09:58:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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="2Vv/OV4i"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728362AbfLPR6I (ORCPT + 14 others); Mon, 16 Dec 2019 12:58:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:57596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728575AbfLPR6G (ORCPT ); Mon, 16 Dec 2019 12:58:06 -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 71C8F205ED; Mon, 16 Dec 2019 17:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519085; bh=bMEM8CgX/6uIErmN9B5ttGlNi4wBwVVcAmuXfFf4Z8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Vv/OV4ir2v2pxr5sXbyG200/DvKyQob6zQquIFJKXaieSEaKOdNWt5eS8kSxJvRT DuPm+Xq5fM6KHTESiDm4BHRhSW8o6fz6sBMKzWQGHx2a2ivJeVPwCOJQizwyXREFHx qZhvZZI/mnTyD2LMwzY14cqDX/kmPKDsNrbZNwes= 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.14 149/267] RDMA/qib: Validate ->show()/store() callbacks before calling them Date: Mon, 16 Dec 2019 18:47:55 +0100 Message-Id: <20191216174910.648241558@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174848.701533383@linuxfoundation.org> References: <20191216174848.701533383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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); }