From nobody Fri May 3 15:37:33 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=1643232852; cv=none; d=zohomail.com; s=zohoarc; b=SPBvBa9a7B677QDVz708AwbsTqX8bPlpPJXCafx3CMxvIi+4B9L74T3sPDptXYGTOhv2C4gE0kagy71+jIt36QfUN6TdCvrp8+BGgrmq8vNrCUv0wd6gsUHFeSVnUKwKflF7pgS44IzO1mTDMAuo7BSGhGQxkPzskjsmbLDGh5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643232852; 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=iyWbyef8NHlaoWllNSDyw+o1ffCncediRvKWa3WPyvY=; b=IUdrab1dfjJWtTlEnvWltyNanTphb0Y5clGTUh+WD4GZl3jPNBw1VUnA9wacVLB6gHQ0kJBZxx7FKIDMYEaAhutKi67Gvs3kuw6Y5TxLWlZBe7s6T/N4T1r6SH3/9kPywiHl7SufuahcOqGpmWOr2+kbp4R3Z3kjnW5/PFBHEYM= 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 1643232852258587.6052977767125; Wed, 26 Jan 2022 13:34:12 -0800 (PST) Received: from localhost ([::1]:49838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCpve-0006fe-PS for importer@patchew.org; Wed, 26 Jan 2022 16:34:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3b7zxYQcKCsQ5ox341oqyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--venture.bounces.google.com>) id 1nCpuP-0005zF-HR for qemu-devel@nongnu.org; Wed, 26 Jan 2022 16:32:54 -0500 Received: from [2607:f8b0:4864:20::a49] (port=56028 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 <3b7zxYQcKCsQ5ox341oqyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--venture.bounces.google.com>) id 1nCpuM-0000YB-TO for qemu-devel@nongnu.org; Wed, 26 Jan 2022 16:32:52 -0500 Received: by mail-vk1-xa49.google.com with SMTP id b26-20020ac5c4fa000000b0031fa5646ccaso329839vkl.22 for ; Wed, 26 Jan 2022 13:32:48 -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=iyWbyef8NHlaoWllNSDyw+o1ffCncediRvKWa3WPyvY=; b=nOxPsZN7N9DWftMrbW0RhZYn+nLOnR/m8HLFg4XdJoFKG7K6h8T7c9sy2t3EceA+1Q UOh5jmHA2gmwt3bJDN7oAaPAb/Srh3yJ3p/MIfpiw+zkNEa/Ejvnzm6fj8S9lRt5yfLt zVCozL6ZGwflbLy/QXBalOvZK2YCpuFbF+aCr4t1TmWEn5qs9eK1lG+m3BDUhsex7nI0 XpNb8xnVAvMl++oTG3IoZxipQWAeKyqQ3h5lqH8u2MxkOYl13PTiRUnoA0Kt6ZYMIV4v oFl0F4fQifOk0Y8f+DZuRlp7B8JWrfDo/vO8VD/jR5HLJM1mD1klnZk6AQqJy/nG5kU1 Bs2Q== 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=iyWbyef8NHlaoWllNSDyw+o1ffCncediRvKWa3WPyvY=; b=0oDJcfEpiR44Eq95hwmQFTkpENNeFpZ+yPrY1xXBzhjU6jW9fqyovc78RKtIdWUc7d nsGKnFV9bf+GCSdU+tUGq9/y+cbQR6B6Y9OHWFUTdEMzRLL8+lB+j2GOsazLNru2+peF U8SNO63x7gyIiYu00aIbi5FdoEfbfQcWlHAoCH98Y+UHqB/TCBR2RBQ0RpAjoncrdrcs mjdb86C+aXOu/PQM1Uzzf62VFnCJi9/j0hc6T+BNfga9+k7tsYbZHtrWshdkIaFJRvsy A3D3fjwmyw07xIb4VKz7AkM/XuCoe+4KjAc/vzBjY5cQakN8AkxtKIoj4YOGw7zihrkF whTg== X-Gm-Message-State: AOAM532bSzKZxTODuDr56M3+RAMeZNj4w+aCRkTEJzWKmSkgJFACbS4O 14I0EVL1jYPcHF9CADUZqw7E/QwGZdzL X-Google-Smtp-Source: ABdhPJwgJRovEXaRsj/WDip0215IuDpE+lgiJT9d94y1LcvR22kNw0nKS8jUB2lrQZnZsdf+q5FbazO4IXc7 X-Received: from venture.svl.corp.google.com ([2620:15c:2a3:200:c75c:8ce4:97cf:a279]) (user=venture job=sendgmr) by 2002:a81:a241:: with SMTP id z1mr0ywg.250.1643232367622; Wed, 26 Jan 2022 13:26:07 -0800 (PST) Date: Wed, 26 Jan 2022 13:25:58 -0800 In-Reply-To: <20220126212559.1936290-1-venture@google.com> Message-Id: <20220126212559.1936290-2-venture@google.com> Mime-Version: 1.0 References: <20220126212559.1936290-1-venture@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v3 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::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=3b7zxYQcKCsQ5ox341oqyyqvo.myw0ow4-no5ovxyxqx4.y1q@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: 1643232854458100001 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 Signed-off-by: Patrick Venture --- 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 Fri May 3 15:37:33 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=1643232419; cv=none; d=zohomail.com; s=zohoarc; b=E4JgghuZZPn576CqS+byjc4tYlkRYgDrHiePcbHXLig+y8egW4WOHRv2dEOYvz0QxF/XqRD/Fg+tObTbElX583NzLbthM3HZVy6RJBB8t8nnAE82nmntq2hBVmO4TLcLTLupipXOwcH/aaeS1T9pGdJO+uak9CzD4oiOeP/Kuj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643232419; 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=v4QEmUI9SkK9M3C8zfYhP5Whu+uSZGt4xx3pkgtBF14=; b=jJkZ92eAFZE7eWHnEH6uy9LQnKY1RmMrWbrPd8ZkYrTAhXIzUsFog51BtphPkQDASr59NN7TnLE6vUdyR0XUWVyXEH3vLhHOHZHENs+UjO7x3hiQK1I+40P85EQ+SlcUzzF8dx5cFI9jGwsaLdR9pi+Xxms0OXBnZ7lIVQmAYMQ= 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 16432324192691023.2270063754545; Wed, 26 Jan 2022 13:26:59 -0800 (PST) Received: from localhost ([::1]:44322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCpog-0002vK-3G for importer@patchew.org; Wed, 26 Jan 2022 16:26:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3dbzxYQcKCsoBu39A7uw44w1u.s426u2A-tuBu1343w3A.47w@flex--venture.bounces.google.com>) id 1nCpo0-00028Q-8Y for qemu-devel@nongnu.org; Wed, 26 Jan 2022 16:26:16 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=33734 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 <3dbzxYQcKCsoBu39A7uw44w1u.s426u2A-tuBu1343w3A.47w@flex--venture.bounces.google.com>) id 1nCpny-0007yb-MT for qemu-devel@nongnu.org; Wed, 26 Jan 2022 16:26:15 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id u185-20020a2560c2000000b0060fd98540f7so1893120ybb.0 for ; Wed, 26 Jan 2022 13:26:13 -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=v4QEmUI9SkK9M3C8zfYhP5Whu+uSZGt4xx3pkgtBF14=; b=aapteQWbcpvw1Fji5i9BzsxkgDW3YSndFI9mhyNP7z4NMVg/y6K06OSKMdopGUSWJG dMMqGbq2C5ASKy1nRB6eSmsGWbhngJxrkCtsSeeOyR/1KnfdEUjBACMDaBgPxIHVb9aq 0CjogE9wF2I/PsdpvYCyevp/tjVIwqtCTtvHEKZ9KpYXqLjzTtLcgntITjSVSwMDgxYM XPTsOQUN6/umt1ETHeHi3/JlqJ0WKCbcC6y6pfBo5yd50Spx0hDEfdfoZhScz7jffb4o HiEj4ETAyUeJQWMtGnLc6P4OqvfMkoeM9q8uk6En+VMRdQCnlS/Sa46hGL5g535XuMsh xukA== 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=v4QEmUI9SkK9M3C8zfYhP5Whu+uSZGt4xx3pkgtBF14=; b=257LIjn3Xaf3juOtNRjDS9uGJyFHsc6Y7fAB11Ct54fnKbA6n4sTe5/Hh064yEA2ki QE+PtXX2UjZqZRCUGM3+LLg8Glc+3Nx18BUBejF1QuuwIo3KV6CKwjY29vOCF26GYjKU 0ABdxH1y7c/K5GUnGmMaTQ2NUUxQe+NOe0Fcj1Wxk6H3NguiI65Owp03LEDuj3vQ/sUI xsV6ZxxV4ASi9OwNzQlwnl/jpN/N2/FBq1tnfxR0yncL0bZ17Jk7rvHQlP863JsYFE0M 9xsL4jzJDnJsFtkdO+epo3NlhKg5VQEptHZSYwWX2/+yPeNlxk52NbnCSAYR6bduUnBn yIaQ== X-Gm-Message-State: AOAM533GZqFYwPskgydT8DN/nSyqD0qlDoVgJF9bE+gqQDehyKWhHbEh /jC0U9sUJ2C5JDYD4Myd/3dRZEAyUr/4 X-Google-Smtp-Source: ABdhPJxLjnWqAZg6LHJfQZiioNDEBF3cc0RqQWE9QRP56I4826JcphU7vrIHITdJsjFWhRFXa2kQb6llXMeF X-Received: from venture.svl.corp.google.com ([2620:15c:2a3:200:c75c:8ce4:97cf:a279]) (user=venture job=sendgmr) by 2002:a05:6902:1205:: with SMTP id s5mr1519277ybu.676.1643232373015; Wed, 26 Jan 2022 13:26:13 -0800 (PST) Date: Wed, 26 Jan 2022 13:25:59 -0800 In-Reply-To: <20220126212559.1936290-1-venture@google.com> Message-Id: <20220126212559.1936290-3-venture@google.com> Mime-Version: 1.0 References: <20220126212559.1936290-1-venture@google.com> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v3 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::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=3dbzxYQcKCsoBu39A7uw44w1u.s426u2A-tuBu1343w3A.47w@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: 1643232420706100001 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