Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7420020rwb; Wed, 23 Nov 2022 06:22:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7iyIjnWD//iPI1HMZ7cJ5L2WMFDN1e4JZJdz2ranH6LJC1f/Br9s1fpQYK9G3tnUKr8WUt X-Received: by 2002:aa7:d558:0:b0:461:eea0:514c with SMTP id u24-20020aa7d558000000b00461eea0514cmr15555539edr.296.1669213341488; Wed, 23 Nov 2022 06:22:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669213341; cv=none; d=google.com; s=arc-20160816; b=uSR+ob/JmVJx5RjTDBUw42OVOBMz1YMJXqsZwSjQTuRYsgcLxMJyc4u/QXvHlzSAdJ C4NBJXv2RjYuSXHD0RaeGLRLffbNBwxjPqUWVmFapTuvawGI/efAaJdSgZ5B33f4jC5t eYX47TLDEwPakcakK0s7xh8du3bW7gzovsnubRsn+4X0itlUw0msyqDzZLgswXwQPy5p 3zZ45OjwWFIwQqqlNOEvkmphBGeb8svpaF3PqrjeCyqvQhO1XH9XAa/wy+7TBBDgRdiQ +MVJ6YfH3hy2uQFTScYMYI12tIaroZeSN0y7jPNFHRp0e4mCEEiRqcLhcDHD0u9NTv9S jeLQ== 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=JIQQBEtxGY9RA4lQzL4HGLDTZt7566ihx4LcqVyA74I=; b=rqnV6p0QkeDw18u/5AyUnQxdFiirnZ7nkOURDTc3i1oo8hO1NipdgBfQw6dpvOHXzg j2OMRweqRnLKjB0ma1T9g1CM85jwQ5WMq1Qy+v2Aang5qOkupUMAkTo3ohuJV3CN9aM5 G14joVEpOjXwyNzJLjdnznvSI3NmXayzVi1/RSJSUlmmjPlW7yeI65605v4DRONjnX4e zgJ8DdfaVLoTljp9Bstt1wq/6//jvSIwQu40AIfn7s2WI3c8j4i/9/hPA3+R2YF17LXl AMAJKEoIg3/RmrNmttRBmdcC6pT2yQP3Ex6DfKtxTJpMISKkeijihvy9hoccO8zvB+un qk8A== 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 v5-20020a056402348500b0046363151bd1si15486088edc.615.2022.11.23.06.21.58; Wed, 23 Nov 2022 06:22:21 -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 S237335AbiKWN4A (ORCPT + 89 others); Wed, 23 Nov 2022 08:56:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236980AbiKWNzb (ORCPT ); Wed, 23 Nov 2022 08:55:31 -0500 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B233786EC; Wed, 23 Nov 2022 05:50:04 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4NHMlH2q7Vz9xGYw; Wed, 23 Nov 2022 21:43:07 +0800 (CST) Received: from roberto-ThinkStation-P620 (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCXNHHwJH5j5POKAA--.41417S2; Wed, 23 Nov 2022 14:49:44 +0100 (CET) Message-ID: Subject: Re: [PATCH] ima: Make a copy of sig and digest in asymmetric_verify() From: Roberto Sassu To: Mimi Zohar , dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, rusty@rustcorp.com.au, axboe@kernel.dk Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu , stable@vger.kernel.org Date: Wed, 23 Nov 2022 14:49:31 +0100 In-Reply-To: References: <20221104122023.1750333-1-roberto.sassu@huaweicloud.com> <9ef25f1b8621dab8b3cd4373bf6ce1633daae70e.camel@linux.ibm.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: LxC2BwCXNHHwJH5j5POKAA--.41417S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXr4DKFWDtF1DXFyUZF18Xwb_yoW5CF48pF 48K3WDKrs8Jr1xKFWIyw4DG398Kr4rKFW7X34kCwn5Zryvvr48Zw40qF47WFyDWryxAF4U tay3tr9rZrn8AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28IcxkI 7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6x AIw20EY4v20xvaj40_Wr1j6rW3Jr1lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280 aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UWE__UUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAFBF1jj4HKeAAAsB X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Wed, 2022-11-23 at 08:40 -0500, Mimi Zohar wrote: > On Wed, 2022-11-23 at 13:56 +0100, Roberto Sassu wrote: > > On Tue, 2022-11-22 at 14:39 -0500, Mimi Zohar wrote: > > > Hi Roberto, > > > > > > On Fri, 2022-11-04 at 13:20 +0100, Roberto Sassu wrote: > > > > From: Roberto Sassu > > > > > > > > Commit ac4e97abce9b8 ("scatterlist: sg_set_buf() argument must be in linear > > > > mapping") requires that both the signature and the digest resides in the > > > > linear mapping area. > > > > > > > > However, more recently commit ba14a194a434c ("fork: Add generic vmalloced > > > > stack support"), made it possible to move the stack in the vmalloc area, > > > > which could make the requirement of the first commit not satisfied anymore. > > > > > > > > If CONFIG_SG=y and CONFIG_VMAP_STACK=y, the following BUG() is triggered: > > > > > > ^CONFIG_DEBUG_SG > > > > > > > [ 467.077359] kernel BUG at include/linux/scatterlist.h:163! > > > > [ 467.077939] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI > > > > > > > > [...] > > > > > > > > [ 467.095225] Call Trace: > > > > [ 467.096088] > > > > [ 467.096928] ? rcu_read_lock_held_common+0xe/0x50 > > > > [ 467.097569] ? rcu_read_lock_sched_held+0x13/0x70 > > > > [ 467.098123] ? trace_hardirqs_on+0x2c/0xd0 > > > > [ 467.098647] ? public_key_verify_signature+0x470/0x470 > > > > [ 467.099237] asymmetric_verify+0x14c/0x300 > > > > [ 467.099869] evm_verify_hmac+0x245/0x360 > > > > [ 467.100391] evm_inode_setattr+0x43/0x190 > > > > > > > > The failure happens only for the digest, as the pointer comes from the > > > > stack, and not for the signature, which instead was allocated by > > > > vfs_getxattr_alloc(). > > > > > > Only after enabling CONFIG_DEBUG_SG does EVM fail. > > > > > > > Fix this by making a copy of both in asymmetric_verify(), so that the > > > > linear mapping requirement is always satisfied, regardless of the caller. > > > > > > As only EVM is affected, it would make more sense to limit the change > > > to EVM. > > > > I found another occurrence: > > > > static int xattr_verify(enum ima_hooks func, struct integrity_iint_cache *iint, > > struct evm_ima_xattr_data *xattr_value, int xattr_len, > > enum integrity_status *status, const char **cause) > > { > > > > [...] > > > > rc = integrity_digsig_verify(INTEGRITY_KEYRING_IMA, > > (const char *)xattr_value, > > xattr_len, hash.digest, > > hash.hdr.length); > > > > Should I do two patches? > > I'm just not getting it. Why did you enable CONFIG_DEBUG_SIG? Were > you testing random kernel configs? Are you actually seeing signature > verifications errors without it enabled? Or is it causing other > problems? Is the "BUG_ON" still needed? When I test patches, I tend to enable more debugging options. To be honest, I didn't check if there is any issue without enabling CONFIG_DEBUG_SG. I thought that if there is a linear mapping requirement, that should be satisfied regardless of whether the debugging option is enabled or not. + Rusty, Jens for explanations. > If you're going to fix the EVM and IMA callers, then make them separate > patches. Ok. Thanks Roberto