Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp350819rdg; Tue, 10 Oct 2023 12:06:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbJWkRCCXywg0RtUT3Vc//gjLW10SZMRkvJPMTQfax3XX69RJCyFzrtC43kHfoAY3WZusS X-Received: by 2002:a17:902:c412:b0:1bd:aeb3:9504 with SMTP id k18-20020a170902c41200b001bdaeb39504mr28046858plk.15.1696964776524; Tue, 10 Oct 2023 12:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696964776; cv=none; d=google.com; s=arc-20160816; b=tKB8oCmgXyfHlB6F0Q4FwxyOgYAb/Hk0OtfnYBcxZmtyH3yosl4/ZKpt/OS/1AHkSw diEvOaUn94zMNhN/kHRKgjmy2P/MQYX8n9yDIK3hTaV7f/THde9G07ixvYmbtrQ6H+Jv QDCBx7oe9Fy1Ukk9omWGT5pjWRTrwEnl9kiFp3kfC5vGa15uZQUV0GrwvHFZJv0HTUn+ QHBNjlarrPFlOvo36vSjvvIuRHkSB0joscGFcS7mN/m93ezpNID8ilUNmiKcPzaL0R/u mil6QpVIf4Hbt4/VGt2swDJ8QzYlo75z4NVykmBbIjtW7oa1GSf9I5pVOMqiqXyKgrzC DSgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=F3gMhW120CKmSLazk5WrZAcUwh0451x7uZSy2NAGFlA=; fh=WXE0LJ8p2HJ8KBJ4NZesrL3mvDzB5Gx85ADjKhDR2ps=; b=gvKuOS6HbDbeKGlBwZ0d8IBvs0x1TXnwlMQXtbFAT6kZLvl4iOI4snqTPWaSrGqmhf p5+XMIdeT1ml3nuwpwiQQ2QzHq+huQEphInWS6VyTi0VGWF+Fgivj7KvV7UtS5mdUjCf O6r5oms5dxqff0AEbtkfNyq/y+aun3/bx9XCwGhMgM06cA8r9eWT864c7L/bjdEfSbw2 haBwb6e8iGv6BYV2vtpQLESuofHStcwcBn8pinvZhNH4lLiFhbMHSg1w/QveQcolmIHQ /Tkb7dfklQIHJBVfhzhiZaRbZtwQkMwMrwhWPBS6NNIfeNCx3QuG9TsyrVo+rS2R+SqZ 6kBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YKfqXHjF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z15-20020a170903018f00b001c9c566b847si873663plg.84.2023.10.10.12.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 12:06:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YKfqXHjF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CFA8983B5B45; Tue, 10 Oct 2023 12:06:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343672AbjJJTF7 (ORCPT + 99 others); Tue, 10 Oct 2023 15:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234162AbjJJTF5 (ORCPT ); Tue, 10 Oct 2023 15:05:57 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89D794; Tue, 10 Oct 2023 12:05:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95796C433C7; Tue, 10 Oct 2023 19:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696964755; bh=slgHXzrc2IofJCZavg5wuuNQrcCzs3dZIe68cvgkTCg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=YKfqXHjFVbF5Ecm0X9rz/cuJ7TwxuPCHbWy3ros5O+ugINGNfCgvW2M06BUH2ApRC 7U8vC5TX8pxOt5NZO0T6qftqrTAOPRRShYdzNeW47y7DlKA3m3398NRbJS8je4D5YB lq2YvYacfrRMNrNgArDVDGGnICM6NrXxML+sH/0g2zwlfXjl8SMOYIRtPxpKe1fsLN 1ZGztSIlAS98Hxc0n7OpR40AdEa3SDwELLOrEC959Te+Lv56HyjfYqX7RUDjXVh7Oc aoBMncCSMIwkQUMRubkpbpA2iLY5+YoZdZLo7RWBlLRzx6K/Oj/2b2MQ2GjkJTqQnH ZYBanr5ovygfQ== Message-ID: <8a8c14694d5ff62e385163bf0852fd3adb675087.camel@kernel.org> Subject: Re: [PATCH v2] KEYS: trusted: Remove redundant static calls usage From: Jarkko Sakkinen To: Linus Torvalds , Sumit Garg , David Howells Cc: peterz@infradead.org, zohar@linux.ibm.com, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, jejb@linux.ibm.com, David.Kaplan@amd.com, bp@alien8.de, mingo@kernel.org, x86@kernel.org, regressions@leemhuis.info, Hyeonggon Yoo <42.hyeyoo@gmail.com> Date: Tue, 10 Oct 2023 22:05:50 +0300 In-Reply-To: References: <20231006051801.423973-1-sumit.garg@linaro.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 10 Oct 2023 12:06:14 -0700 (PDT) X-Spam-Level: ** On Tue, 2023-10-10 at 11:28 -0700, Linus Torvalds wrote: > On Thu, 5 Oct 2023 at 22:18, Sumit Garg wrote: > >=20 > > Static calls invocations aren't well supported from module __init and > > __exit functions. Especially the static call from cleanup_trusted() led > > to a crash on x86 kernel with CONFIG_DEBUG_VIRTUAL=3Dy. > >=20 > > However, the usage of static call invocations for trusted_key_init() > > and trusted_key_exit() don't add any value from either a performance or > > security perspective. Hence switch to use indirect function calls inste= ad. >=20 > I applied this patch to my tree, since it is a fix for the issue, and > doesn't change any logic otherwise. >=20 > However, I do note that the code logic is completely broken. It was > broken before too, and apparently causes no problems, but it's still > wrong. >=20 > That's a separate issue, and would want a separate patch, but since I > noticed it when applying this one, I'm replying here: >=20 > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 trusted_key_exit =3D trusted_key_sources[i].ops->exit; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 migratable =3D trusted_key_sources[i].ops->migratable= ; > >=20 > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 ret =3D static_call(trusted_key_init)(); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 ret =3D trusted_key_sources[i].ops->init(); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (!ret) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break= ; >=20 > Note how this sets "trusted_key_exit" even when the ->init() function fai= ls. Sumit, can you remind me why this continues *on any failure*? E.g. something like this would make more sense to me: ret =3D trusted_key_sources[i].ops->init(); if (!ret) { static_call_update(trusted_key_seal, trusted_key_sources[i].ops->seal); static_call_update(trusted_key_unseal, trusted_key_sources[i].ops->unsea= l); static_call_update(trusted_key_get_random, get_random); static_call_update(trusted_key_exit, trusted_key_sources[i].ops->exit); migratable =3D trusted_key_sources[i].ops->migratable; break; } if (ret !=3D -ENODEV) break; ` BR, Jarkko