From patchwork Fri Aug 27 14:49:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 1521689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23e; helo=mail-lj1-x23e.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbf7xuoeqmgqe24ndf5i@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=J/G9FRbS; dkim-atps=neutral Received: from mail-lj1-x23e.google.com (mail-lj1-x23e.google.com [IPv6:2a00:1450:4864:20::23e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gx2gm4jDbz9s5R for ; Sat, 28 Aug 2021 00:50:10 +1000 (AEST) Received: by mail-lj1-x23e.google.com with SMTP id b29-20020a2ebc1d000000b001ba014dfa94sf2840153ljf.9 for ; Fri, 27 Aug 2021 07:50:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1630075800; cv=pass; d=google.com; s=arc-20160816; b=gm+IGzq53/sW4AA+CNR6tn6kwxI6EKBtBNMfEocUz1I06X4B2WKZ7dubVlhjfnlFCe Bmo/MwKh+EPlGY5ySVAy9wYzLLsVuPNpya8Bj3v+b0tCOuIpv1g8zkXfbtTMM8FeImTp 6iTdDassPAHxoJb3KIU2446Qwdog3wt0nACXdqbbbx93SFJA5vrYrtySwwwiNIPnWl0k 2CjKTpMiC+HGiWrQQMH63WlA338fqUx05LNs8RFKWHxE/aIrdZvTirVX0fs4qpcaXN8S ePA7RF9GM32XuFEPlwmtiokyNFnJ4JXN2Ip+r8IR3R9VR+RrxgVO8ns1lEGuJhZ4Kkar uhqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=uO8v9UyJv+4IBZMyhxkccQaYatZj/09xteVRz7fYKOs=; b=qyJEPYylhphLAIDHQzrX0RkXoPNZIYQgAuTeV97A8fK8ePXLUcv0TtteXHcDb3Or+r RLZZZthaBk0ewpobUeKYNJr3RuodAqSwDMilUr0Lo7C374TMjwT9GtZ6XXg1n0P8RmwY J/DaCO359N/Pb/LtUKcdJiJd7OTtaPzCkyj7dPbAbYjqKAfrLEJ+Mhvb4kNBYOcBX/h9 W9Z44xCoMGhvorldQ2HEnO6koETd1c5cu8l6YVlDcsUJixrr+87mzbE8txdeLnpthqYI HfiFuetGCyQ6O9YNftSMOKYrNA7TuJD627Sixn1eKUSRJPSTjYCfisiA0HI5iLr6gI9H hr6Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=uO8v9UyJv+4IBZMyhxkccQaYatZj/09xteVRz7fYKOs=; b=J/G9FRbSuKbs0iiLIQU/podb0ALRxh5g1HPrlo10z1AeyU+Mh/f76YbTUyM/nIEy7K EaoT0svjVTU9nF1MyQiRGrmjlOR/o8ghzB24HXM99TqjcS9AAJ2QXfyRIL3EvnZCgcmm H4uos/Kp6PZ58J09lPW1rp7qhxIf+wVeczszneniKGNv3EmeGoAqzuvacOeHsDOOjf4t sfkc4VRAOQFKuxVmIMiryzA6j6ozK/QqgiTT3Pt+l6sgGbc7hsoGqWW1QXXfmMv25tWj s0veWQkZc4BfkuwbUKa1XnYTX6AxWRyD3hni5assR/Aw/Kv2Vc/2FNXq4h18U6XulPOV rluw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=uO8v9UyJv+4IBZMyhxkccQaYatZj/09xteVRz7fYKOs=; b=lorHVpI654zqv8+wKckacC/GPs8RukaRSsQ9QaP8qHe9RYpIA0M/QNxXwCWRVaYzYl FD683d5DIjM4K5r2vmEqA6mc5CzAFmcYR3FsbxT/QAt8HLaVAAbkIgE7KFyVcXH61E11 pN5AhHDyNV7fF8TomUVg/+lqny06GpwkAQ7ZB2ri8FYLLHRUAC2w/eZykXyDFL0zZRag 7hPteCo7VZIKqM0LntEFLJAG4QtXClPNUZ5WY8++9hI0d7nYeQeyM8hP+UPs8V2WuvSF DFOX3kf6hDCn/yNGIp9i/wCHolOmaWYNxvL19tQAYXH1cM0A7I9w0M/WCtkrYY9KDepC I2Kw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM5300GUJq7KvkMhx6zzFACFwkMkwfCXaBy8/wTdVANtSzqQ2RxE9g 5Z12c/rqGBnoUHko5deujNI= X-Google-Smtp-Source: ABdhPJzPCrI6OvqNeJlcryUC1ut8vJ+hG5eERiLx/8OwdqBekk9O3AuKoe5l0Q4erZxirbYVXVx3OA== X-Received: by 2002:a2e:8511:: with SMTP id j17mr7955948lji.407.1630075800227; Fri, 27 Aug 2021 07:50:00 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:ac2:4146:: with SMTP id c6ls2765282lfi.2.gmail; Fri, 27 Aug 2021 07:49:59 -0700 (PDT) X-Received: by 2002:ac2:4e0f:: with SMTP id e15mr2995001lfr.262.1630075799264; Fri, 27 Aug 2021 07:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630075799; cv=none; d=google.com; s=arc-20160816; b=CXNXGc61USPCiSKIdtbu59cTcTT3qXKeeWP3QvgwrapnwpHN92NmNGsueWM+fdiRd0 SSko9ViPOu9bpaLlCtN7RMQKT52ieYr/iA3c+1JCsu4J+n8+EqamZnVCQnqBRCq5Eekp oJc9H/xeyqhXtBHD5MdBzPyVkWPusLdILAOSpqYX2xblYJEdkwPdBVye2UDdIprwDNI1 2gNY+SzpyEBJNAUyq3Fn/BBWiZn461nKgmf/j9lmB1XkmEEDU2EVCmAnGdTYTHqG4uMF hQHbuuqUTVyZU+Xs5LPpiVkMxk8xSaKhajpaWMp59dceKtBBrFTAygEQWB6fXhDktKO6 LqWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=QPgj1HNgN5w0de2tsDZgQXuC3OJqNeA7XsD1u3DwVqk=; b=Myj4JKPwikIjSQd8N0Hu04wIh70NxLC+Yr0HrovbGaXlz1qsKxZRhMr7QZ0Xsz/g0k nZHt+RKLHM1K1gzxAwNU2reh1QpwnTVLpjqz0LG+jpAu3UPRz0JhMgH4x70t4q4eyLOb unbtOQlvCgxdQ4PiqrHZQPe3jfXoTuaz8skY8eg28QdbjnBMZ3ORbf0K6i9qe82pm+9W gGxqwAq26/gyFlJ8Hfqs3+FfYYk3XFpu2dbTDGHXBrsqBvmsuYN8CXVd1p7hUOSkigRr WtuEOGI/H/iAhegqYQQCPIURlzgIlWgzJqytxpnRowMks0GMkCX3yNOhbuJTaQD28JuS 7o2w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id e17si372228ljo.2.2021.08.27.07.49.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Aug 2021 07:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id 17REnwFh013768 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 27 Aug 2021 16:49:58 +0200 Received: from MD1ZFJVC.ad001.siemens.net ([139.22.37.198]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id 17REnwoa005805; Fri, 27 Aug 2021 16:49:58 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm , Michael Adler Subject: [swupdate] [PATCH] Lua: Replace lightuserdata to fix LuaJIT on aarch64 with 48bit VA Date: Fri, 27 Aug 2021 16:49:42 +0200 Message-Id: <20210827144942.55981-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Current aarch64 (distro) kernels ship with CONFIG_ARM64_VA_BITS_48 enabled, see, e.g., [1] for Debian's kernel, resulting in a LuaJIT panic "bad light userdata pointer" on aarch64 with distro-packaged old(er) LuaJIT versions that limit lightuserdata to 47 bit pointers. One mitigation option is to use a kernel with less VA bits, ruling out using distro kernels untouched. Another mitigation is to use the latest LuaJIT as this issue has been resolved, see [2,3], ruling out using the (older) distro's LuaJIT package untouched -- until distros eventually catch up. Hence, to allow SWUpdate on systems with >47 bits VA to run on current distros' kernel and LuaJIT packages, replace lightuserdata with "full" userdata. For other systems with with <=47 bits VA, this change has no effect other than Lua's gc having to clean up the "full" userdata of sizeof(struct dict*) when it becomes unreferenced: For sw-description embedded scripts, this is happens after having interpreted sw-description. For a Lua handler, this happens at its next call as an explicit free and gc cycle call would occupy more permanent space. [1] https://salsa.debian.org/kernel-team/linux/-/blob/bullseye/debian/config/arm64/config#L13 [2] https://github.com/LuaJIT/LuaJIT/issues/49 [3] https://github.com/LuaJIT/LuaJIT/pull/230 Signed-off-by: Christian Storm Signed-off-by: Michael Adler --- corelib/lua_interface.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index a6da6f2..e1a9c3e 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -854,7 +854,7 @@ static int l_get_bootenv(lua_State *L) { } static int l_set_bootenv(lua_State *L) { - struct dict *bootenv = (struct dict *)lua_touserdata(L, lua_upvalueindex(1)); + struct dict *bootenv = *(struct dict**)lua_touserdata(L, lua_upvalueindex(1)); const char *name = luaL_checkstring(L, 1); const char *value = luaL_checkstring(L, 2); @@ -1036,7 +1036,8 @@ static int l_handler_wrapper(struct img_type *img, void *data) { ERROR("Lua stack corrupted."); return -1; } - lua_pushlightuserdata(gL, (void *)img->bootloader); + struct dict **udbootenv = lua_newuserdata(gL, sizeof(struct dict*)); + *udbootenv = img->bootloader; luaL_setfuncs(gL, l_swupdate_bootenv, 1); lua_pop(gL, 1); } @@ -1206,7 +1207,8 @@ lua_State *lua_parser_init(const char *buf, struct dict *bootenv) lua_setglobal(L, "SWUPDATE_LUA_TYPE"); /* prime L as LUA_TYPE_PEMBSCR */ luaL_openlibs(L); /* opens the standard libraries */ luaL_requiref(L, "swupdate", luaopen_swupdate, 1 ); - lua_pushlightuserdata(L, (void *)bootenv); + struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*)); + *udbootenv = bootenv; luaL_setfuncs(L, l_swupdate_bootenv, 1); lua_pop(L, 1); /* remove unused copy left on stack */