Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp342836pxu; Wed, 25 Nov 2020 23:16:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTJV+aTS2HWOV+XL/7/r0SU+ZMBctaKYB8Fx3ulCUDo9Wm5FdrFlPKq8J7xSG3Lun/CR4e X-Received: by 2002:a05:6402:38a:: with SMTP id o10mr1243542edv.349.1606374960844; Wed, 25 Nov 2020 23:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606374960; cv=none; d=google.com; s=arc-20160816; b=MO4r0lLWrWbeVS0Yy2PvUPQDUwQKrRgh3k1pvIht2huLQ7X1c25YhB7M2NRrtXaTze apIUJXWdBrBSRiKNLu52cJG2hnbBp1YOdmfhFQ9Gf1bZEFpynj7/Aw+R3+ueOrou1WCd nmAirb1wq7XFAoyh2vr+C1R1/Viw22WN3+yT6bW9bLwcuDNf/hGNHEJo5NewUn5lHvL9 RnQem057dOXPDrYSrF3tmRQxenp/Rsk+f21VsdbzvdWsaV4vRCO0nNNDPHC3tEjXHrRI szXLDrI6aTN4iI6fDBkFgAN9kyAOoF4eMeuMVaD97+DF46SvPItR3qGTa8WldmO4FQM5 rZsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NIpG45UWwddpGV+62KwVJM4R9vkmQaVM+kUHYytsuOk=; b=zc0o5NUeKw3ZksQIoJvyNmTGLG3S+a8xgJSyFAm6Z41izyMesXzlYAV2Yhc/DrCiX5 nM7XAlop7H4LjvXk8A64/4I3kl0GH+F75n0SbfgsvaBn6/t2mk57I19xHMj2USC8hI75 DT84WqKUHBEKjwtDFrd1hKXjhb3A0Igjv5fI7mLpsCozMSxa/gG3o6MsA5p8VBpgILWH f9S/7hZ7ZUBAokftxg45aUR2wKExZ1A+WyiocMiUUWX19QOylZkeuAiNld8qJvS+9VaS MgWl7fk3Pf6Pw8GBMfvcQH2PVkYDP5SJR4yttwE/dnbRY5HVzjGiEimfGfn5Q+4k71ow 1w0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kWV6G2yZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si2601952edb.100.2020.11.25.23.15.37; Wed, 25 Nov 2020 23:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kWV6G2yZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732442AbgKYSOy (ORCPT + 99 others); Wed, 25 Nov 2020 13:14:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730643AbgKYSOy (ORCPT ); Wed, 25 Nov 2020 13:14:54 -0500 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE93AC0613D4; Wed, 25 Nov 2020 10:14:53 -0800 (PST) Received: by mail-io1-xd42.google.com with SMTP id m13so3040895ioq.9; Wed, 25 Nov 2020 10:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NIpG45UWwddpGV+62KwVJM4R9vkmQaVM+kUHYytsuOk=; b=kWV6G2yZXMm4VSHbnojYmPa+C5P3JnpUTHqE23CMhNkQBQWRzmmhqOLBUtQv2atXCT gfx8m7eCmFJ7pVlsuccPiH6QWEPUd8AOsN93MuFELIyPMSRf5jsCMU0WOq//RI0OE3v8 Xcdy8XkXYHOwwkywVeuV38sTpPsttpVy3JvqUPqjjnzwH11K8V/hcwvS5Z9IHaMrKIUK 5aPycy8OBpj2x7nvopzyosAyOu5TyhaWlUYzEp+8JqfTnIOXSNZZFCbA0rFGLuslWfdY 0h9j9VHpYmDhGDt0sVob662k93U0Re/54lGaFjmxi8C+L9fpuTq3YUdx9b9EMjfmYlAP xBkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NIpG45UWwddpGV+62KwVJM4R9vkmQaVM+kUHYytsuOk=; b=eGNs1ZBLBayuVA4HFTYdwRRp2B6JX5sBFZu9gdbQXp7ZkUya3FzV3rNyLsIaXdh2fl 1hQVdNaU/cI4mn4GB6XdOTFgRjLyBuUNfVBU2Z3gWB7RYJm69S8+NnaWho44nF792gC0 m9/tuZkaVbKSINvAVLeZLKT1105l/4jdMX2EaRAHu2NQUWMkZiJUZ2p7NZJW7RN0SWjd 5g/5eUxANUESc3xvKVXaQDvpAGH66XBCSRsdWnA2DeB/mEBI//RsTVYavGsCHo9s6O58 TtbjsxqiahEdB+eL3UWU6sF1XuHw5r6SL2FNZgNfVIHPIzvePpZQ1RHKLz8pDGjqmEfC N8uA== X-Gm-Message-State: AOAM531jHlFCHk4UC5pcbvGttDLYkCbgoo6zlgxUMds69xaYUmoWI5hh vvs65c/j52dhKSxTH0IKtPfC/znq5UeUzz7EIkQ= X-Received: by 2002:a5e:a815:: with SMTP id c21mr2793016ioa.141.1606328093153; Wed, 25 Nov 2020 10:14:53 -0800 (PST) MIME-Version: 1.0 References: <30b491ad-a7e1-f7b5-26b8-2cfffc81a080@huawei.com> In-Reply-To: From: Yury Norov Date: Wed, 25 Nov 2020 10:14:42 -0800 Message-ID: Subject: Re: [Question] About SECCOMP issue for ILP32 To: Xiongfeng Wang Cc: bobo.shaobowang@huawei.com, Catalin Marinas , Arnd Bergmann , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-api@vger.kernel.org" , Adam Borowski , Alexander Graf , Alexey Klimov , Andreas Schwab , Andrew Pinski , Bamvor Zhangjian , Chris Metcalf , Christoph Muellner , Dave Martin , "David S . Miller" , Florian Weimer , Geert Uytterhoeven , Heiko Carstens , James Hogan , James Morse , Joseph Myers , Lin Yongting , Manuel Montezelo , Mark Brown , Martin Schwidefsky , Maxim Kuvyrkov , Nathan_Lynch , Philipp Tomsich , Prasun Kapoor , Ramana Radhakrishnan , Steve Ellcey , Szabolcs Nagy Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 31, 2020 at 11:15 AM Yury Norov wrote: > > On Mon, Aug 31, 2020 at 5:48 AM Xiongfeng Wang > wrote: > > > > Hi Yury, > > > > Hi Xiongfeng, > > [restore CC list] > > Haven't seen this before. What kernel / glibc / ltp do you use? > > > We were testing the ILP32 feature and came accross a problem. Very apperaciate > > it if you could give us some help ! > > > > We compile the LTP testsuite with '-mabi=ilp32' and run it on a machine with > > kernel and glibc applied with ILP32 patches. But we failed on one testcase, > > prctl04. It print the following error info. > > 'prctl04.c:199: FAIL: SECCOMP_MODE_STRICT doesn't permit read(2) write(2) and > > _exit(2)' > > > > The testcase is like below, syscall 'prctl' followed by a syscall 'write'. > > prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); > > SAFE_WRITE(1, fd, "a", 1); > > > > When we execute syscall 'write', we receive a SIGKILL. It's not as expected. > > We track the kernel and found out it is because we failed the syscall_whitelist > > check in '__secure_computing_strict'. Because flag 'TIF_32BIT_AARCH64' is set, > > we falls into the 'in_compat_syscall()' branch. We compare the parameter > > 'this_syscall' with return value of 'get_compat_model_syscalls()' > > The syscall number of '__NR_write' for ilp32 application is 64, but it is 4 for > > 'model_syscalls_32' returned from 'get_compat_model_syscalls()' > > So '__secure_computing_strict' retuned with 'do_exit(SIGKILL)'. We have a > > modification like below, but I am not sure if it correct or not. > > > > --- a/kernel/seccomp.c > > +++ b/kernel/seccomp.c > > @@ -618,7 +618,7 @@ static void __secure_computing_strict(int this_syscall) > > { > > const int *syscall_whitelist = mode1_syscalls; > > #ifdef CONFIG_COMPAT > > - if (in_compat_syscall()) > > + if (is_a32_compat_task()) > > syscall_whitelist = get_compat_mode1_syscalls(); > > It calls the arch function from generic code. It may break build for > other arches. > This also looks dangerous because it treats ILP32 execution as non-compat. > > The right approach would be implementing arch-specific > get_compat_mode1_syscalls() > in arch/arm64/include/asm/seccomp.h that returns an appropriate table. > Refer MIPS > code for this: arch/mips/include/asm/seccomp.h > > Thanks, > Yury > > > #endif > > do { > > > > > > Thanks, > > Xiongfeng > > The fix is on my repo; versions 5.2 and 4.19 are updated: https://github.com/norov/linux/commits/ilp32-4.19 https://github.com/norov/linux/commits/ilp32-5.2