Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6851505rdb; Fri, 15 Dec 2023 09:54:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjxrLNF+BzIbqubSKc1iinFoq4fqia0h7PIPxi+9YURiNsFb4PBkw/Lzhtp2JFqdnkjF7P X-Received: by 2002:a05:6870:d213:b0:1fb:75a:de6e with SMTP id g19-20020a056870d21300b001fb075ade6emr13628860oac.92.1702662873246; Fri, 15 Dec 2023 09:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662873; cv=none; d=google.com; s=arc-20160816; b=L3MslvLS9fgltcq9mZ7NBLS9xjUIYlp0Ach9cI4RdZqJYZAoDR86yS4ezs+dXTGQaB u173mFLVXBAOqSYcr8Xnz44AOPpOCoSlmYN5eyayuKL0/hr3iA84Be/EK11pMrAEHv9E hQ7kTxIqpcQDUfQXQI1mWmg8pzLfzCK2SJtwsbxfwo1vFzvDIauZGm7J1I3OahTRtUph /AB5Y5AeRNp/u6PXy2BtlxtKNzxmhGBX+4nBZb76+wEXUJb4mqznEUoLTU1R1lpDpeQK vj85EJ+6mmGGeUF6miTlxs40FHqiGLaq9l058fZYwQ7rdcc9dxTRc+O4kDgds4O0xgT6 8Mkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=36Al+miGLrdB9/hSzVxp15OWW+dtzN9WjkaQxb3yweA=; fh=RWkbRmo7BqJaOo1SBh1WAU3T0JppXgXH0TZkjHUCJ8o=; b=oC6XCsVISDKCXPHfitT20plwx/fOme697abyLI+XLWFMhWAvjI0uLfk2Iq7mcL1Qy/ CBK101QR839JPEm5R2jnI82ooFpdOiQ24MDeUy5VZVIGgmIa7zme+hPR0zAaucj9ngc+ eHktamfT5Rngr6vWBGLQ23pttCrnGQQk1xqxgiflceNQwi2vqYTtptzYpO6hp/LgO1aH 0CQ23pbmkDV2Y4qtXY+m7ogWvJhF8BbGKRcJtpfUQMha8INtSZxHLLQdFqBxERiTVTAk wqods/GppAYKzvSh1XE174noncgavcA5n/8eGFhtLfL6WIllnDzEB3xM7jpc9ExKYUpD wMFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=h7l6IAz9; spf=pass (google.com: domain of linux-kernel+bounces-1471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ca14-20020a056a02068e00b005c660b46609si13734227pgb.486.2023.12.15.09.54.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:54:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=h7l6IAz9; spf=pass (google.com: domain of linux-kernel+bounces-1471-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 02AFDB22FC6 for ; Fri, 15 Dec 2023 17:52:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0F7C30103; Fri, 15 Dec 2023 17:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="h7l6IAz9" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43B3D30116; Fri, 15 Dec 2023 17:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BFERTtf024580; Fri, 15 Dec 2023 17:51:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=36Al+miGLrdB9/hSzVxp15OWW+dtzN9WjkaQxb3yweA=; b=h7 l6IAz9dvXrOvEGnjq6qJ3IX9Y9VoPQWXLAM9TuyMY0VOsVXDtfbRKk/A+MvGpRz/ vaidWxZdg/rS7FJ5yXSAmYntxPg9MSXEm5G8sM+Ht/p2iFt6qA9c2GV2QnVsP8JH v4+VAvpP79Rrvy/uUDW+3mDveHMOx42Ic+vwqm2eVSVaSdtBeDAi4qaNMMkmFPQh fQIp+nHyxf+1+f1+iIhOUS3+wFIvwoyX+FVKBFik/A/qw4n0iWCSUgMV2vt7idzh s4cE5PA2AnMnEQfBsFOlzgN4MVI4Y8Chz/N4QeuOP+btdyJwIkT8zsFBPJJVaBaz O3n4Lc0AntpSrLA+Y9qg== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v0hqchpqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 17:51:11 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BFHpB80025241 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 17:51:11 GMT Received: from [10.110.27.143] (10.80.80.8) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 15 Dec 2023 09:51:10 -0800 Message-ID: Date: Fri, 15 Dec 2023 09:51:09 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] tty: Add comments for tty-ldisc module loading logic Content-Language: en-US To: Jiri Slaby , Vijaya Krishna Nivarthi , Zijun Hu , , , , CC: , References: <1702640236-22824-1-git-send-email-quic_zijuhu@quicinc.com> <1702647690-6787-1-git-send-email-quic_zijuhu@quicinc.com> <6401ff24-c82d-4d69-9aaf-b219af9d4db9@kernel.org> From: Elliot Berman In-Reply-To: <6401ff24-c82d-4d69-9aaf-b219af9d4db9@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: CfessXSuprFdEV-b3anYUGYyHhFFnXK0 X-Proofpoint-GUID: CfessXSuprFdEV-b3anYUGYyHhFFnXK0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1011 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312150125 On 12/15/2023 9:26 AM, Jiri Slaby wrote: > On 15. 12. 23, 15:19, Vijaya Krishna Nivarthi wrote: >> Hi, >> >> >> On 12/15/2023 7:11 PM, Zijun Hu wrote: >>> Current tty-ldisc module loading logic within tty_ldisc_get() >>> is prone to mislead beginner that the module is able to be loaded >>> by a user without capability CAP_SYS_MODULE, add comments to make >>> the logic easy to undertand. >>> >>> Signed-off-by: Zijun Hu >>> --- >>> Changes in v2: >>> - Remove condition checking changes >>> >>>   drivers/tty/tty_ldisc.c | 4 ++++ >>>   1 file changed, 4 insertions(+) >>> >>> diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c >>> index 3f68e213df1f..34526ffaccbc 100644 >>> --- a/drivers/tty/tty_ldisc.c >>> +++ b/drivers/tty/tty_ldisc.c >>> @@ -150,6 +150,10 @@ static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc) >>>        */ >>>       ldops = get_ldops(disc); >>>       if (IS_ERR(ldops)) { >>> +        /* >>> +         * Always request tty-ldisc module regardless of user's >>> +         * CAP_SYS_MODULE if autoload is enabled. >>> +         */ The added comment confused me more :-) "Request tty-ldisc if process has CAP_SYS_MODULE or autoload is enabled" >> >> Without much knowledge of this file... >> >> >> What the if condition below accomplishes is evident, > > After a bit of thinking, sure. > >> it probably doesn't require a comment. > > I would not add a comment there at all. I would rewrite the code so it is obvious to everyone. Like: > > static inline bool tty_ldisc_can_autoload(void) > { >   return capable(CAP_SYS_MODULE) || tty_ldisc_autoload; > } > > And then: > if (!tty_ldisc_can_autoload()) >   return ERR_PTR(-EPERM); > >> A more useful comment would be why it does so? > > From an insider, the reason is obvious. But maybe not so much for newcomers. Well, one could document the new inline above. Like: > "" > We allow loads for capable users or when autoloading is explicitly enabled. > "" > or alike... I agree with Vijaya that it seems evident after a few moments of analysis, but we're also maybe used to reading kernel code more. I don't think we should be opposed to changes that make code easier to grok, even if they're trivial. If we want to make it clearer, I like Jiri's suggestion. One other thing I'd add is to give a reference to read config LDISC_AUTOLOAD's help text. Zijun, Please send future revisions of the patch to our internal pre-submit review list before sending to kernel.org. Qualcommers can visit go/upstream. - Elliot