From nobody Tue May 7 08:43:38 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=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1643220583; cv=none; d=zohomail.com; s=zohoarc; b=KkmkAoV30/dICR0vBE1IwIpjQ4LgIn2J7qPxLRhCm/KvIeN5oO+SxwX4BVMrQ/eJj6sbPYFujr9HzxthI5JNsCo+QwyauhX/XsoGsmPK/rZz7GCUlmhk+UUnJv49qlWIoWArOfb7qpqOf0C6rDiqhjy2Gf8urS2Is4jgY8wD+O4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643220583; h=Content-Type: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=9CHa3z7ibh+wQwKi0QxjDP31H6eY49wbJnmXPqH4vEs=; b=cv11XSPQO0KJlJr85NPheY32eFZDVQ/skqHcFRicATDXCVV+BrEBSSRJZV4qCPbb6wcWPYekgIyw1kCzYGbhbzYvZxGvxkfebJvTKhgRzfv7gq6iX7OLE69YNnvSANP6JXNX3dssQh7ot5845+Naej8xYTOpCDdKdMzq9MyeQQY= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643220583768567.3249309855054; Wed, 26 Jan 2022 10:09:43 -0800 (PST) Received: from localhost ([::1]:35414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCmjm-0002b9-TK for importer@patchew.org; Wed, 26 Jan 2022 13:09:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <35IvxYQcKCtcO7GMNK79HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--venture.bounces.google.com>) id 1nCmZT-0000TN-T9 for qemu-devel@nongnu.org; Wed, 26 Jan 2022 12:59:03 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=56216 helo=mail-yb1-xb4a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <35IvxYQcKCtcO7GMNK79HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--venture.bounces.google.com>) id 1nCmZS-0000ev-7V for qemu-devel@nongnu.org; Wed, 26 Jan 2022 12:59:03 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id e13-20020a25e70d000000b00615e9bc9a3cso590785ybh.22 for ; Wed, 26 Jan 2022 09:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=9CHa3z7ibh+wQwKi0QxjDP31H6eY49wbJnmXPqH4vEs=; b=hkWn4pS2uPH14Ew1IExDsXW7Ie03CP34ljCUxXKklF18Xl2/p+MvbtmCh/uSfgMWVD Dwp0Lk03qxlOIF2+UCrZYuLZJLG11tR9SAvGHvX9/O4YTbH08ODelrkXvtDVSKFoXyAK LYrgfGwqNk4/xmkWUA0qnlspnOgx4h4/X5KlUh80zMginFNjrsEbS/eik9Eh0/gmlLYb gJOZaGe/WRPEvSALbJMaSzy+/ggGjBrXUN3+blIt3YrbyPmfFFthhE00vqsZb5XGfqey FA0LR5/x1D/zOr9Eqm3MAr3zM8P/QQlx2eWRuWeH9jjpPyP7XJiuJKuTZKAPRqE3yEJB zxMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9CHa3z7ibh+wQwKi0QxjDP31H6eY49wbJnmXPqH4vEs=; b=rW8FX5l6jJup+Iu6scFDQlC69w127iKy9tB2FH//Es9HJtWiV+vw6ATvoA49BIZdfX FaGsiZC5wMaZHdXi2dYP/RLIYkPcKxlljaQeh6rH5vpcBr5pj68FRVLDQFwY+pRuWgkO pAvhAG3MsUDTfNIapbferXlZIKoUHReE4GauEtcZi+o9tQS/vkojeRpvSO94fdhYehF8 5Rjxv6oRJKyXI2Vf7sDmJq1p74qpljxBM4K/U+efl3k79AaDKbqe9bl0CdLDyO4DV9nL Di5L/xgtKlbuqmoudogsBRy7a+cMe4a/PtQ7cONZWeeqWPDNrE4Nrg+7lqrEaLfPfRWy r8fA== X-Gm-Message-State: AOAM532nrbZKRn/T832kN+vCaGGiVxnQQbhq5VrdHw+fzLgJrUe0cPsB yKFWg95tM5bdDOw4OmLxWHKZsbP1ZMDO X-Google-Smtp-Source: ABdhPJwvmxGR2HmvRtuUS/J94MTiYcqdotB05r9WJ+CIHBjVgXUCcTn4IT9azdlG9I4wctNMHGtJkcJznRlb X-Received: from venture.svl.corp.google.com ([2620:15c:2a3:200:c75c:8ce4:97cf:a279]) (user=venture job=sendgmr) by 2002:a5b:d0a:: with SMTP id y10mr56428ybp.385.1643219940958; Wed, 26 Jan 2022 09:59:00 -0800 (PST) Date: Wed, 26 Jan 2022 09:58:49 -0800 In-Reply-To: <20220126175850.1904968-1-venture@google.com> Message-Id: <20220126175850.1904968-2-venture@google.com> Mime-Version: 1.0 References: <20220126175850.1904968-1-venture@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 1/2] linux-user: rt_sigprocmask, check read perms first From: Patrick Venture To: laurent@vivier.eu Cc: qemu-devel@nongnu.org, scw@google.com, Patrick Venture X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b4a (failed) 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::b4a; envelope-from=35IvxYQcKCtcO7GMNK79HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--venture.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -87 X-Spam_score: -8.8 X-Spam_bar: -------- X-Spam_report: (-8.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1643220585624100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shu-Chun Weng Linux kernel does it this way (checks read permission before validating `ho= w`) and the latest version of ABSL's `AddressIsReadable()` depends on this behavior. c.f. https://github.com/torvalds/linux/blob/9539ba4308ad5bdca6cb41c7b73cbb= 9f796dcdd7/kernel/signal.c#L3147 Reviewed-by: Patrick Venture Signed-off-by: Shu-Chun Weng Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5950222a77..34bd819e38 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9508,6 +9508,13 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, } =20 if (arg2) { + p =3D lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t)= , 1); + if (!p) { + return -TARGET_EFAULT; + } + target_to_host_sigset(&set, p); + unlock_user(p, arg2, 0); + set_ptr =3D &set; switch(how) { case TARGET_SIG_BLOCK: how =3D SIG_BLOCK; @@ -9521,11 +9528,6 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, default: return -TARGET_EINVAL; } - if (!(p =3D lock_user(VERIFY_READ, arg2, sizeof(target_sig= set_t), 1))) - return -TARGET_EFAULT; - target_to_host_sigset(&set, p); - unlock_user(p, arg2, 0); - set_ptr =3D &set; } else { how =3D 0; set_ptr =3D NULL; --=20 2.35.0.rc0.227.g00780c9af4-goog From nobody Tue May 7 08:43:38 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=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1643220899; cv=none; d=zohomail.com; s=zohoarc; b=FzPYPC4WZ2ysu+g0TBHvGN8QFIVWxVmzeK1/u64zN+PX34AHGHRjKldLbhLODlZbz+Y/g1NoJl/6s/1CkoJyqf2bQpNyvkIa0xgiFTesLYHXpb33RzmR1braW6H5Vua72jqoQHOzyy/ms5mvu3jrgeQqYrlL4TbjLCAEIGD6q3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643220899; h=Content-Type: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=fgS+QNTtfMyzoGQEpgY8eyTtvHgIOBV5p9Tua/RmFdA=; b=UTQiZWF/fxzAZGz1iO1Vu7DPdtGi9otbevTGt6ibd7YPRWPlpwQxyxURTJrhnj+jtfmbl45Rbac+PtY4SNqjYN3NPPezoeI7ejlBBwjWWTH6IfSBDt3G+ZI2QOAtENQGHgkJ0e8f8p8KCl3zL4if12gDff3gUhNzvetOZSb5z3I= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643220899638291.59310064971567; Wed, 26 Jan 2022 10:14:59 -0800 (PST) Received: from localhost ([::1]:47142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCmos-0002DF-Fy for importer@patchew.org; Wed, 26 Jan 2022 13:14:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <36IvxYQcKCtsSBKQROBDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--venture.bounces.google.com>) id 1nCmh8-00009w-8B for qemu-devel@nongnu.org; Wed, 26 Jan 2022 13:06:58 -0500 Received: from [2607:f8b0:4864:20::a49] (port=55277 helo=mail-vk1-xa49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <36IvxYQcKCtsSBKQROBDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--venture.bounces.google.com>) id 1nCmh6-0002GY-9e for qemu-devel@nongnu.org; Wed, 26 Jan 2022 13:06:57 -0500 Received: by mail-vk1-xa49.google.com with SMTP id d14-20020a056122032e00b00320364e9d66so131884vko.21 for ; Wed, 26 Jan 2022 10:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fgS+QNTtfMyzoGQEpgY8eyTtvHgIOBV5p9Tua/RmFdA=; b=W+cNmYtpWtjHjzixv0dicxr+tblXcZOwaaVCfVZhrIJaJPv7milz+PqVRbwnUGV8MU Pb60r2dLV6dWmsjnOTEwoTSjHhMhSJfqicCqMCUNnVusQJgTdsLouC7iV2GQdmHZhmlX ultTmHapp8PmnYjrKwPrfW/aMG421+u/4LNCzWwQrRNCvFnRBZlGxf7Sx3THgoCtfr2F miOB/NgHrRUCa2CN9WCY6fIqU1OJ3Au7K2VNOujwvMkCvRG1p/nQzcy9A8MLVvfLzwoN LnjV0L7NQdB0q41UH5dGdKuwOWLrIynWR5VHStv7V7MWrAvV4e1Qmozfj+lDCfK9h7MY wlnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fgS+QNTtfMyzoGQEpgY8eyTtvHgIOBV5p9Tua/RmFdA=; b=09yd+CduJ0xol/AXYD23EYbHzAV0nHesVsSocQQ3t65OwqPhSWAVDMeK02cgbunqK0 rHnKmiIyBxfeOybCUVvmv7yxzJgDzOoaWyM7ZN3uTZHeolaZMoUdVpBh/89/l8vCs6Vf S1CTLJ3e8yZhSYpGGmnL5SzIyJ7hg7Ca9dwGsabTM0bhCLmMXy9WImFNH8rVmNKucx2Y tuX+e+0Sp9h9039LcReVowamFVjAVYXkl9xt6GnJ8bwn/XtwgPCe8d6h0OpNb7aV8r5L 9mOW8rt40MrfLD5ohWNktMajNKzfFlCopa4MNwSk6/ka5+BeTA13LAzbaTgj2mEbvyDV bxxA== X-Gm-Message-State: AOAM531b0Om37hh6AmKjTbo/3Q8SkevZV8EbvOYrQBMMUTaJDCoH29Vm rPqzOXZSMfmre2giqmEw1O0SXF9yFudC X-Google-Smtp-Source: ABdhPJzc0zh6wcaWylCJ58AI8TjuXMfytURKa4jaEtddR2co1TL2X0nEtBkP9eMjspqabLc6hepk1QttOpIS X-Received: from venture.svl.corp.google.com ([2620:15c:2a3:200:c75c:8ce4:97cf:a279]) (user=venture job=sendgmr) by 2002:a81:4e8a:0:b0:2cb:4b73:47c9 with SMTP id 00721157ae682-2cb4b734c3emr6745537b3.380.1643219944111; Wed, 26 Jan 2022 09:59:04 -0800 (PST) Date: Wed, 26 Jan 2022 09:58:50 -0800 In-Reply-To: <20220126175850.1904968-1-venture@google.com> Message-Id: <20220126175850.1904968-3-venture@google.com> Mime-Version: 1.0 References: <20220126175850.1904968-1-venture@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v2 2/2] linux-user: sigprocmask check read perms first From: Patrick Venture To: laurent@vivier.eu Cc: qemu-devel@nongnu.org, scw@google.com, Patrick Venture X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::a49 (failed) 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::a49; envelope-from=36IvxYQcKCtsSBKQROBDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--venture.bounces.google.com; helo=mail-vk1-xa49.google.com X-Spam_score_int: -87 X-Spam_score: -8.8 X-Spam_bar: -------- X-Spam_report: (-8.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1643220903615100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Linux kernel now checks the read permissions before validating `how` Suggested-by: Laurent Vivier Signed-off-by: Patrick Venture Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 34bd819e38..210483d4e4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9465,6 +9465,13 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, int how; =20 if (arg2) { + p =3D lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t)= , 1)); + if (!p) { + return -TARGET_EFAULT; + } + target_to_host_old_sigset(&set, p); + unlock_user(p, arg2, 0); + set_ptr =3D &set; switch (arg1) { case TARGET_SIG_BLOCK: how =3D SIG_BLOCK; @@ -9478,11 +9485,6 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, default: return -TARGET_EINVAL; } - if (!(p =3D lock_user(VERIFY_READ, arg2, sizeof(target_sig= set_t), 1))) - return -TARGET_EFAULT; - target_to_host_old_sigset(&set, p); - unlock_user(p, arg2, 0); - set_ptr =3D &set; } else { how =3D 0; set_ptr =3D NULL; --=20 2.35.0.rc0.227.g00780c9af4-goog