Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp485989pxu; Wed, 14 Oct 2020 06:29:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfBwb9Gp24FyjFETdYniYYjHydBOSzMVm/i9dS7XVg03bUBOr5LEfa+wNjxdEHirRdW6q0 X-Received: by 2002:a17:906:400b:: with SMTP id v11mr5140781ejj.421.1602682179952; Wed, 14 Oct 2020 06:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602682179; cv=none; d=google.com; s=arc-20160816; b=QqpchQvidiQiR9g0MxvIVJghsxaD+ofsjiXfA2+jloFGalv7Xj02uQnPqH004qavoX KZEIZwxNYZUDpaCqQNCUcYz6IL68oKWrM8Axud27ecuEJdpmdZBIpsQ5O+QEK9omuUqD XF23q4o/nRQaidOBn30iwlPUAor92D2lIu+sn6Rzx0SRQo0PAEzn2G7dYIZGXPYOypxK 99Zb8D4Uu+QPYk79vsxYvAqKCDmg4UQnK1M16kJBew8qFXao0LjaSekkS+1NzgqbyI3b hbqwK3yzzVEZUynLUw+PQdU7SR2cr9RjVvzoKlu7QDRAu1DFUnhEP2FzY23mioFqEdXW YX0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ABiTA6hFtXP0oYeC1XbiwALLzlf+HAyRRK4UXFyPFsU=; b=HQxeh9yVhHh+Bvj39y+1JzNki20d9DmWGgc/hPB/s73YbrnTCvOS40QeOXnOhJtQYh f4LFAKyxvmB7dXKdvfMM/N79wgsGWt4ZSjN8TXBewvg7oxESDFYIIRsJiXJ6ATjh13/T TeiZYLPl+oJRvpEcbmyqli5UQ5pVcW3N/mrzkNCrGE9qhprMWKGF3zMGEhG4uven8zoS 9NH35t8ZT738YwmQ6NbLFsfo9p41qvIXAE2oUPdCF6HRIeU99xql01yy+apO9xKSBGSp u8hKQCKoqgUvgI7PaOLtWkPTKODXpuzY63qNYOvKuyPdlmss/bhPFlgZD3tkWCb588oP SELg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vy1ARA7c; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si2189740ejz.746.2020.10.14.06.29.11; Wed, 14 Oct 2020 06:29:39 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=Vy1ARA7c; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728361AbgJNHiQ (ORCPT + 99 others); Wed, 14 Oct 2020 03:38:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54058 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728242AbgJNHiM (ORCPT ); Wed, 14 Oct 2020 03:38:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602661090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ABiTA6hFtXP0oYeC1XbiwALLzlf+HAyRRK4UXFyPFsU=; b=Vy1ARA7cqg+vvg8K/WbOtuc+ddh69k005RbNoM9vlqH03yGbkHNhi1LlZl4RMhgIj+zoXs ijWtdeQ/sgHRcG1VrwV2oZTN1o5Xhhlw8wM3/HmU3Zn8Yd1bsxDfI+6fK+wO5ycERj8xlc tr6tAHFwTtlKLJ5Uau8+W1KAbPpvomo= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-97-vJkfAzBjMVaMgDOqfcfvOw-1; Wed, 14 Oct 2020 03:38:08 -0400 X-MC-Unique: vJkfAzBjMVaMgDOqfcfvOw-1 Received: by mail-wm1-f72.google.com with SMTP id i9so238927wml.2 for ; Wed, 14 Oct 2020 00:38:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ABiTA6hFtXP0oYeC1XbiwALLzlf+HAyRRK4UXFyPFsU=; b=gLpA42E6QiwpGM9ugyjymm3YjeZovLVtacBuDa+ABXhjKocXAm5Ls5viw9fm5e833O VmOcxEI6p+2Lv0pC5+5Uz7zV2Jlzb1heRtGCK1HMtTN9F6sL6Mnpj+B380D4pQprZXXK QmxKLWXsLFL/tB/XI+OVz+zl1EpJ+XvS3DjQkCsu+fUrpR9BR2ptzx7V3b2S9tyjV7GU YzAzHaekdr6MVwTF7k4r6iJddf1AD/rFo+75HZA7pjW1Tt3KMRxqQC9FW3jsFBCJrKjv oouglMRuS/uVo2xE+hgnDyx2lml2cXPLIjQhKKuzXZsEF2xJAbDMmpkYCZF0FUX+WtQ/ vthA== X-Gm-Message-State: AOAM532q2CT7yJimL/isS+W1PKX4uwEw8SD2A4RTgU4A+MIkBcWYSE1/ xrwxj8nvkYxZyc6pVoPX1qZNUuXl6WnR65iyK2qIa3GtrGKMdMGjHfM+cfP2MReQdKDAAB5rKOM Kf/WmVxVxYPFbTYVvsOPxsbSD X-Received: by 2002:a5d:6a51:: with SMTP id t17mr3894810wrw.80.1602661087401; Wed, 14 Oct 2020 00:38:07 -0700 (PDT) X-Received: by 2002:a5d:6a51:: with SMTP id t17mr3894791wrw.80.1602661087201; Wed, 14 Oct 2020 00:38:07 -0700 (PDT) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id y66sm2618360wmd.14.2020.10.14.00.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 00:38:06 -0700 (PDT) From: Julien Thierry To: linux-kernel@vger.kernel.org Cc: jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, raphael.gault@arm.com, benh@kernel.crashing.org, Julien Thierry Subject: [PATCH v3 1/3] objtool: check: Fully validate the stack frame Date: Wed, 14 Oct 2020 08:38:00 +0100 Message-Id: <20201014073802.436630-2-jthierry@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201014073802.436630-1-jthierry@redhat.com> References: <20201014073802.436630-1-jthierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A valid stack frame should contain both the return address and the previous frame pointer value. On x86, the return value is placed on the stack by the calling instructions. On other architectures, the callee need to explicitly save the return address on the stack. Add the necessary checks to verify a function properly sets up all the elements of the stack frame. Signed-off-by: Julien Thierry --- tools/objtool/check.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f50ffa243c72..87f10e726a75 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1671,12 +1671,20 @@ static bool has_modified_stack_frame(struct instruction *insn, struct insn_state return false; } +static bool check_reg_frame_pos(const struct cfi_reg *reg, + int expected_offset) +{ + return reg->base == CFI_CFA && + reg->offset == expected_offset; +} + static bool has_valid_stack_frame(struct insn_state *state) { struct cfi_state *cfi = &state->cfi; - if (cfi->cfa.base == CFI_BP && cfi->regs[CFI_BP].base == CFI_CFA && - cfi->regs[CFI_BP].offset == -16) + if (cfi->cfa.base == CFI_BP && + check_reg_frame_pos(&cfi->regs[CFI_BP], -cfi->cfa.offset) && + check_reg_frame_pos(&cfi->regs[CFI_RA], -cfi->cfa.offset + 8)) return true; if (cfi->drap && cfi->regs[CFI_BP].base == CFI_BP) @@ -1805,8 +1813,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi, case OP_SRC_REG: if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP && cfa->base == CFI_SP && - regs[CFI_BP].base == CFI_CFA && - regs[CFI_BP].offset == -cfa->offset) { + check_reg_frame_pos(®s[CFI_BP], -cfa->offset)) { /* mov %rsp, %rbp */ cfa->base = op->dest.reg; -- 2.25.4