From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C82DC433B4 for ; Fri, 23 Apr 2021 10:52:10 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D3DD60698 for ; Fri, 23 Apr 2021 10:52:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D3DD60698 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=linux-audit-bounces@redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-U24mTzZLNQmAXkS6zA9mng-1; Fri, 23 Apr 2021 06:52:06 -0400 X-MC-Unique: U24mTzZLNQmAXkS6zA9mng-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEECB10053ED; Fri, 23 Apr 2021 10:52:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B31681002EE6; Fri, 23 Apr 2021 10:52:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8EFA11806D1C; Fri, 23 Apr 2021 10:52:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13NAa6iJ003918 for ; Fri, 23 Apr 2021 06:36:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4F23521C3556; Fri, 23 Apr 2021 10:36:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4975C21C3551 for ; Fri, 23 Apr 2021 10:36:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76F968533B5 for ; Fri, 23 Apr 2021 10:36:03 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2074.outbound.protection.outlook.com [40.107.237.74]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-AnQgpBx-OHynv5i98IGIKw-1; Fri, 23 Apr 2021 06:35:59 -0400 X-MC-Unique: AnQgpBx-OHynv5i98IGIKw-1 Received: from MWHPR1101MB2351.namprd11.prod.outlook.com (2603:10b6:300:74::18) by MWHPR1101MB2192.namprd11.prod.outlook.com (2603:10b6:301:59::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Fri, 23 Apr 2021 10:35:58 +0000 Received: from MWHPR1101MB2351.namprd11.prod.outlook.com ([fe80::c156:455d:860e:ba87]) by MWHPR1101MB2351.namprd11.prod.outlook.com ([fe80::c156:455d:860e:ba87%4]) with mapi id 15.20.4065.024; Fri, 23 Apr 2021 10:35:58 +0000 From: He Zhe To: oleg@redhat.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, paul@paul-moore.com, eparis@redhat.com, linux-audit@redhat.com, linux-kernel@vger.kernel.org, zhe.he@windriver.com Subject: [PATCH v2 2/3] arm64: syscall.h: Add sign extension handling in syscall_get_return_value for compat Date: Fri, 23 Apr 2021 18:35:32 +0800 Message-Id: <20210423103533.30121-2-zhe.he@windriver.com> In-Reply-To: <20210423103533.30121-1-zhe.he@windriver.com> References: <20210423103533.30121-1-zhe.he@windriver.com> X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: CY4PR19CA0041.namprd19.prod.outlook.com (2603:10b6:903:103::27) To MWHPR1101MB2351.namprd11.prod.outlook.com (2603:10b6:300:74::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-lpg-core2.corp.ad.wrs.com (60.247.85.82) by CY4PR19CA0041.namprd19.prod.outlook.com (2603:10b6:903:103::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Fri, 23 Apr 2021 10:35:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f28e30c-dbb0-4d32-afd3-08d90643939e X-MS-TrafficTypeDiagnostic: MWHPR1101MB2192: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: OQb4Xtc3URswsbP0UHi73MaMObWyT5y1UWASUG3g7fuhwEL4EYMstfjAEbR02MTSjoE1t17toiZALySrkdRnM4ReMMasnl94xz77TdNOmdsXDi2CyKYvqpRSIQiFlrQfrM2vQwONsteEUGPNMbp/YqVVNrlES8TIcKhwxohEyYzckmuy/3S7gGee8DNDIOvj9TU6ZMcdDHY7mmZgN22kVTTTf+Jsvk2ru7Fm+d7TH1T94N8B7u+R3A2Gp3iR6yyoyFsDIuDz/8qvAOapWxyAUSw6Zeu4QKvRBL10/vjAjwGcomI9E7SQLoYEd0fhruUr8D5CxGPIR/u/JjmYukbPmjT1U32uzXHyD4MC9g5YUwKSBqGt78kwVzp2OnebIzAVJC1KW9vlLV/KvmSQjVto87Y+2Io95llw+VM7aSiCUZmEi/UPHOSRti1tWKm6C0GgEPArhyGbT6lcvYG3lAWZPSEm2vu+5EZOszhKRCZO1UK2Yg70SVTACDX3yoYbEL/bZQ8rToD5h9JZnUXvgT0Y6IqaLyNJH1YasoMu9WaRY9RlAgwQHX5cX5kvJjRsEcMNbonNUh58MpjJYlUcs4yXgSaWWz4ezkfLkixz89MqGjptjVtip7+b2JeZG8Ot3XFoojysb3148Tvp1whT9ikeEWMK85Dw235Ww5pZCzOpdMs= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1101MB2351.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(39850400004)(396003)(136003)(366004)(52116002)(38100700002)(86362001)(38350700002)(8676002)(6486002)(8936002)(6512007)(26005)(186003)(16526019)(316002)(6666004)(1076003)(6506007)(478600001)(2906002)(5660300002)(66946007)(2616005)(83380400001)(956004)(66476007)(66556008)(36756003); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?caomrY6hgNAKBbvoXixZHPre/wmowBpTGRWkh0DkadTgIBDXSJtUcbRGEhX/?= =?us-ascii?Q?GgX1ODnjOCNEeHKXLBifmgK4n1F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sPaFANmTQSTsaFAlikXtNgHQskY9VuCDL+lK0t8HUntopc6MBNEu5JpY?= =?us-ascii?Q?q7tfrHSRmmXt4U/98jTjGVFza6x0Tip2JhJ5ns/MDBwyJkxOLDCmqED2F5dU?= =?us-ascii?Q?guYQ2V861SPwWqquf/lIBWj6LIGahI85clwvh/QGF3F14Urug+uuDWzLiHiT?= =?us-ascii?Q?qksx9l39CHPl1AbEIFx8tHVmp0Kue2BWNenlxFvon4TY6MnhGxoN8Dy762ZP?= =?us-ascii?Q?epoxK9845Ux2AZxLoKzQZkpHYXyaq0q5KiEpy06ps+ih/0MzCRs7jtDpUGaF?= =?us-ascii?Q?FlKOzFShmdA7S/Z7Y63uJngIT+lm3KooIzgm3gkif414gcXPhDC76llcHcZa?= =?us-ascii?Q?jIfkFzCb2Fi6VcjPBwVLbKoE?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f28e30c-dbb0-4d32-afd3-08d90643939e X-MS-Exchange-CrossTenant-AuthSource: MWHPR1101MB2351.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2021 10:35:58.0672 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GfBm4xr20QaNeidFkyp8vSIbKrXJuxQ/z22S6gDQM4TihvtS1/IEcGB0LxRIsRq+dZ3heaALeppvLDTmfWOMVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1101MB2192 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: linux-audit@redhat.com X-Mailman-Approved-At: Fri, 23 Apr 2021 06:50:23 -0400 X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Add sign extension handling in syscall_get_return_value so that it can handle 32-bit compatible case and can be used by for example audit, just like what syscall_get_error does. Suggested-by: Mark Rutland Signed-off-by: He Zhe --- v1 to v2: Improve error code check suggested by Mark arch/arm64/include/asm/syscall.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index cfc0672013f6..c3b5fca82ff4 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -44,7 +44,20 @@ static inline long syscall_get_error(struct task_struct *task, static inline long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { - return regs->regs[0]; + long val = regs->regs[0]; + long error = val; + + if (compat_user_mode(regs)) + error = sign_extend64(error, 31); + + /* + * Return codes with bit 31 set may or may not be an error code. + * For example, mmap may return a legal 32 bit address with bit 31 set + * for 32 bit thread, in which case the untouched val should be + * returned. Otherwise, the sign-extended error should be returned if + * it still falls in error number range. + */ + return IS_ERR_VALUE(error) ? error : val; } static inline void syscall_set_return_value(struct task_struct *task, -- 2.17.1 -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit