Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7393850rwb; Tue, 15 Nov 2022 11:34:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Z5MDRanARTmbt/PUbdNBCQr2TbrMPy6qqqB4ikMomLQb/SphgbA9EAkEx2KnZdRl4HtwL X-Received: by 2002:a05:6402:515:b0:456:ee32:799b with SMTP id m21-20020a056402051500b00456ee32799bmr16237691edv.2.1668540896919; Tue, 15 Nov 2022 11:34:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668540896; cv=none; d=google.com; s=arc-20160816; b=lDonpVS9jyV6/s9M+Oo1lXWV5WS3D3mFOM3VWO4T22Yjh5TxiRXFbOzYGH4osmh30X E1n4Hy6T+HUJTbLL4SvsP7Q79x6W77pVYd/uIju4pUyYH0TsCQzAnLyT7yc8z4taKFYp knttvIwp2NV/y1Rf6nJVisVFInkQ3A5Pd5GyMEQTEVw/hL4zgWKITd1K5jxl/jo87PzG qOzaZ2IVgc7ZcR8Mr9ZHgSVdwRJkyuZul/SP7iHuvbLcDrahuQ5p3yRndH8QUKKYNutd 9o+KYRnzZmJngFdkoW1XAEyuvao0VZYuLVp5sPVmbLWnQERcNw5gZ0pzutl9qAk9Jsg4 6XyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=egkqihs2sr0oF22jXEFl2ODKUB6NoHIRqyFESnR22Po=; b=pzr8DrYpqzpMD7jpLB9ZrUykYzrnMJVx1ieKEv+jtrlgJg0ICojZxQ72Ush+H3aRn0 lOB0QlcavH15rUyFBezdFcDkxz2nXQwhnQsHEVdVyZdHojQtXUSxQRm9GmvMt/HZHfaM J5ORd7kQ7ldPBAZqZvTrEFWqmLTrIyusD7DMylsDE6u/iV7oHdveEJ2DDh2dPUkbaY9X g9+zsbi4oRFB0Ml5Qk6mrBpKuvNHN/rPvF3nIV8H34B668cf9ruHVIkKOFcU549ni9m+ TXwdHeIbEatW+IbrKDxGb2Z3Ghj/sQtQwAKesUErvaYGSPQOXQy8+0XHUJhO9o7kSE2R w6oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="KG3/FWNc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a056402269400b004637e16cfa3si14263520edd.598.2022.11.15.11.34.19; Tue, 15 Nov 2022 11:34:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="KG3/FWNc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbiKOSlq (ORCPT + 90 others); Tue, 15 Nov 2022 13:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbiKOSln (ORCPT ); Tue, 15 Nov 2022 13:41:43 -0500 Received: from sonic307-15.consmr.mail.ne1.yahoo.com (sonic307-15.consmr.mail.ne1.yahoo.com [66.163.190.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9538D2B611 for ; Tue, 15 Nov 2022 10:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1668537701; bh=egkqihs2sr0oF22jXEFl2ODKUB6NoHIRqyFESnR22Po=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=KG3/FWNcT9TEoxHxWqSuubdZnALbuRRJE8rvpivuFRBId2c6fbf/qUeQvlNEFjzAYEYlylGf/XKCt7xiimD25ehwZj/V316+gmlSd3WYzRuyJz2AuiZOywivX4TQ6mtHdw/lWjA/7qZeagc2cKWu9ZJwRQhuNPu3vsvebwV7oZtMsk4Vuawkd4Q8dhgpKdreThXHCrbqxZrjfAMd3RIevqYMmVWZL21ZcnRQgp7Nk2EhxElqKrqEWTREXMqdY5mPxeJsaec9ODMVo9OUePtHHtrrslDgLo5Ni2hACgx4//WTIR4r7Slyt982IFC45xhGqq5MAmqrCN+pfCnBKYbuZQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1668537701; bh=GV9vfvzuRmUmikfPnShy3dm10p8aECsF1GFLC6wwqhe=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=Du8Tf4jDq9yuYpK3nYt4Xj3SWH+iFJPyDh58JhVpRJhaT2F20Lhg8i4zQfr9nlfS8M5YoweJXvgZl6RWJMhsVA2UeD/5QtZyS4ik7z/NfbqeXtOYMd9iJYkksEgDf83GPYg0KTzyGvt7obDO23MilXEQpAhtjK5ceXbmm292WWzg5fMOBKsE5ltFQH35TfRUQ6RBqMsQDXgoTxrs38BbIf2QFLQCbcvSxFszAWPGYLPo3H5yEeouS7qwINDoOyNeg6gkhV1WB/5DHQYCJOLxaYEW3PToBcC/+AosJW/PQmRocY6lZ+l6XxTgNQrkFhll0887wAUZcML4oB2lzxbaUQ== X-YMail-OSG: PtPiVa4VM1kxOR.C3vYFXqjEWnIpTEK631Q8btYdK1sYE5yfvkGXYsC0vEMkrUm kJW4jGwC159u2920gdaWhS0p8PNVPsdt74GOlu83X8S8D1A_bPRmAMAX48GkUKTUdh8PMGQ7b.Uu c.f4VYCJQlqwqEXCL9unXRy02V_eZToqPjoaJdz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1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Tue, 15 Nov 2022 18:41:41 +0000 Received: by hermes--production-bf1-5878955b5f-kkjj4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID c17cf4ef8fd2f159571973f2179af8ed; Tue, 15 Nov 2022 18:41:38 +0000 (UTC) Message-ID: <8a52c1ca-c7cb-62a9-711c-532c33b5d40c@schaufler-ca.com> Date: Tue, 15 Nov 2022 10:41:34 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [RFC][PATCH 0/4] security: Ensure LSMs return expected values Content-Language: en-US To: Roberto Sassu , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, revest@chromium.org, jackmanb@chromium.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: bpf@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu , casey@schaufler-ca.com References: <20221115175652.3836811-1-roberto.sassu@huaweicloud.com> From: Casey Schaufler In-Reply-To: <20221115175652.3836811-1-roberto.sassu@huaweicloud.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.20863 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/15/2022 9:56 AM, Roberto Sassu wrote: > From: Roberto Sassu > > LSMs should follow the conventions stated in include/linux/lsm_hooks.h for > return values, as these conventions are followed by callers of the LSM > infrastructure for error handling. > > The ability of an LSM to return arbitrary values could cause big troubles. > For LSMs aiming at being upstreamed, this event is unlikely, as each LSM is > carefully reviewed and it won't be accepted if it does not meet the return > value conventions. However, the recent introduction of BPF LSM allows > security modules (not part of the kernel) to inject arbitrary values, > without BPF LSM verifying them. > > The initial idea was to fix BPF LSM itself. However, due to technical > difficulties to determine the precise interval of return values from a > static code analysis of eBPF programs, the new approach was to put the > fix in the LSM infrastructure, so that all LSMs can benefit from this work > as well. The LSM infrastructure is a hodgepodge of inconsistently defined functions. That makes them difficult to deal with in any sort of consistent way. Your attempt to make them more rational is laudable, but falls short of being useful, while slowing all security processing to no end. I don't consider this a "fix", and I don't see how it benefits any LSM other than BPF. Adding return code checks into the infrastructure code is insufficient. If someone adds a bpf_secid_to_secctx() eBPF program you're going to have a whole new set of problems that this clutter isn't going to help with at all. Return values are an important part of the problem, but nowhere near the whole of it. Please take this back into the BPF security module, where it belongs. BPF isn't playing by the admittedly complex, inconsistent and arbitrary rules of the LSM infrastructure. Your proposal doesn't change that, nor does it sufficiently change the infrastructure to make BPF safe. > > The biggest problem of allowing arbitrary return values is when an LSM > returns a positive value, instead of a negative value, as it could be > converted to a pointer. Since such pointer escapes the IS_ERR() check, its > use later in the code can cause unpredictable consequences (e.g. invalid > memory access). > > Another problem is returning zero when an LSM is supposed to have done some > operations. For example, the inode_init_security hook expects that their > implementations return zero only if they set the fields of the new xattr to > be added to the new inode. Otherwise, other kernel subsystems might > encounter unexpected conditions leading to a crash (e.g. > evm_protected_xattr_common() getting NULL as argument). This problem is > addressed separately in another patch set. > > Finally, there are LSM hooks which are supposed to return just 1 as > positive value, or non-negative values. Also in these cases, although it > seems less critical, it is safer to return to callers of the LSM > infrastructure more precisely what they expect. > > Patches 1 and 2 ensure that the documentation of LSM return values is > complete and accurate. Then, patch 3 introduces four flags (LSM_RET_NEG, > LSM_RET_ZERO, LSM_RET_ONE, LSM_RET_GT_ONE), one for each interval of > interest (< 0, = 0, = 1, > 1), and sets the correct flags for each LSM > hook. Finally, patch 4 verifies for each return value from LSMs that it is > an expected one. > > Roberto Sassu (4): > lsm: Clarify documentation of vm_enough_memory hook > lsm: Add missing return values doc in lsm_hooks.h and fix formatting > lsm: Redefine LSM_HOOK() macro to add return value flags as argument > security: Enforce limitations on return values from LSMs > > include/linux/bpf_lsm.h | 2 +- > include/linux/lsm_hook_defs.h | 779 ++++++++++++++++++++-------------- > include/linux/lsm_hooks.h | 136 ++++-- > kernel/bpf/bpf_lsm.c | 5 +- > security/bpf/hooks.c | 2 +- > security/security.c | 38 +- > 6 files changed, 589 insertions(+), 373 deletions(-) >