From nobody Thu Oct 31 00:18:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=midokura.com ARC-Seal: i=1; a=rsa-sha256; t=1622440396; cv=none; d=zohomail.com; s=zohoarc; b=P0JN6cNjFRwezb9UoCmV+gKX3+CcOzGbr7R9fBUjvLrjW2Nm8YdvlL4bdqjB/NEhghnzutrSEO7dRIE5g7uY26+kxLucxAVY1NzB2VyJ0RJQel+/+rkedxoh1vPabeAy0LQspXOqlgfbj6rWTrDTXyuKRKjFGA5Vmi6hCKXWlA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622440396; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=ElndNf7bzK2ywsqgRYmzkBkqCLVCnqJDSvnF4es01wLdxGQmbg+J6M5bzVkZVb5eiB/6StwtMb8aejfnK8lesdPRWq5WdrJt0fRitckG1Wfx2rwtqyRyswT/wEyczDp8es3wAuEE+eZEnjaIaHqwMiZV459WgFMTjtnc+j7zZ6A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622440396015253.03595194420177; Sun, 30 May 2021 22:53:16 -0700 (PDT) Received: from localhost ([::1]:44702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnarT-0007tb-0v for importer@patchew.org; Mon, 31 May 2021 01:53:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnapW-0004wn-5J for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:14 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43977) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnapU-0003oo-JN for qemu-devel@nongnu.org; Mon, 31 May 2021 01:51:13 -0400 Received: by mail-pl1-x62d.google.com with SMTP id v12so4647145plo.10 for ; Sun, 30 May 2021 22:51:12 -0700 (PDT) Received: from spacetanuki.lan ([202.12.244.32]) by smtp.gmail.com with ESMTPSA id b10sm4744058pfi.122.2021.05.30.22.51.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 May 2021 22:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=midokura.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=YJNev2eneIe6WmmLgurJ2stSBhx5kKSiExGV3uLvfyOjdfZUOlc1UovaIwAvh21LD6 V57+HI0dpqOqqdoCRevAZdqnahe1oJ/kwWnVA1bPHzj7PAqXCueHMHG4kQ6xV6fbu/Pc sWMNjxAbCbqv7iVG7rMTk3YWuXhjXUWUk20JQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DAsgew0PuL4nW9yTQE28tqe8JgDQa0h/wMivkuc7Sqs=; b=iT4laYPPC6KHFNBKA2DPR8KHLHNPfuS5kZqedYfnfZEHOUdMC5NSQuifUc1A1dLJly uNhBfXBHI3l+khjnQKT4JmjtCL0xA9m2qUc26XETrNJnqs2H8X383oroAOVfkItbSPjP fo7Z07ZQnXtUs06ZlFEJ3Wns5900uQdsWiRkd5XxSpFNW/O23SUEU/IlH+gStnn7Ts3C +hWVvncJrAomuJqAoPqiD65Wi3HL8GeI6IYkazbupyC7DSqmVrfWF3tXG9Y0SQXNm2L+ kQDQG5S80YCLFXk3BoB9m5ZEm5cgZo8mWq0/7tZ+cPRtSS6S1udECoECliiRuxj0wtZv jCfQ== X-Gm-Message-State: AOAM530qproxLX/x6PsLFYoZuFTEUBtXEMHV/Pm6VE2IhF6ECwlt62Od aFJu5Kv5KXwijHFTMXUWGZe+/QJG1Lg9Hw== X-Google-Smtp-Source: ABdhPJxyHFIOisANzzN2h3H/XQ95b/AJM0t3feppzfdN+U2yf6tsywUSh747UiMvL9K77QiXIiQoJg== X-Received: by 2002:a17:90b:4384:: with SMTP id in4mr17741440pjb.159.1622440271198; Sun, 30 May 2021 22:51:11 -0700 (PDT) From: YAMAMOTO Takashi To: qemu-devel@nongnu.org Cc: YAMAMOTO Takashi , Laurent Vivier Subject: [PATCH v2 04/11] linux-user: make exec_path realpath Date: Mon, 31 May 2021 14:50:11 +0900 Message-Id: <20210531055019.10149-5-yamamoto@midokura.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210531055019.10149-1-yamamoto@midokura.com> References: <20210531055019.10149-1-yamamoto@midokura.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=yamamoto@midokura.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @midokura.com) Content-Type: text/plain; charset="utf-8" Otherwise, it can be easily fooled by the user app using chdir(). Signed-off-by: YAMAMOTO Takashi --- linux-user/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index a9d02f9583..be604a84f9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -55,6 +55,7 @@ #endif =20 char *exec_path; +char exec_path_store[PATH_MAX]; int exec_fd =3D -1; =20 int singlestep; @@ -611,7 +612,20 @@ static int parse_args(int argc, char **argv) exit(EXIT_FAILURE); } =20 - exec_path =3D argv[optind]; + /* + * Try to get the realpath of the executable to avoid being + * fooled by chdir is the user app. + * + * Note: realpath here can fail for some use cases. + * For example, runc executes an unlinked binary via + * /proc/self/fd. + * It isn't fatal as far as we have an exec fd. + * (Otherwise, we will fail to load the binary. + */ + exec_path =3D realpath(argv[optind], exec_path_store); + if (exec_path =3D=3D NULL) { + exec_path =3D argv[optind]; + } =20 return optind; } --=20 2.21.1 (Apple Git-122.3)