From nobody Sat Feb 7 07:25:39 2026 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660033712; cv=none; d=zohomail.com; s=zohoarc; b=oHu/g8EJ3Z/ljGPEA4fGO3acvFuO7bVQSU5V58Vui8CHpcDve6Ya3uFgBjqNRylrD2P5LXh1t4oNG7darBEAcylhQ8e+FqeVg7nLNR9Z9R+aFa2LCLH18wYzG34fF1xEfch9fC4CsQFjCbrAargk0QeCRa5a35TltT8mrmJmlI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660033712; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ezMtzJdsQt0Ofa4jcTwGnF+9OCTmlooriMBu5SWAmPA=; b=MIY/Bnn+kY8szgBtW6RG9TDmrBvxWInJuIyYRzcbbUjbekQJF8YQlFp2XvGUnJMO1F/vW1UZmvSsexqqdYnDFW/K5w6cq9wR64WuRlkMN6i2g9eUekPiR/8DaoWbewQ1LpK2G0pXq64RifTeqfHOwuMVK/lcqguYD2ITPE/73lc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660033712402257.0990264236848; Tue, 9 Aug 2022 01:28:32 -0700 (PDT) Received: from localhost ([::1]:40824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLKbH-00084D-2I for importer@patchew.org; Tue, 09 Aug 2022 04:28:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oL86A-0003D9-Pq for qemu-devel@nongnu.org; Mon, 08 Aug 2022 15:07:34 -0400 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]:34367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oL869-0005oe-9F for qemu-devel@nongnu.org; Mon, 08 Aug 2022 15:07:34 -0400 Received: by mail-qv1-xf36.google.com with SMTP id u8so7053255qvv.1 for ; Mon, 08 Aug 2022 12:07:32 -0700 (PDT) Received: from arctic4.juliacomputing.io ([2001:550:2:2c::46:13]) by smtp.gmail.com with ESMTPSA id i25-20020ac871d9000000b00342f960d26esm2405363qtp.15.2022.08.08.12.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 12:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=ezMtzJdsQt0Ofa4jcTwGnF+9OCTmlooriMBu5SWAmPA=; b=Jgy5MjGuj9jQZCmcdkSUQjzNgUsHsGXx+LXw7kui7bxzqtm+IG8+8Jrkkz3x4bZhzY PNuMRPtXmCK0qlf/MlH+E2IxCB16kcxjn5H6/ZtF+zX/nIa9gzfHpbrTGLYaPwx2pJBS 8iDLOc/mVSSGDe1UGaw0QEd6d83EKDPCzpImrYw60JDVyPCmfc5iSa10lJcDLd7nevcu LD5ZgtjX1Li1MI2WROW3qTptIPHEs5vf5CpnZU1r+8FWahk4NdHh1KDOmdD5JyT8cgZ3 xA6BWx8ZHfmFK5pqBllAbZK9TuEMBq1Eo9itjsY4w+oDAeaN0IPvesRYrTXm17NU9Ohr XkYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=ezMtzJdsQt0Ofa4jcTwGnF+9OCTmlooriMBu5SWAmPA=; b=hcx10TxZ6WUZRtHxLipsWI/FjLKvQbX5RJ+wKF0iITjDAoKqeS1KDqAf0NzmZ04wfp 2L5RJtCWxn1S39u7DBVicKhKaugxKz+1VAcFY7fT+3LoKACsoJs2snQZdK8oRdYIDYce sRNBzBc24KC8uo9qth9aSKoh68ooXsd+cIk1MGso4UTXV8Cx3nNlxpYNtkllBdlkrDZR AvhinsGDKI6ExgG42jb14az+Lrpl7tKb42xDLPCj2bcxhthYfhWu3ZAARiPkA1SBW4sQ vTGNOdGkBmZlRFdctR6RJsnbNFOe/Ij1L7CYeDhFtfgzH5bWcyOqzwB8aYQw7LuRyCEr IpCw== X-Gm-Message-State: ACgBeo17hY0BSq0OWJ5s9p6LKoeWp/0FzLmIZ9HLb/Qw1DN/lhoTI0Bv HZIAkH8JktJ/mheWz3VY0BB2L6giUKhx+Q== X-Google-Smtp-Source: AA6agR7MFqgcCJdsfUnVTCPUd8D4yJW7i4vV2qY7XcJTXdiMF/hU11ThMRtJ5Pqp7POLcDxpgOVR6w== X-Received: by 2002:a05:6214:212d:b0:475:c30d:fa8b with SMTP id r13-20020a056214212d00b00475c30dfa8bmr16916584qvc.123.1659985651468; Mon, 08 Aug 2022 12:07:31 -0700 (PDT) From: Jameson Nash To: qemu-devel@nongnu.org Cc: Jameson Nash , Laurent Vivier Subject: [PATCH] linux-user: fix readlinkat handling with magic exe symlink Date: Mon, 8 Aug 2022 15:07:27 -0400 Message-Id: <20220808190727.875155-1-vtjnash@gmail.com> X-Mailer: git-send-email 2.25.1 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::f36; envelope-from=vtjnash@gmail.com; helo=mail-qv1-xf36.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 09 Aug 2022 04:24:59 -0400 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660033714101100001 Content-Type: text/plain; charset="utf-8" Exactly the same as f17f4989fa193fa8279474c5462289a3cfe69aea before was for readlink. I suppose this was simply missed at the time. Signed-off-by: Jameson Nash Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ef53feb5ab..6ef4e42b21 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9894,11 +9894,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, = int num, abi_long arg1, p2 =3D lock_user(VERIFY_WRITE, arg3, arg4, 0); if (!p || !p2) { ret =3D -TARGET_EFAULT; + } else if (!arg4) { + /* Short circuit this for the magic exe check. */ + ret =3D -TARGET_EINVAL; } else if (is_proc_myself((const char *)p, "exe")) { char real[PATH_MAX], *temp; temp =3D realpath(exec_path, real); - ret =3D temp =3D=3D NULL ? get_errno(-1) : strlen(real) ; - snprintf((char *)p2, arg4, "%s", real); + /* Return value is # of bytes that we wrote to the buffer.= */ + if (temp =3D=3D NULL) { + ret =3D get_errno(-1); + } else { + /* Don't worry about sign mismatch as earlier mapping + * logic would have thrown a bad address error. */ + ret =3D MIN(strlen(real), arg4); + /* We cannot NUL terminate the string. */ + memcpy(p2, real, ret); + } } else { ret =3D get_errno(readlinkat(arg1, path(p), p2, arg4)); } --=20 2.25.1