Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1712729rdb; Sun, 8 Oct 2023 23:27:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXn3jAivdZIoBSQMofTYp5k1aa97pKVF+K9HNEtOaHLbDpBTtu7qJkLqsGwE0EI6QazUhs X-Received: by 2002:a17:902:f693:b0:1c5:6f43:9502 with SMTP id l19-20020a170902f69300b001c56f439502mr19056441plg.14.1696832850801; Sun, 08 Oct 2023 23:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696832850; cv=none; d=google.com; s=arc-20160816; b=g9yN4bB4Ff/xvFfvoGin37Z6z/BUOnXr3dP2wl3cpXbN62Z5ouu913WOaqKNqBofKP JTtF+aij1FuOK87rQXXL6NC+qFMSi2cvZwEdV6q0WjYciVBjvyN2OsdwhYFRu9QIoJ2g sptm1Trptm7+rV1lkFhakri+hBcJ4ZVYMsWSvdiwFGNbI7eIDVg5KbQSCb0oe6Qb3v0H 0aOO20kGWCSDYzBfYuv6Og9cU4ZvUawv32FF7kqRDDOrPiG2DQ6k0PoGItuIQLzReaXC Z2tGGZOy0bOuqdBPjmqdBY7OF1QevL6c73vMTR18O7ayLMUFipbi8v2vHMmdPAdyW25z XEGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=H2fxCUSPL89877g5I8VIeATWezF+t3F3yjBwJkxQ/GY=; fh=U4AnEI3NGHOOeUEqrp8QaofFPl6Ma7lPDJK2l/3f7bY=; b=MhVdvoX9KlWnnUa9T47EEW7iiutyzBRuAwpycbQqLb73YzFz4787oy8kO2dyJIJu53 c2BmUksxgmA6TjNDBcHz0odFkDuGf2u6Mh3oiH+V8fMgmhM64lSbupK2tK2iMS3c/M56 VnbzIp4b35slA72bzO7wr5DWPmC5s0DUGq2CC5kiOO+lqTfSXR5oLgGagP0rmNIvNWtY 1AErrDR5Ck5tjoK4yKlU2ffc3an98yWsz33BlOgDCbz22gcYFFkQ3E+SZBg2Og2jLSQH SoICRJNHPhacqOAEup1w2DKCIDjGYhxIPY5q8lSL55o1FN3umVJ5s8bRw2xyx6GAQshH zWvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OFgJ68Xm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a4-20020a1709027d8400b001c72c792794si8884228plm.47.2023.10.08.23.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 23:27:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OFgJ68Xm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 78FEC8021B1E; Sun, 8 Oct 2023 23:27:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345176AbjJIG1P (ORCPT + 99 others); Mon, 9 Oct 2023 02:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345168AbjJIG1O (ORCPT ); Mon, 9 Oct 2023 02:27:14 -0400 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A39AAA4 for ; Sun, 8 Oct 2023 23:27:12 -0700 (PDT) Received: by mail-ua1-x933.google.com with SMTP id a1e0cc1a2514c-7a7e11a53c3so3554400241.1 for ; Sun, 08 Oct 2023 23:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696832832; x=1697437632; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=H2fxCUSPL89877g5I8VIeATWezF+t3F3yjBwJkxQ/GY=; b=OFgJ68XmziJUX3RXCZnLMAjcLe7TuG6xSpg20meNsf+7h8IKj1FIvXEY3quFRinjuC XuDkfeszFUOOCIjMWYUQ7YvOeiaT7/eVxB/TwVVO1l9PZAvhZ82H4YxasJrHV2mACXNj Inli+K8fmUERGnPUw7HWDgK+Yz0lsP3xYYgPRw/TGZDnbgKOT1AuGjihxDo80kUMvkEn 71GiI9g7HzRVBg8rL91do+OJQNAZHRH4uOJ9et1g58mb1z3jWJO6l7zz8tWjdhA9IIGT Rxkf7lQsPCBOr7KIarWD11RUQ3p28sjxUOwlR5DygNsWIw05E0n8rYEKjh8rMqRY5ow/ 21oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696832832; x=1697437632; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H2fxCUSPL89877g5I8VIeATWezF+t3F3yjBwJkxQ/GY=; b=b5SFW3tpxG7iBgXM+/E0esns4uGYRnzWUlCqOb5+Mf1ZzyBDuw4jgN4aPX8YYDWDK3 E1x3mIk3L0IaL6Zl47MNtCXZvWEH9xEZz+H35YPbJmiGPgfSaGJl/4dmWmvj37Z/2Q0e //wjG5tJYCxWH630QEhT3HdKbsDbeAwNt8vQxGPAsNmj6TFmsQNl2vrI1HsujKBPkhMV NVBJs1ecz/MJimm4CicHxIBOAbp0iqIFc/V6Q9m6EI/f2CqyiqmSgmvVMNnbQRHIVrMA IKinM9p73g7Zw1jlAeYNC7Z2OEC4KfEBbFjDmKDXSsxTeoPicqjiia2j1ETkgDqyPL35 s7Aw== X-Gm-Message-State: AOJu0YxTbPVkRkfcVfuGFWDoyAf54JVB99FVbtggeA/fMMw2N0qWVn2j gBGiW1mn3bIfU7TCW3QrFnBJWaK+j8myJ12YKzjA6w== X-Received: by 2002:a67:f656:0:b0:452:61fa:1e04 with SMTP id u22-20020a67f656000000b0045261fa1e04mr5510020vso.9.1696832831704; Sun, 08 Oct 2023 23:27:11 -0700 (PDT) MIME-Version: 1.0 References: <20231007170448.505487-1-masahiroy@kernel.org> In-Reply-To: <20231007170448.505487-1-masahiroy@kernel.org> From: Sumit Garg Date: Mon, 9 Oct 2023 11:57:00 +0530 Message-ID: Subject: Re: [PATCH 1/5] modpost: fix tee MODULE_DEVICE_TABLE built on big endian host To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Bhupesh Sharma , Daniel Thompson , Jens Wiklander , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 morse.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 (morse.vger.email [0.0.0.0]); Sun, 08 Oct 2023 23:27:28 -0700 (PDT) X-Spam-Level: ** Hi Masahiro, On Sat, 7 Oct 2023 at 22:34, Masahiro Yamada wrote: > > When MODULE_DEVICE_TABLE(tee, ) is built on a host with a different > endianness from the target architecture, it results in an incorrect > MODULE_ALIAS(). > > For example, see a case where drivers/char/hw_random/optee-rng.c > is built as a module. > > If you build it on a little endian host, you will get the correct > MODULE_ALIAS: > > $ grep MODULE_ALIAS drivers/char/hw_random/optee-rng.mod.c > MODULE_ALIAS("tee:ab7a617c-b8e7-4d8f-8301-d09b61036b64*"); > > However, if you build it on a big endian host, you will get a wrong > MODULE_ALIAS: > > $ grep MODULE_ALIAS drivers/char/hw_random/optee-rng.mod.c > MODULE_ALIAS("tee:646b0361-9bd0-0183-8f4d-e7b87c617aab*"); > > This issue has been unnoticed because the ARM kernel is most likely built > on a little endian host (cross-build on x86 or native-build on ARM). > > The uuid field must not be reversed because uuid_t is an array of __u8. > To me it wasn't obvious that DEF_FIELD() has certain endianness limitations. > Fixes: 0fc1db9d1059 ("tee: add bus driver framework for TEE based devices") > Signed-off-by: Masahiro Yamada > --- > > scripts/mod/file2alias.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c > index 7056751c29b1..70bf6a2f585c 100644 > --- a/scripts/mod/file2alias.c > +++ b/scripts/mod/file2alias.c > @@ -1348,13 +1348,13 @@ static int do_typec_entry(const char *filename, void *symval, char *alias) > /* Looks like: tee:uuid */ > static int do_tee_entry(const char *filename, void *symval, char *alias) > { > - DEF_FIELD(symval, tee_client_device_id, uuid); As you have mentioned in patch #3: the limitations of TO_NATIVE(), if you can update comments for DEF_FIELD() as well to make it clear that it doesn't support byte arrays/strings would be helpful. I think the following check that you have introduced in patch #3 can still be bypassed for byte arrays/strings. + _Static_assert(sizeof(x) == 1 || sizeof(x) == 2 || \ + sizeof(x) == 4 || sizeof(x) == 8, "bug"); BTW, for this fix feel free to add: Reviewed-by: Sumit Garg -Sumit > + DEF_FIELD_ADDR(symval, tee_client_device_id, uuid); > > sprintf(alias, "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", > - uuid.b[0], uuid.b[1], uuid.b[2], uuid.b[3], uuid.b[4], > - uuid.b[5], uuid.b[6], uuid.b[7], uuid.b[8], uuid.b[9], > - uuid.b[10], uuid.b[11], uuid.b[12], uuid.b[13], uuid.b[14], > - uuid.b[15]); > + uuid->b[0], uuid->b[1], uuid->b[2], uuid->b[3], uuid->b[4], > + uuid->b[5], uuid->b[6], uuid->b[7], uuid->b[8], uuid->b[9], > + uuid->b[10], uuid->b[11], uuid->b[12], uuid->b[13], uuid->b[14], > + uuid->b[15]); > > add_wildcard(alias); > return 1; > -- > 2.39.2 >