[From nobody Thu Jun 25 05:55:07 2020
Received: from sonic306-2.consmr.mail.bf2.yahoo.com ([74.6.132.41])
 by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux))
 id 1h9YLr-0004Sq-Ju
 for openwrt-devel@lists.openwrt.org; Thu, 28 Mar 2019 16:58:05 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1553792281; bh=LDvnY0s/3wH/PO9AbYlRsd7G3GRS6GAkrIDnmK8ZgfQ=;
 h=From:To:Cc:Subject:Date:From:Subject;
 b=HsSkpASHZSAZY8ngwonkvvw1Po//O6q+042wQXTek42hw9GBmqi5+QVazRmuzJvzOPYiF/PB4QuprJ5olIf+8ajYejuHjmCNb45aINvD1ZdvQMM1E2ZHWaNYhwqE5apz19XqJvz/CAvymJb7jpph2qpB/hxrTkCM/pIj03zld9u7oIlDu93l6pq+7Ci+EuHf0tYCh2uTAw4a3aUZ5NwZOr7AZNCH9Gnsvbgu5fAfMXFLe4iSJBGadu/3mzHLwYHrQPp2Ugn1ZcxrYSVD5KNS8PzneehcLb381T0R6u7pFLYZ44o7GVNj3hdQPGVRiTIZJo8N/GpDBByQfIkFfBKwPQ==
X-YMail-OSG: u5FYdfcVM1kc3ushVXhxiSBcPYdbOHkKh6Ynn.AhmRMe3dtXN7SUwK9HhFtotWh
 RGk.BBxdKhxF_Igv5c7tG88nZ6lTss2uKtV3fFsn6kt5riv55tG9CT1cV2idxpcDqd337T1S0XsP
 xPTA3CYTdj0BQiE_lQlVptjptmIWJ1pY1sRGDLjcqGLJnzp7w.Vez5GrXQKg_Nv7mJxXtZfJ9RWB
 RzlIW6Ani5lPGsBAsYkfq13u7W4E.1CZXvunCGFNHL.q3Fqy.U3LIGx2Z8FPMUHoKoVsYVDKNm5u
 VcxPPU3SvvkcG4rkG1el6CVMF68Aba55q80p0UcgY236AXHalvltA4RRW3EX2v9ExFpFjVLLTGAv
 RUBPJ_EBaX42voTgqA1xGkjt5OlaPG2Dow.jIO7kNOKJT9YkLBGOpxaf2XD5Op6Ujry62cP2H_0O
 6V2ee2XEHzD8wq5LODEFOrEcq.OdKrMs6Ee2lxinlnOBA.E_RryBctqV2qXNBSSEs3oHvrGPLn14
 u9miflGzGP0kKB6idChlq61WV.nLcdFdpA.sPGrtoPaUulmpeB7U_8M76rEX_pKFwd1nxbODRoWH
 nrSCy4BRGuT9.zlu9tOqj9ddFdAI9NWx1hZsUtKryUDbTu3QOf0XK9jb35wrwKfKDWUDYupW.Gt0
 XT9GV4YOJH0PukoI_JHktm7WbaD3jpHBthFtJVq46OZ7WVEVGAwkq1I6xmPjApQo6WA5Wsvk_mtT
 iCwvF8BpdCihWfqg4ZCNpmxCaKRdk8bbLDB1fPSzA.TbpY_qDtKQAGaDMrD_EMITVyw7RFTVmj82
 kpJVzhLjCPys678FIyv86ViGICtMjUN5krTFDZjSecpMGOu4E25QuC7iZV_aaaysYsLkgcNTwjZP
 EjAtqGYNZYpNzKyQCh3ZSNc3W.V3U_XZZbT9k029Bs7xEu6zxmbE2FXpo_d39wfWoDUS3oiu7dgy
 Xcr_Ev0aoNMynfnaqWjK5y0UOxgx.aQVLzM6.1WoVVvYeR_LKZ858FfE_SAoZjmjAsSKdQ4tDtRb
 mLZvUMfluSMKt5LNGM6_rVuiFluRn2vvFPnn.IL0KYB.eqjfhxtdthJBoLbY-
Received: from sonic.gate.mail.ne1.yahoo.com by
 sonic306.consmr.mail.bf2.yahoo.com with HTTP; Thu, 28 Mar 2019 16:58:01 +0000
Received: from 18.175.75.177.infopasa.com.br (EHLO gateway.troianet.com.br)
 ([177.75.175.18])
 by smtp421.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID
 f9a9e28034233343cd0652e7d2f74393; 
 Thu, 28 Mar 2019 16:57:57 +0000 (UTC)
From: Eneas U de Queiroz &lt;cote2004-github@yahoo.com&gt;
To: openwrt-devel@lists.openwrt.org
Cc: Eneas U de Queiroz &lt;cote2004-github@yahoo.com&gt;
Subject: [PATCH] download.mk,image.mk: add --mode=a-s option to tar
Date: Thu, 28 Mar 2019 13:57:49 -0300
Message-Id: &lt;20190328165749.27727-1-cote2004-github@yahoo.com&gt;
X-Mailer: git-send-email 2.19.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 
X-CRM114-CacheID: sfid-20190328_095803_714345_26C070CB 
X-CRM114-Status: UNSURE (   3.71  )
X-CRM114-Notice: Please train this message.
X-Spam-Score: -0.2 (/)
X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary:
 Content analysis details:   (-0.2 points)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [74.6.132.41 listed in list.dnswl.org]
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (cote2004-github[at]yahoo.com)
 -0.0 SPF_PASS               SPF: sender matches SPF record
 -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from
 envelope-from domain
 -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from
 author's domain
 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
 0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily
 valid

Otherwise tar will keep the sgid bit when running from a sgid-set
directory, resulting in a different file being generated.

Signed-off-by: Eneas U de Queiroz &lt;cote2004-github@yahoo.com&gt;
---

Notes:
    This fixes an issue exposed in
    https://github.com/openwrt/packages/pull/8513
    
    Tested it by reproducing the wrong tarball with master by setting ./tmp
    sgid.  Then applied the patch and ran it again, ending up with the right
    file.

diff --git a/include/download.mk b/include/download.mk
index 33141910fc..09794e155e 100644
--- a/include/download.mk
+++ b/include/download.mk
@@ -55,7 +55,8 @@ define dl_pack
 	$(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))
 endef
 define dl_tar_pack
-	$(TAR) --numeric-owner --owner=0 --group=0 --sort=name $$$${TAR_TIMESTAMP:+--mtime=&quot;$$$$TAR_TIMESTAMP&quot;} -c $(2) | $(call dl_pack,$(1))
+	$(TAR) --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
+		$$$${TAR_TIMESTAMP:+--mtime=&quot;$$$$TAR_TIMESTAMP&quot;} -c $(2) | $(call dl_pack,$(1))
 endef
 
 ifdef CHECK
diff --git a/include/image.mk b/include/image.mk
index 9e40a54f51..b91a3a3d7a 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -291,7 +291,7 @@ endef
 
 ifdef CONFIG_TARGET_ROOTFS_TARGZ
   define Image/Build/targz
-	$(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
+	$(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
 		$(if $(SOURCE_DATE_EPOCH),--mtime=&quot;@$(SOURCE_DATE_EPOCH)&quot;) \
 		-C $(TARGET_DIR)/ . | gzip -9n &gt; $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
   endef

]