Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp123294pxb; Wed, 18 Nov 2020 18:34:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp0h0QlagvP0AA1q2lfAZoUFLF0yf60gFPXL8ubNQYzlPJqKCRJSfPHH9EPrn/eoppGwrc X-Received: by 2002:a17:906:718f:: with SMTP id h15mr17050618ejk.243.1605753262787; Wed, 18 Nov 2020 18:34:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605753262; cv=none; d=google.com; s=arc-20160816; b=derBgrgpONG5dbGAg5reQirCXP21zN9Uy9pvawXaiLv3OiihoPL2e911t7WFxq95YW 6lxgsuWsQ+IQRkdW0x9BRfNWygwivAlSSF9KysrqWRwpnFAy3XPoAUR0TWRR/w4fkwQS skF0/tOukIRk3nwk66C/IaByr4LaZuUW+MuAq34TYxRXgVvpxuhhoCAyChJbxOfI7JH4 IpbSB4J7lNDPmKV70v5CFiJGYy5+BRr7PhFd6848qcTAO8SwLyE9xkrX2/lDpDOPsFj2 rGxUQ1pIkQbRrvjQd9kM23MJoFpDsrs4ccRvVCT8e1R4ebzAo3fp3zCvFS+OFYRzH3li FqdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=rx90vSXNqgCjHdEL35nvQhLOHv46OTOVVynXFyD1fxg=; b=ckAZ8C77sRmTxYAP1L2ArpcI0gXdgoHogOoh1D+JbIYmHuTOvwLea9tbHFfTzEKkaA hPUfVnnAp1hCr7eFTuhiXr00TlfEzaN7ey4Je1KGadWTrzO2pbqGYLJ8GJCVd4nNF6Fj KoDG/eqJbekzQkDvAgQ+BefOZWpdJ9mkBI8MTJEuZA5v0DfN+5AqQ8KpFiXNP7PBSufI 5C6ItmmwFYvyDl8nuhvS/Knf99KbYbioKcMpQW08CftDTMidOKMnZSsgUhnYfk0JXJku wthlLfT3+wXrJ+lJa6jcN3NP2xjO/3hyGLK7Mq4NVAobfG8wWfACkMZ+PxI7VyhVFnUR 0lzQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x7si18078657ede.597.2020.11.18.18.33.59; Wed, 18 Nov 2020 18:34:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbgKSC3V (ORCPT + 99 others); Wed, 18 Nov 2020 21:29:21 -0500 Received: from mail.loongson.cn ([114.242.206.163]:52810 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726304AbgKSC3U (ORCPT ); Wed, 18 Nov 2020 21:29:20 -0500 Received: from bogon.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxytF62LVfImASAA--.42816S2; Thu, 19 Nov 2020 10:29:15 +0800 (CST) From: Jinyang He To: Thomas Bogendoerfer , Huacai Chen , Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel Date: Thu, 19 Nov 2020 10:29:12 +0800 Message-Id: <1605752954-10368-1-git-send-email-hejinyang@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9AxytF62LVfImASAA--.42816S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tw4UGF13tw18Gw1fWw17Wrg_yoW8WF17pr nrG34xJrWUJrWjkrWUXFy5Jr1UJw1DX347XF1xtw1xZw15ur9rGF18Gry7ta4UGry0kF47 Xa4Dtr4UJr4UAFUanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkvb7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4 vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40E FcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr 0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8JwCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j7eOLUUUUU= X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These instructions consist of 6bits function field and 26bits address field. The value of target_addr as follows, ================================================================= | high 4bits | low 28bits | ================================================================= |the high 4bits of this PC | the low 26bits of instructions << 2| ================================================================= Thus, loc_orig and log_new both need high 4bits ranther than high 6bits. Replace 0x3ffffff with 0xfffffff. Signed-off-by: Jinyang He --- arch/mips/kernel/relocate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c index 3d80a51..709cfa0 100644 --- a/arch/mips/kernel/relocate.c +++ b/arch/mips/kernel/relocate.c @@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset) /* Original target address */ target_addr <<= 2; - target_addr += (unsigned long)loc_orig & ~0x03ffffff; + target_addr += (unsigned long)loc_orig & ~0x0fffffff; /* Get the new target address */ target_addr += offset; @@ -105,7 +105,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset) return -ENOEXEC; } - target_addr -= (unsigned long)loc_new & ~0x03ffffff; + target_addr -= (unsigned long)loc_new & ~0x0fffffff; target_addr >>= 2; *loc_new = (*loc_new & ~0x03ffffff) | (target_addr & 0x03ffffff); -- 2.1.0