Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp819588pxb; Wed, 13 Jan 2021 17:24:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYXACm9oEkHINWK49ArRY1pTOASidr2ceq+mtZ3x8a7Px611Uk6g6yrGZ/P9jpj7ksK1cl X-Received: by 2002:a17:906:4d8d:: with SMTP id s13mr3516423eju.305.1610587452263; Wed, 13 Jan 2021 17:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610587452; cv=none; d=google.com; s=arc-20160816; b=ItieFgEZH6IFI3LymF7nZB+LLwyeYiJDx9bRqaXX/lRxIHB95wkyKEl1rq25ODECkO esnlwSWCt3Hllu2c/U/vKNp+o6jqOhFnOqt5o6eemfjO+5Z6iDYe1B8phlKht5q0lNoo Jto4IMvJ4VA0YZi0PUeaVcfH280o3CTcyDpF67GuCuxK38E5Rccs3BNEZw5VJnrtxjax J7eVXVge/S78s0jiYJwTO6V1uHkn49wJhdyR46xreg3RQAHKTcrxTU4X19IMFS8N8rON 3TfPgltECLEtZCZpWxMUTMlmvY6MDsutEuYMT4WAHeqTDOzLjcf0WnpNLdokVRtOWa80 dDWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=kslj8Wj8U87VV6ybtvsgQSgYNIBVEXh0ztirzXBMiJ0=; b=avXdl8hpMuc8zI815fCuvAEa82JZ1E1rC1x1c7oqFUBZJWhBXhZ7BNaUAbPPoD+D8q nd12mynwD6pLLEqW97THa/uvNjOonOIL/u0r2Sm1uXfxzihz3D411wSrVYz3g1HKYmRE +vZAKHGVj3OzuFSnmbcZWn8iSkG3tjUtUNj1VZqIywzRmthcuSvJ7NCSUiGJjkx5S+v4 BWQHmKeA4NMMCMur4110TqyhH9X9jJQacMjkugQ0VJbxVR0Qe6cGAbYkUnva06IzpLy1 zj6oSpVakIE4vzLvxA+FHCwSzzeUMp+ufJx8F7WNvEqNrqqoJuzcEAAxXzlFsXu/kQ94 g4jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=jQn9ZBvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si1956286ejj.425.2021.01.13.17.23.45; Wed, 13 Jan 2021 17:24:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=jQn9ZBvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbhANBV5 (ORCPT + 99 others); Wed, 13 Jan 2021 20:21:57 -0500 Received: from so254-31.mailgun.net ([198.61.254.31]:50912 "EHLO so254-31.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbhANBTP (ORCPT ); Wed, 13 Jan 2021 20:19:15 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1610587132; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=kslj8Wj8U87VV6ybtvsgQSgYNIBVEXh0ztirzXBMiJ0=; b=jQn9ZBvT5v57TrMgjFxJDhglSZbDcPEfRPR/rNUu9nM0l1oz5EDNbG+PO+vHWETGlZsE3PFc 1pa1oS0erE1DMwJbhm+E1FS08HgV90dZxBPO1HygEwrDrs0xa9Ypg8wD8/fNdnOl/6l6daWo rh9mooEpFTwjYx+OXNIwetfOfWM= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-east-1.postgun.com with SMTP id 5fff94c9c88af061078450dd (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 14 Jan 2021 00:48:09 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 01AD9C43467; Thu, 14 Jan 2021 00:48:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3C32BC433C6; Thu, 14 Jan 2021 00:48:06 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 14 Jan 2021 08:48:06 +0800 From: Can Guo To: Adrian Hunter Cc: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Matthias Brugger , Stanley Chu , Bean Huo , Nitin Rawat , Satya Tangirala , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: Re: [PATCH v4 2/2] scsi: ufs: Protect PM ops and err_handler from user access through sysfs In-Reply-To: References: <1610546230-14732-1-git-send-email-cang@codeaurora.org> <1610546230-14732-3-git-send-email-cang@codeaurora.org> Message-ID: <6908e7103529d12fd6ca0e5fa696b4bc@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-13 22:53, Adrian Hunter wrote: > On 13/01/21 3:57 pm, Can Guo wrote: >> User layer may access sysfs nodes when system PM ops or error handling >> is running, which can cause various problems. Rename eh_sem to >> host_sem >> and use it to protect PM ops and error handling from user layer >> intervene. >> >> Acked-by: Avri Altman >> Reviewed-by: Stanley Chu >> Signed-off-by: Can Guo >> --- >> drivers/scsi/ufs/ufs-sysfs.c | 106 >> ++++++++++++++++++++++++++++++++++++------- >> drivers/scsi/ufs/ufshcd.c | 42 ++++++++++------- >> drivers/scsi/ufs/ufshcd.h | 10 +++- >> 3 files changed, 125 insertions(+), 33 deletions(-) >> >> diff --git a/drivers/scsi/ufs/ufs-sysfs.c >> b/drivers/scsi/ufs/ufs-sysfs.c >> index 0e14384..7cafffc 100644 >> --- a/drivers/scsi/ufs/ufs-sysfs.c >> +++ b/drivers/scsi/ufs/ufs-sysfs.c >> @@ -154,18 +154,29 @@ static ssize_t auto_hibern8_show(struct device >> *dev, >> struct device_attribute *attr, char *buf) >> { >> u32 ahit; >> + int ret; >> struct ufs_hba *hba = dev_get_drvdata(dev); >> >> if (!ufshcd_is_auto_hibern8_supported(hba)) >> return -EOPNOTSUPP; >> >> + down(&hba->host_sem); >> + if (!ufshcd_is_sysfs_allowed(hba)) { > > I expect debugfs has the same potential problem, so maybe > ufshcd_is_sysfs_allowed() is not quite the right name. I noticed your debugfs change - currently it is only printing error counts recorded in hba struct, which is fine. Even in this patch, the check is only added for those entries which need to talk with HW. Sysfs nodes like show/store rpm/spm_lvl does not need this check. Thanks, Can Guo. > >> + ret = -EBUSY; >> + goto out; >> + } >> +