From patchwork Wed Aug 9 17:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711930 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:baf:b0:129:c516:61db with SMTP id gf47csp135483rwb; Wed, 9 Aug 2023 10:51:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6YEG9HG3XhJPIYh4P7nuwTYwdbl5wJL2Bc8EPPLWtMhg5WmaLHR+1Azy59jyqcy1oyuKE X-Received: by 2002:a05:620a:4110:b0:76c:bfeb:97d0 with SMTP id j16-20020a05620a411000b0076cbfeb97d0mr4314229qko.58.1691603469428; Wed, 09 Aug 2023 10:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691603469; cv=none; d=google.com; s=arc-20160816; b=s3vTVvYcHIRkjgH5BXUCdInMXbTsyY2v1IxyilFWChXrNJdZ5frZdem1rx4348c5Te R0igqk00qJNUUUycBLL9Kk+os4YowB0HJf9f/lXR7Noa3CFL9iQSMpw6c/hTM4kBpgc6 nB9KM1vGE7X1u57KRH76upzB2vFi0heF2+F2tIH04AzXjqX71TSDXOZq4HilS1Gero+s bUjj9bk2dqt9S+YQux3gtbVJVhad8FUSv6Uo4wfGVzeH293pQkBsqO+xc+UufBLIhNfF c+iYFmlheV3nW+ezbi+aSOOdZWsPmjIOXgbl7NalRaPP5RXcpIDjmRSE0SpH5vFhIlt0 tzmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hIJbV1+QSy586PHNn48HKMsvhOSunQxnQqr0K94zk5U=; fh=LqDr+k4kYq5gdxxYNR+AXeflmVPlfwJowKBh4V3WpJ0=; b=C80O+6H7/xgKprfapGTQcHX2RSFuHPrZ7IKGve/+GnEBmz3miObG6bT+PP+fO2uuEH QutGJcHisg2n/YOGuXtxr5fRU2f4V06vvLc3bPfoUC0AYCBpBlMC/5/gWi2GKz8JFgHq FwKOV26U3fex0q/bWdTptmv0Bm+nRUJOsbOA4A2vsDM9bUWuach5xh4LFi/Ug1FBNP3X SiqdIlG7PhvT2WK25XxrZDLULnjMrr0ViAxoqpC2IwaLeCeJXFYZQciRkq7yigPuRV8C /42Mne7kgTaCwywx4lXx7H8XbrPm3KuWLBOAH7SWIcX/s4i3K8fYxm/Aw5irxRhvhKBs MLtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ld3vbphY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x29-20020a05620a0b5d00b007681446a032si8102680qkg.269.2023.08.09.10.51.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Aug 2023 10:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ld3vbphY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTnK5-0000Q4-SN; Wed, 09 Aug 2023 13:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTnK4-0000Ov-78 for qemu-devel@nongnu.org; Wed, 09 Aug 2023 13:50:16 -0400 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTnK2-0005g0-Ep for qemu-devel@nongnu.org; Wed, 09 Aug 2023 13:50:15 -0400 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6bc8d1878a0so54818a34.1 for ; Wed, 09 Aug 2023 10:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691603413; x=1692208213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hIJbV1+QSy586PHNn48HKMsvhOSunQxnQqr0K94zk5U=; b=Ld3vbphY4vL9PDzXs1ZSC+0g/pDzUI71ZYemHpH+T0FZK6o8iIjo0EwvzNHPLBAfEE WXSRBmubQBBXF+t4Bp1edacF3IIwbk+MNz2i7ZmEIfl6U0EqmFO36rbN1FcJuSzHtYXD j9aW5p7q/J8R9XOIarXqpIuf0t12RgsICnTc+neikFsi+a9gKml/o5JGbH+E/9nDJdvS +SS4Lw7P6D5nxETBFKWhL6EC+sU0RxVnyt0mWZPWoyRRRif+LFPhTpVetthPXS7rh9ji gzpkVMpA19+XlclJRBCMizuXEh2d3E0aTQTIgq90gnvo33yhMW4TVWTXZNUE6aB33bxy 5ETQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691603413; x=1692208213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hIJbV1+QSy586PHNn48HKMsvhOSunQxnQqr0K94zk5U=; b=Yra75fGETBgTtVH+GdtrjAtZ5BF1IEaMNlwSbnHEOeElwhdNXn5oVjcjFR9Q8mh5yj S1PtHCjW0rB5rGoALYp1iItvUlnrCkLutvxucHPLH0mllBT0PrAKU0XcSjczKbw4x7X5 GcSsHRZGFOfhD+7rF530Z7revem7ld84hfH+6VDOh/1DtsckuxLiKNZg1GH4K901cfG2 LC2HxjOX/VkoLQuKVVdtgXwQu+S1Hi6GG5vNGWEHF8g1sGtYDoH8O5AB16p756Uxfxav wwP1qz4M/tq2AYCgCdOjbxYmo+Iw+dJunXT/vejb4pnctYbrv59H07X1tXnb5XqI5FU/ BjjQ== X-Gm-Message-State: AOJu0YzJYdPdTVjiDG9p+fpIVPLVkxhn3PzLXSgS0koGoMFoD2R9DO8q tHf8kIp1sMbCdyFRVXhn++KGAQGPH0U/i9ZSvls= X-Received: by 2002:a05:6808:2092:b0:3a3:613b:2787 with SMTP id s18-20020a056808209200b003a3613b2787mr41229oiw.32.1691603412805; Wed, 09 Aug 2023 10:50:12 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:6bf0:9674:6ac4:f74c]) by smtp.gmail.com with ESMTPSA id y7-20020a17090a2b4700b0025dc5749b4csm1753710pjc.21.2023.08.09.10.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 10:50:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 6/6] linux-user: Fix openat() emulation to correctly detect accesses to /proc Date: Wed, 9 Aug 2023 10:50:06 -0700 Message-Id: <20230809175006.242479-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230809175006.242479-1-richard.henderson@linaro.org> References: <20230809175006.242479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x331.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller In qemu we catch accesses to files like /proc/cpuinfo or /proc/net/route and return to the guest contents which would be visible on a real system (instead what the host would show). This patch fixes a bug, where for example the accesses cat /proc////cpuinfo or cd /proc && cat cpuinfo will not be recognized by qemu and where qemu will wrongly show the contents of the host's /proc/cpuinfo file. Signed-off-by: Helge Deller Reviewed-by: Daniel P. Berrangé Message-Id: <20230803214450.647040-2-deller@gmx.de> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 12ebc70df5..9353268cc1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8557,9 +8557,12 @@ static int open_hardware(CPUArchState *cpu_env, int fd) } #endif -int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, + +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname, int flags, mode_t mode, bool safe) { + g_autofree char *proc_name = NULL; + const char *pathname; struct fake_open { const char *filename; int (*fill)(CPUArchState *cpu_env, int fd); @@ -8585,6 +8588,14 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, { NULL, NULL, NULL } }; + /* if this is a file from /proc/ filesystem, expand full name */ + proc_name = realpath(fname, NULL); + if (proc_name && strncmp(proc_name, "/proc/", 6) == 0) { + pathname = proc_name; + } else { + pathname = fname; + } + if (is_proc_myself(pathname, "exe")) { if (safe) { return safe_openat(dirfd, exec_path, flags, mode);