Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp718967rwb; Wed, 16 Nov 2022 06:52:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EWWAOmpkwqfxQv4l6REFwSpdIroSUhAa4iaeRNpplDA0rPm46TN6GOh3ia64s9DuPWMi7 X-Received: by 2002:aa7:cb48:0:b0:461:d2ab:3e05 with SMTP id w8-20020aa7cb48000000b00461d2ab3e05mr18722325edt.286.1668610374731; Wed, 16 Nov 2022 06:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668610374; cv=none; d=google.com; s=arc-20160816; b=PCWUDtAekbNLbBLe7E2xz72inPPr9Q2pbhusYcoMV+5Gu1fL7niye5QeW8AZa0+0fZ GTkxYDbmtj9/P7FD7Zc1G9OUHOCj25v/o+Zc158vrcWovTXRpB5UyqwJIUm9q+7EVfe7 FD0j6GIUwbH9okM3kM38yJi7HVJlmKZehoUll1F4zic3cKTbVURh4Klc2gASC8vUU0GH n6+jKFQ1bO1d8Ok5PRVATiOAB8cxhFhBIrHEEnnh9Q4i35ykk+D75Gq9GYh1T1Cbof+d OhOb3letm9VMr8nblx81C+xA6Mto2P7Vm/wRtw+e1tsoliSkHrFs7vE9rfWOEZ7ieL68 MI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=80yM10P6dCcp8pBUJzplEjTBIW102mkLZiVgDVFS9J4=; b=mGYnIohA8DgPQwrUpS5vqg212tMM9feSGhXcXhAdzxRUJJGQ2vHgUeOH5tvXzaxFsC a0C5Pp/Un7NkrFIN7nQrusETMCfu1tT4FpEdO1FeVqborIZhvbQUl7amzH/3adQA/29C BpXiiMCnR9XLCOTmrF4HoMhhRLaT5UT+RrFJ/t+OE8Fgzg/+A7PJKKTS5E5HMQ23eAWV 2nkYH6UqKZzJQUNoqHAZqZcyWk3oyLxFJMmmqzvIjsC0sM2Lh9TCFsDV2aNdjFlLRJlu ErwFmKVzHw3NeJzlLcfwTXlUlTqrf8G1Z3T4Ufn62Hy92ImOjVD2BeOfmmFTK677vsm8 tC8g== ARC-Authentication-Results: i=1; mx.google.com; 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 dt10-20020a170907728a00b007b28c65347esi1249150ejc.695.2022.11.16.06.52.32; Wed, 16 Nov 2022 06:52:54 -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; 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 S233463AbiKPOhr (ORCPT + 91 others); Wed, 16 Nov 2022 09:37:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233452AbiKPOhh (ORCPT ); Wed, 16 Nov 2022 09:37:37 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F6942871C; Wed, 16 Nov 2022 06:37:27 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4NC57M42dnz9xFg4; Wed, 16 Nov 2022 22:30:39 +0800 (CST) Received: from roberto-ThinkStation-P620 (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCXgm+C9XRjFB1tAA--.18710S2; Wed, 16 Nov 2022 15:37:02 +0100 (CET) Message-ID: <700dffccdfeeb3d19c5385550e4c84f08c705e19.camel@huaweicloud.com> Subject: Re: [RFC][PATCH 4/4] security: Enforce limitations on return values from LSMs From: Roberto Sassu To: Paul Moore Cc: 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, jmorris@namei.org, serge@hallyn.com, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu Date: Wed, 16 Nov 2022 15:36:46 +0100 In-Reply-To: References: <20221115175652.3836811-1-roberto.sassu@huaweicloud.com> <20221115175652.3836811-5-roberto.sassu@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-CM-TRANSID: LxC2BwCXgm+C9XRjFB1tAA--.18710S2 X-Coremail-Antispam: 1UD129KBjvJXoWxurW8uFyUGw48XryUJw4rAFb_yoW5Gr4rpa y5JFy5GF4v9r47AwnIyw43Zw1Fy393Gr4UJr9Iy347Zw15trZxKr40k3WY9FyUCr4S9w1j yr4YqF93Ca4DA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZ18PUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgASBF1jj4GDggAAsl X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 Tue, 2022-11-15 at 21:35 -0500, Paul Moore wrote: > On Tue, Nov 15, 2022 at 12:58 PM Roberto Sassu > wrote: > > From: Roberto Sassu > > > > LSMs should not be able to return arbitrary return values, as the callers > > of the LSM infrastructure might not be ready to handle unexpected values > > (e.g. positive values that are first converted to a pointer with ERR_PTR, > > and then evaluated with IS_ERR()). > > > > Modify call_int_hook() to call is_ret_value_allowed(), so that the return > > value from each LSM for a given hook is checked. If for the interval the > > return value falls into the corresponding flag is not set, change the > > return value to the default value, just for the current LSM. > > > > A misbehaving LSM would not have impact on the decision of other LSMs, as > > the loop terminates whenever the return value is not zero. > > > > Signed-off-by: Roberto Sassu > > --- > > security/security.c | 34 ++++++++++++++++++++++++++++++++++ > > 1 file changed, 34 insertions(+) > > Casey touched on some of this in his reply to patch 0/4, but basically > I see this as a BPF LSM specific problem and not a generalized LSM > issue that should be addressed at the LSM layer. Especially if the > solution involves incurring additional processing for every LSM hook > instantiation, regardless if a BPF LSM is present. Reading your > overall patchset description I believe that you understand this too. Yes, I had this concern too. Thanks Paul and Casey for taking the time to reply. I liked the fact that the fix is extremely simple, but nevertheless it should not impact the performance, if there are alternative ways. I thought maybe we look at non-zero values, since the check is already there. But it could be that there is an impact for it too (maybe for audit_rule_match?). > If you want to somehow instrument the LSM hook definitions (what I > believe to be the motivation behind patch 3/4) to indicate valid > return values for use by the BPF verifier, I think we could entertain > that, or at least discuss it further, but I'm not inclined to support > any runtime overhead at the LSM layer for a specific LSM. Ok, yes. Patches 1-3 would help to keep in sync the LSM infrastructure and eBPF, but it is not strictly needed. I could propose an eBPF-only alternative to declare sets of functions per interval. More or less, I developed an eBPF-based alternative also for patch 4. It is just a proof of concept. Will propose it, to validate the idea. Thanks Roberto