Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp363593rwi; Wed, 26 Oct 2022 01:46:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6FhEojWwH75uFs4nPHEUuF2gkJmjZwGT9LcWB1/92ngj0m+5DjU6Y/aO687jqcL/G3gspX X-Received: by 2002:aa7:ce8d:0:b0:461:50fd:e358 with SMTP id y13-20020aa7ce8d000000b0046150fde358mr24532472edv.194.1666773998947; Wed, 26 Oct 2022 01:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666773998; cv=none; d=google.com; s=arc-20160816; b=o1c5Gv2q8GEPDrCdSSLhngeB/nLKIpPsMRk1ohhFwBN7ouqPN4A3TLGQE8fYWACwOG LKtyOEKFTNqbjyH3pzqwU0UccuIVIXwYQ99/WtoSYivtxTfZC9IqtoaJMq3YOmVPhpVu wLwp9oKQJHwowimLLA0zPCs1h7DebgJIlGUwKXApEvkTypjDbFv7nNuhwx4ioaBxfEuh uF+MYhK0TF9f9UiuRA7CI1HGtY2I7PfhGoB+Uq+T057WBy3gSrJXT+U89hv+MhUQWIfa GNFUqHTNWSwGpK+sGA5YYYUneSnhKGD5HYyXOlEoxeE3DA23mdZNblV17tu95tgZFS4d 1OSQ== 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; bh=Xk0mzRIiY4t1Yaf/pJIzUj6dhzWsDEGXwvAGKKNpf00=; b=M0xHbb7t81XeqbtjslWLX8dUXaNCs8CPq8gLY2sD16tVuh66+YQJ+zSzY9Cfu+SDgf KBK4ij0FHTwwBO2nQ64A6O9j94aqQ3jLV1aZHfrJyAZj1yU6uyCQhetkbxvKzVOLPLt/ FV0HHTc5PwsWCpdxlqmHfVVIdiC1wQrscp9VmZwHmR2jXh6knxEob1NZjvoaEG11F3C8 98sXvFobNfJp4gdj7jonxc9OWVHbBoww4lpYEKBLpTLlqSY8XCyh3ZpQKyOtmEV/cT2k yuUxU+esiMH/9V0q8L5oD+b26PgH4JN0zHQtF/+7OEDY7vsNgjgob9TGsNWACGJWcsuv fWOw== 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 x19-20020a05640226d300b0043dfc949d31si6047254edd.25.2022.10.26.01.46.12; Wed, 26 Oct 2022 01:46:38 -0700 (PDT) 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 S233467AbiJZIok (ORCPT + 99 others); Wed, 26 Oct 2022 04:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbiJZIoW (ORCPT ); Wed, 26 Oct 2022 04:44:22 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E16CD7E1D; Wed, 26 Oct 2022 01:42:35 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4My2Fz396Gz9v7HC; Wed, 26 Oct 2022 16:36:07 +0800 (CST) Received: from [10.206.134.65] (unknown [10.206.134.65]) by APP2 (Coremail) with SMTP id GxC2BwC37Pje8lhjkXoSAA--.11282S2; Wed, 26 Oct 2022 09:42:15 +0100 (CET) Message-ID: <34357c96-fe58-ffe5-e464-4bded8f119d5@huaweicloud.com> Date: Wed, 26 Oct 2022 10:42:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [RFC][PATCH] bpf: Check xattr name/value pair from bpf_lsm_inode_init_security() Content-Language: en-US To: Alexei Starovoitov , Casey Schaufler Cc: KP Singh , Florent Revest , Brendan Jackman , Paul Moore , James Morris , "Serge E . Hallyn" , bpf , LSM List , LKML , nicolas.bouchinet@clip-os.org, Mimi Zohar , linux-integrity References: <20221021164626.3729012-1-roberto.sassu@huaweicloud.com> <98353f6c82d3dabdb0d434d7ecf0bfc5295015ad.camel@huaweicloud.com> From: Roberto Sassu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: GxC2BwC37Pje8lhjkXoSAA--.11282S2 X-Coremail-Antispam: 1UD129KBjvJXoWxury7WryrXr1kWry8CFy7GFg_yoW5WrW8pF W5KF4UKFs8JF97u3s2qa1rWFWIy395Kr47Ja98JwnrZrn8Ar1ayr1fJFWY9ay7Cw4xCw1F v3y2v3sxu3WDZaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_ GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE 14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x07UWE__UUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQARBF1jj4SrugAAsw X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 10/26/2022 8:37 AM, Alexei Starovoitov wrote: > On Tue, Oct 25, 2022 at 7:58 AM Casey Schaufler wrote: >> >> On 10/25/2022 12:43 AM, Roberto Sassu wrote: >>> On Mon, 2022-10-24 at 19:13 -0700, Alexei Starovoitov wrote: >>>> I'm looking at security_inode_init_security() and it is indeed messy. >>>> Per file system initxattrs callback that processes kmalloc-ed >>>> strings. >>>> Yikes. >>>> >>>> In the short term we should denylist inode_init_security hook to >>>> disallow attaching bpf-lsm there. set/getxattr should be done >>>> through kfuncs instead of such kmalloc-a-string hack. >>> Inode_init_security is an example. It could be that the other hooks are >>> affected too. What happens if they get arbitrary positive values too? >> >> TL;DR - Things will go cattywampus. >> >> The LSM infrastructure is an interface that has "grown organically", >> and isn't necessarily consistent in what it requires of the security >> module implementations. There are cases where it assumes that the >> security module hooks are well behaved, as you've discovered. I have >> no small amount of fear that someone is going to provide an eBPF >> program for security_secid_to_secctx(). There has been an assumption, >> oft stated, that all security modules are going to be reviewed as >> part of the upstream process. The review process ought to catch hooks >> that return unacceptable values. Alas, we've lost that with BPF. >> >> It would take a(nother) major overhaul of the LSM infrastructure to >> make it safe against hooks that are not well behaved. From what I have >> seen so far it wouldn't be easy/convenient/performant to do it in the >> BPF security module either. I personally think that BPF needs to >> ensure that the eBPF implementations don't return inappropriate values, >> but I understand why that is problematic. > > That's an accurate statement. Thank you. > > Going back to the original question... > We fix bugs when we discover them. > Regardless of the subsystem they belong to. > No finger pointing. I'm concerned about the following situation: struct *function() { ret = security_*(); if (ret) return ERR_PTR(ret); } int caller() { ptr = function() if (IS_ERR(ptr) goto out; } I quickly found an occurrence of this: static int lookup_one_common() { [...] return inode_permission(); } struct dentry *try_lookup_one_len() { [...] err = lookup_one_common(&init_user_ns, name, base, len, &this); if (err) return ERR_PTR(err); Unfortunately, attaching to inode_permission causes the kernel to crash immediately (it does not happen with negative return values). So, I think the fix should be broader, and not limited to the inode_init_security hook. Will try to see how it can be fixed. Roberto