From patchwork Fri Jun 2 13:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 70508 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE83B3858431 for ; Fri, 2 Jun 2023 13:20:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE83B3858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685712016; bh=Dti2iBTY2tuALU3vkz/WWbCcIUqybJITHfduPsSbmT0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NpSMrr6zd+/am+h9ywRDoCe++dqgKxRODfMlQrap5iLhw35DwtNHS/DsKahFS1KOq LpxYIOtcP7xjJWIm1JchDLxmWgUeW1M8GaYzAdjIro09wPh0U5hrwB6HYbCV4lP2U1 bFm/crfouUqSehBnI4q8QqyacEIL9gp0lA65lpOg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 88583385781F for ; Fri, 2 Jun 2023 13:19:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88583385781F Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6af8b25fc72so1723876a34.3 for ; Fri, 02 Jun 2023 06:19:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711992; x=1688303992; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dti2iBTY2tuALU3vkz/WWbCcIUqybJITHfduPsSbmT0=; b=cxecI1bl5p3PzSFu1Dk58XtgDAxZ+VuFll39FtckVJI+scUnGE56xK/h5nRym24ugj WqjAvLsf83SVRPhDAIslqRwL4/x2qZpZb7YLURlW3aoSN2NCsXOb1zRtdnG3d20H8DZe FajlBmyDPKX6iAXq9xIoeH7CGoSGX0BduGuazld4PSrwBReQILW8OMC1whHTa23qlcQ0 cJkHow5wneVo2ZX5XdHZ06EFlvDLAnhjlLKIdVZh447mcWK0EiTGPKThGQNHyayXeBnl phFjAw58lXdUwu52zLuwmB/hQp31Kj32Bq3hP5XTBXYkqSJPhpuSS7RZhrn1h2aNC/85 HXIg== X-Gm-Message-State: AC+VfDyRCaKf9R8wdEGlS2z+cPqeVF880cRRkgi+As1rVequrKWTOE3Y Y9hYGHV+JWlM+KGc7suL9FZqpC0BVwn79GlfyuZVrA== X-Google-Smtp-Source: ACHHUZ66Vh1MWZbq11qFlG9kTkXGQcoY/+oWJRqBMUNPp8cPwg0QLlhHRZhUWsruwGxUOCWCUx4wPQ== X-Received: by 2002:a9d:4e93:0:b0:69f:578a:d1ea with SMTP id v19-20020a9d4e93000000b0069f578ad1eamr2896874otk.32.1685711992345; Fri, 02 Jun 2023 06:19:52 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:fe49:2366:8bb3:f3aa:b9fc]) by smtp.gmail.com with ESMTPSA id f6-20020a056830204600b00697be532609sm554191otp.73.2023.06.02.06.19.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:19:51 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Fail as unsupported if personality call is filtered Date: Fri, 2 Jun 2023 10:19:48 -0300 Message-Id: <20230602131948.29191-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Container management default seccomp filter [1] only accepts personality(2) with PER_LINUX, (0x0), UNAME26 (0x20000), PER_LINUX32 (0x8), UNAME26 | PER_LINUX32, and 0xffffffff (to query current personality) Although the documentation only state it is blocked to prevent 'enabling BSD emulation' (PER_BSD, not implemented by Linux), checking on repository log the real reason is to block ASLR disable flag (ADDR_NO_RANDOMIZE) and other poorly support emulations. So handle EPERM and fail as UNSUPPORTED if we can really check for BZ#19408. Checked on aarch64-linux-gnu. [1] https://github.com/moby/moby/blob/master/profiles/seccomp/default.json Reviewed-by: Florian Weimer --- sysdeps/unix/sysv/linux/tst-personality.c | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sysdeps/unix/sysv/linux/tst-personality.c b/sysdeps/unix/sysv/linux/tst-personality.c index e730650e5b..6ad192ef0e 100644 --- a/sysdeps/unix/sysv/linux/tst-personality.c +++ b/sysdeps/unix/sysv/linux/tst-personality.c @@ -19,27 +19,36 @@ #include #include +#include static int do_test (void) { - int rc = 0; unsigned int test_persona = -EINVAL; unsigned int saved_persona; errno = 0xdefaced; saved_persona = personality (0xffffffff); - if (personality (test_persona) != saved_persona - || personality (0xffffffff) == -1 - || personality (PER_LINUX) == -1 - || personality (0xffffffff) != PER_LINUX - || 0xdefaced != errno) - rc = 1; - - (void) personality (saved_persona); - return rc; + unsigned int r = personality (test_persona); + if (r == -1) + { + /* The syscall argument might be filtered by kernel, so the + test can not check for the bug issue. */ + if (errno == EPERM) + FAIL_UNSUPPORTED ("personality syscall argument are filtered"); + FAIL_EXIT1 ("personality (%#x) failed: %m", test_persona); + } + + TEST_COMPARE (r, saved_persona); + TEST_VERIFY (personality (0xffffffff) != -1); + TEST_VERIFY (personality (PER_LINUX) != -1); + TEST_VERIFY (personality (0xffffffff) == PER_LINUX); + TEST_COMPARE (0xdefaced, errno); + + personality (saved_persona); + + return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include