From patchwork Wed Sep 9 23:34:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1361150 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=QdY75rDZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bn3HW3PK2z9sSJ for ; Thu, 10 Sep 2020 12:48:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730136AbgIJB7K (ORCPT ); Wed, 9 Sep 2020 21:59:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:63980 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730127AbgIJBxX (ORCPT ); Wed, 9 Sep 2020 21:53:23 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089NWE9E063609; Wed, 9 Sep 2020 19:35:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=c5K0tr2EUSh8vhEx/GnEl/mv9R9MKq/O6pEhPZpA72M=; b=QdY75rDZehVABFyDtHBLTAoPo3/Fob/71FZhzxjyGgoitdHvXupbFzG7SYFlVMMztKOD n4H0USMNHhK6xU2BVbXXdPuFglcyrPdcKAM8cqBCwtqeliIWWY53prvXj46aPwdUSGpM q1MHHlVOB6fxH1MZL6pjgbXPfQq9O/PAdNMvNKeM2ubMnY7NUnTeQlkS1mEWtNFUk2gf 7fYhHyaU5nf5ohskYviXn7KGIg5tFKJCeI1a+SsFbGG9NPz2HGSE9nAdAto5ttJOOaGb zpVWRKlsR/YtxuDridINif51Isn7I9pETYncSuYvSkwcAt4z1kzUOIU1FwiAqL5s+2Zc tw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f8jq0bxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:35:00 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089NX5YI065089; Wed, 9 Sep 2020 19:34:59 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f8jq0bx3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:34:59 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089NWsBA023911; Wed, 9 Sep 2020 23:34:58 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8dba4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 23:34:58 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089NXMXL64225740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 23:33:22 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 33897A405B; Wed, 9 Sep 2020 23:34:55 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7E44A4051; Wed, 9 Sep 2020 23:34:54 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.5.224]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Sep 2020 23:34:54 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Yauheni Kaliuta , Ilya Leoshkevich Subject: [PATCH RFC bpf-next 1/5] bpf: Make bpf_patch_insn_single() accept variable number of old insns Date: Thu, 10 Sep 2020 01:34:35 +0200 Message-Id: <20200909233439.3100292-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909233439.3100292-1-iii@linux.ibm.com> References: <20200909233439.3100292-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_17:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 bulkscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090202 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Since this changes the function's meaning, rename it to bpf_patch_insns(). It is still expected to only grow the function or to preserve its size, not to shrink it. Signed-off-by: Ilya Leoshkevich --- include/linux/filter.h | 4 ++-- kernel/bpf/core.c | 18 +++++++++--------- kernel/bpf/verifier.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index 995625950cc1..d926ab1cfada 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -892,8 +892,8 @@ static inline bool bpf_dump_raw_ok(const struct cred *cred) return kallsyms_show_value(cred); } -struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, - const struct bpf_insn *patch, u32 len); +struct bpf_prog *bpf_patch_insns(struct bpf_prog *prog, u32 off, u32 len_old, + const struct bpf_insn *patch, u32 len); int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt); void bpf_clear_redirect_map(struct bpf_map *map); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index ed0b3578867c..dde5f61f5a99 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -429,10 +429,10 @@ static void bpf_adj_linfo(struct bpf_prog *prog, u32 off, u32 delta) linfo[i].insn_off += delta; } -struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, - const struct bpf_insn *patch, u32 len) +struct bpf_prog *bpf_patch_insns(struct bpf_prog *prog, u32 off, u32 len_old, + const struct bpf_insn *patch, u32 len) { - u32 insn_adj_cnt, insn_rest, insn_delta = len - 1; + u32 insn_adj_cnt, insn_rest, insn_delta = len - len_old; const u32 cnt_max = S16_MAX; struct bpf_prog *prog_adj; int err; @@ -451,7 +451,7 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, * we afterwards may not fail anymore. */ if (insn_adj_cnt > cnt_max && - (err = bpf_adj_branches(prog, off, off + 1, off + len, true))) + (err = bpf_adj_branches(prog, off, off + len_old, off + len, true))) return ERR_PTR(err); /* Several new instructions need to be inserted. Make room @@ -468,14 +468,13 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, /* Patching happens in 3 steps: * * 1) Move over tail of insnsi from next instruction onwards, - * so we can patch the single target insn with one or more - * new ones (patching is always from 1 to n insns, n > 0). + * so we can patch the target insns. * 2) Inject new instructions at the target location. * 3) Adjust branch offsets if necessary. */ insn_rest = insn_adj_cnt - off - len; - memmove(prog_adj->insnsi + off + len, prog_adj->insnsi + off + 1, + memmove(prog_adj->insnsi + off + len, prog_adj->insnsi + off + len_old, sizeof(*patch) * insn_rest); memcpy(prog_adj->insnsi + off, patch, sizeof(*patch) * len); @@ -483,7 +482,8 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, * the ship has sailed to reverse to the original state. An * overflow cannot happen at this point. */ - BUG_ON(bpf_adj_branches(prog_adj, off, off + 1, off + len, false)); + BUG_ON(bpf_adj_branches(prog_adj, off, off + len_old, off + len, + false)); bpf_adj_linfo(prog_adj, off, insn_delta); @@ -1155,7 +1155,7 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_prog *prog) if (!rewritten) continue; - tmp = bpf_patch_insn_single(clone, i, insn_buff, rewritten); + tmp = bpf_patch_insns(clone, i, 1, insn_buff, rewritten); if (IS_ERR(tmp)) { /* Patching may have repointed aux->prog during * realloc from the original one, so we need to diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 814bc6c1ad16..dd0b138ee382 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9628,7 +9628,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of { struct bpf_prog *new_prog; - new_prog = bpf_patch_insn_single(env->prog, off, patch, len); + new_prog = bpf_patch_insns(env->prog, off, 1, patch, len); if (IS_ERR(new_prog)) { if (PTR_ERR(new_prog) == -ERANGE) verbose(env, From patchwork Wed Sep 9 23:34:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1361151 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bFOCNXZ7; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bn3Jm3kVXz9sSJ for ; Thu, 10 Sep 2020 12:50:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgIJB67 (ORCPT ); Wed, 9 Sep 2020 21:58:59 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:18784 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729789AbgIJBoP (ORCPT ); Wed, 9 Sep 2020 21:44:15 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089NUdHV189446; Wed, 9 Sep 2020 19:35:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=b3WFthoDKjKR9I/DkTgdZOS3smXy47kVdfX9G3THCXw=; b=bFOCNXZ7yUqXAStfONKEsKdG2qGlalLadJ1XXqdRFJEELtzY7NbnOcoeeUhQJUEuEgWq g1S4sTzEJ/prIWv4nzOK3HPFmtDm9k6wR5XK1P6jQfYouS1bxcPBz+EE6L7Y9kB2yggv H7ZxMnBiPnfFXvNVZtlCzufa1s615Zk7X8R4OuL2siP/Fo9dzRuEDKTEW31vzKaiEm0u GIHB4qipNHXQ4WGY+GtUioYZdDoY7/1RG3yEbAFjgh6ViCAiIcBjplp7fKncpxTRMcwg tjEhu7eWuedBU8wY+whlr4cDaYFmAwvDNOmaGR1DP3iOliCw3NPl0isAZK00C0c3xBum 5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33f86pgvej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:35:37 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089NWbII001417; Wed, 9 Sep 2020 19:35:37 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0b-001b2d01.pphosted.com with ESMTP id 33f86pgve4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:35:37 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089NWiBK026316; Wed, 9 Sep 2020 23:35:35 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma01fra.de.ibm.com with ESMTP id 33c2a811w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 23:35:35 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089NZWgX23658854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 23:35:32 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87125A4051; Wed, 9 Sep 2020 23:35:32 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 26684A4040; Wed, 9 Sep 2020 23:35:32 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.5.224]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Sep 2020 23:35:32 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Yauheni Kaliuta , Ilya Leoshkevich Subject: [PATCH RFC bpf-next 2/5] bpf: Make adjust_insn_aux_data() accept variable number of old insns Date: Thu, 10 Sep 2020 01:34:36 +0200 Message-Id: <20200909233439.3100292-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909233439.3100292-1-iii@linux.ibm.com> References: <20200909233439.3100292-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_17:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 mlxscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090202 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Since this changes the function's meaning, rename it to adjust_insns_aux_data(). The way this function used to be implemented for a single insn is somewhat tricky, and the new version preserves this behavior: 1. For both fast and slow paths, populate zext_dst at [off, off + cnt_old) positions from insns at [off + cnt - cnt_old, off + cnt) positions. On the fast path, this produces identical insn_aux_data and insnsi offsets. On the slow path the offsets are different, but they will be fixed up later. 2. If the prog size did not change, return (fast path). 3. Preserve all the aux data for the leading insns. 4. Preserve all the aux data for the trailing insns, including what has been produced during step 1. This is done by memcpying it to a different offset, which corrects the difference between insn_aux_data and insnsi offsets. 5. Populate seen and zext_dst for the remaining insns. Signed-off-by: Ilya Leoshkevich --- kernel/bpf/verifier.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index dd0b138ee382..077919ac3826 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9572,25 +9572,29 @@ static void convert_pseudo_ld_imm64(struct bpf_verifier_env *env) insn->src_reg = 0; } -/* single env->prog->insni[off] instruction was replaced with the range - * insni[off, off + cnt). Adjust corresponding insn_aux_data by copying - * [0, off) and [off, end) to new locations, so the patched range stays zero +/* Instructions from the range env->prog->insni[off, off + cnt_old) were + * replaced with the range insni[off, off + cnt). Adjust corresponding + * insn_aux_data by copying [0, off) and [off, end) to new locations, so the + * patched range stays zero. */ -static int adjust_insn_aux_data(struct bpf_verifier_env *env, - struct bpf_prog *new_prog, u32 off, u32 cnt) +static int adjust_insns_aux_data(struct bpf_verifier_env *env, + struct bpf_prog *new_prog, u32 off, + u32 cnt_old, u32 cnt) { struct bpf_insn_aux_data *new_data, *old_data = env->insn_aux_data; struct bpf_insn *insn = new_prog->insnsi; u32 prog_len; int i; - /* aux info at OFF always needs adjustment, no matter fast path - * (cnt == 1) is taken or not. There is no guarantee INSN at OFF is the - * original insn at old prog. + /* aux infos at [off, off + cnt_old) need adjustment even on the fast + * path (cnt == cnt_old). There is no guarantee the insns at [off, + * off + cnt_old) are the original ones at old prog. */ - old_data[off].zext_dst = insn_has_def32(env, insn + off + cnt - 1); + for (i = off; i < off + cnt_old; i++) + old_data[i].zext_dst = + insn_has_def32(env, insn + i + cnt - cnt_old); - if (cnt == 1) + if (cnt == cnt_old) return 0; prog_len = new_prog->len; new_data = vzalloc(array_size(prog_len, @@ -9598,9 +9602,10 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, if (!new_data) return -ENOMEM; memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off); - memcpy(new_data + off + cnt - 1, old_data + off, - sizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1)); - for (i = off; i < off + cnt - 1; i++) { + memcpy(new_data + off + cnt - cnt_old, old_data + off, + sizeof(struct bpf_insn_aux_data) * + (prog_len - off - cnt + cnt_old)); + for (i = off; i < off + cnt - cnt_old; i++) { new_data[i].seen = env->pass_cnt; new_data[i].zext_dst = insn_has_def32(env, insn + i); } @@ -9636,7 +9641,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of env->insn_aux_data[off].orig_idx); return NULL; } - if (adjust_insn_aux_data(env, new_prog, off, len)) + if (adjust_insns_aux_data(env, new_prog, off, 1, len)) return NULL; adjust_subprog_starts(env, off, len); return new_prog; From patchwork Wed Sep 9 23:34:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1361149 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=IZUUiDcQ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bn3H80phKz9sTd for ; Thu, 10 Sep 2020 12:48:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726440AbgIJCsc (ORCPT ); Wed, 9 Sep 2020 22:48:32 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38938 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728442AbgIJB7V (ORCPT ); Wed, 9 Sep 2020 21:59:21 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089NYoAm006178; Wed, 9 Sep 2020 19:36:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=F5yY13Ku9Oa07L6Qh1v3rTNCa/VIRzaa0yl9PlZh610=; b=IZUUiDcQN70Ie5g/juCoYjGFLS+9Hlbf3y+Op0VzV6ZHp8HuwM50T9s4HtWXssTWkRMd mauVtV8NzvG/9LRTBNPbA4ybKCRZomlLkv+lSMX9/PTdAV4jMNceLF16GY9dZ1ECfMA3 eAowa3TDdmTcS2ubV7fsRoAksVOxIKhkzVM14Vr+iFozdgRU0FgR+x2fzEg3Tw147tx8 A5s29orKso8D8jX+FevAN1GrmaklSs5S29KHw9YzjxgiqadCb9ksbYGnuyHDcn0fD13v NOm4NQyHnudtACvu1kwjTQCmAtFqPJjVEGDGAyEurEo9DaywW+cnspyL+bFuwkVxhA9X ng== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f8re841x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:36:17 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089NYuAq007107; Wed, 9 Sep 2020 19:36:17 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f8re8418-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:36:16 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089NWalo023856; Wed, 9 Sep 2020 23:36:14 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8dbbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 23:36:14 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089NYdSQ64225600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 23:34:39 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECD88A4040; Wed, 9 Sep 2020 23:36:11 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A414A4051; Wed, 9 Sep 2020 23:36:11 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.5.224]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Sep 2020 23:36:11 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Yauheni Kaliuta , Ilya Leoshkevich Subject: [PATCH RFC bpf-next 3/5] bpf: Make adjust_subprog_starts() accept variable number of old insns Date: Thu, 10 Sep 2020 01:34:37 +0200 Message-Id: <20200909233439.3100292-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909233439.3100292-1-iii@linux.ibm.com> References: <20200909233439.3100292-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_17:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 suspectscore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090207 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Simply adjust the fast path condition and the delta. No renaming needed in this case. Signed-off-by: Ilya Leoshkevich --- kernel/bpf/verifier.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 077919ac3826..6791a6e1bf76 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9614,17 +9614,18 @@ static int adjust_insns_aux_data(struct bpf_verifier_env *env, return 0; } -static void adjust_subprog_starts(struct bpf_verifier_env *env, u32 off, u32 len) +static void adjust_subprog_starts(struct bpf_verifier_env *env, u32 off, + u32 len_old, u32 len) { int i; - if (len == 1) + if (len == len_old) return; /* NOTE: fake 'exit' subprog should be updated as well. */ for (i = 0; i <= env->subprog_cnt; i++) { if (env->subprog_info[i].start <= off) continue; - env->subprog_info[i].start += len - 1; + env->subprog_info[i].start += len - len_old; } } @@ -9643,7 +9644,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of } if (adjust_insns_aux_data(env, new_prog, off, 1, len)) return NULL; - adjust_subprog_starts(env, off, len); + adjust_subprog_starts(env, off, 1, len); return new_prog; } From patchwork Wed Sep 9 23:34:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1361116 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=XzDnIL8q; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bn29q03x3z9sTg for ; Thu, 10 Sep 2020 11:58:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725772AbgIJB6j (ORCPT ); Wed, 9 Sep 2020 21:58:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52974 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727893AbgIJBjE (ORCPT ); Wed, 9 Sep 2020 21:39:04 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089NV6np093258; Wed, 9 Sep 2020 19:36:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=UtVGwcgokTQGGsRFQ9YKQlW9Re6DacOp1/VYozSm0KY=; b=XzDnIL8q+7lYg2spU+TbNR2tApa3Yk8QlSWml90eDsFLVdJ+zQcs8/RsKNqlVmnvEfm3 axAPcKjCnjMbQKYCFa0Mio/ztDhe579mr8xqGxefES4bidq+qhytNEMm+4xAUwG4av8c jv7yqmTsRYClff8fFbFT2l68UH/wkLiZrQmEwCHWwp+IC7n9cpbQv9AWYF1pl0tqC6gj YEqZ6GImo0e3B/fJJ/z9ql7DnsA9jFW0xn0kLb42nWQ2PAT1uyL8I8ZlnK5U7aKg3HH+ lfEmA8vd88jbAGerh1XbG+4FVEG8sJZg3Cz6ok4PYquBo1tCAmLnzsuzchtCfrW0ZSE5 JQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 33f6hfup49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:36:51 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089NYRVx104345; Wed, 9 Sep 2020 19:36:51 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 33f6hfup3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:36:51 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089NWD0x013772; Wed, 9 Sep 2020 23:36:49 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma05fra.de.ibm.com with ESMTP id 33f3yrg6ec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 23:36:49 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089NakSx39715274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 23:36:46 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FACDA404D; Wed, 9 Sep 2020 23:36:46 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DD06A4051; Wed, 9 Sep 2020 23:36:46 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.5.224]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Sep 2020 23:36:46 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Yauheni Kaliuta , Ilya Leoshkevich Subject: [PATCH RFC bpf-next 4/5] bpf: Make bpf_patch_insn_data() accept variable number of old insns Date: Thu, 10 Sep 2020 01:34:38 +0200 Message-Id: <20200909233439.3100292-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909233439.3100292-1-iii@linux.ibm.com> References: <20200909233439.3100292-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_17:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090202 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Since this changes the function's meaning, rename it to bpf_patch_insns_data(). There are quite a few uses - adjust them all instead of creating a wrapper, which is not worth it in this case. Signed-off-by: Ilya Leoshkevich --- kernel/bpf/verifier.c | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6791a6e1bf76..17c2e926e436 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9629,12 +9629,14 @@ static void adjust_subprog_starts(struct bpf_verifier_env *env, u32 off, } } -static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off, - const struct bpf_insn *patch, u32 len) +static struct bpf_prog *bpf_patch_insns_data(struct bpf_verifier_env *env, + u32 off, u32 len_old, + const struct bpf_insn *patch, + u32 len) { struct bpf_prog *new_prog; - new_prog = bpf_patch_insns(env->prog, off, 1, patch, len); + new_prog = bpf_patch_insns(env->prog, off, len_old, patch, len); if (IS_ERR(new_prog)) { if (PTR_ERR(new_prog) == -ERANGE) verbose(env, @@ -9642,9 +9644,9 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of env->insn_aux_data[off].orig_idx); return NULL; } - if (adjust_insns_aux_data(env, new_prog, off, 1, len)) + if (adjust_insns_aux_data(env, new_prog, off, len_old, len)) return NULL; - adjust_subprog_starts(env, off, 1, len); + adjust_subprog_starts(env, off, len_old, len); return new_prog; } @@ -9972,7 +9974,8 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, patch = zext_patch; patch_len = 2; apply_patch_buffer: - new_prog = bpf_patch_insn_data(env, adj_idx, patch, patch_len); + new_prog = bpf_patch_insns_data(env, adj_idx, 1, patch, + patch_len); if (!new_prog) return -ENOMEM; env->prog = new_prog; @@ -10011,7 +10014,8 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) verbose(env, "bpf verifier is misconfigured\n"); return -EINVAL; } else if (cnt) { - new_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt); + new_prog = + bpf_patch_insns_data(env, 0, 1, insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10059,7 +10063,8 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) }; cnt = ARRAY_SIZE(patch); - new_prog = bpf_patch_insn_data(env, i + delta, patch, cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + patch, cnt); if (!new_prog) return -ENOMEM; @@ -10157,7 +10162,8 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) } } - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); + new_prog = + bpf_patch_insns_data(env, i + delta, 1, insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10435,7 +10441,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) cnt = ARRAY_SIZE(mask_and_mod) - (is64 ? 1 : 0); } - new_prog = bpf_patch_insn_data(env, i + delta, patchlet, cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + patchlet, cnt); if (!new_prog) return -ENOMEM; @@ -10454,7 +10461,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) return -EINVAL; } - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10506,7 +10514,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) *patch++ = BPF_ALU64_IMM(BPF_MUL, off_reg, -1); cnt = patch - insn_buf; - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10590,7 +10599,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) map)->index_mask); insn_buf[2] = *insn; cnt = 3; - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10625,8 +10635,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) return -EINVAL; } - new_prog = bpf_patch_insn_data(env, i + delta, - insn_buf, cnt); + new_prog = bpf_patch_insns_data( + env, i + delta, 1, insn_buf, cnt); if (!new_prog) return -ENOMEM; @@ -10694,8 +10704,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env) BPF_REG_0, 0); cnt = 3; - new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, - cnt); + new_prog = bpf_patch_insns_data(env, i + delta, 1, + insn_buf, cnt); if (!new_prog) return -ENOMEM; From patchwork Wed Sep 9 23:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 1361119 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=BT4b1AhX; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Bn2B16hJ0z9sT6 for ; Thu, 10 Sep 2020 11:59:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbgIJB7C (ORCPT ); Wed, 9 Sep 2020 21:59:02 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44908 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729824AbgIJBpB (ORCPT ); Wed, 9 Sep 2020 21:45:01 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 089NZI5e128144; Wed, 9 Sep 2020 19:37:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=pBMLCZNcYuWQcclrP/ceXhKw5ZPXEsDgH8qPadhIZMA=; b=BT4b1AhXzbLFM8c947LEhRa+9tapDmN9/i/o4lOvmhePIX5TxydtYe+88ljywoh92Xq8 rpnMTlei+TaYQmFf75zXkhsnQQYz+IDMVIMWInUbFntrFMVPSKCbvKyQ7elWtNPc9TeG jBluvlRLAcuu/LttF6n20OZ/0kCGjY/cdRWW1oPlqV8WXp1UEOWib+/wbL4ov2tzOvjy Aak9T7juM9dFI3VmkI7tNtPA3JsE56jTOLFCG1MsRwpRMO48MsOIpZT9wGB+U9OJuzKx 69kupZSa4TR8rGdKa8ypNR9Hbwc4sBTgWD0rPX9esRtnBlvcw1gKK7jbmEQYIVKSIHt3 dA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f7v598b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:37:15 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089NZxjv131604; Wed, 9 Sep 2020 19:37:15 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 33f7v598ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 19:37:14 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 089NbDhW028000; Wed, 9 Sep 2020 23:37:13 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 33c2a8dbcv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Sep 2020 23:37:13 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 089NbAIu34406714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 9 Sep 2020 23:37:10 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8AD1FA4040; Wed, 9 Sep 2020 23:37:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 271D1A404D; Wed, 9 Sep 2020 23:37:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.5.224]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Sep 2020 23:37:10 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann Cc: bpf@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Yauheni Kaliuta , Ilya Leoshkevich Subject: [PATCH RFC bpf-next 5/5] bpf: Do not include the original insn in zext patchlet Date: Thu, 10 Sep 2020 01:34:39 +0200 Message-Id: <20200909233439.3100292-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909233439.3100292-1-iii@linux.ibm.com> References: <20200909233439.3100292-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-09_17:2020-09-09,2020-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 suspectscore=0 mlxlogscore=987 priorityscore=1501 malwarescore=0 impostorscore=0 adultscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090202 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org If the original insn is a jump, then it is not subjected to branch adjustment, which is incorrect. As discovered by Yauheni in https://lore.kernel.org/bpf/20200903140542.156624-1-yauheni.kaliuta@redhat.com/ this causes `test_progs -t global_funcs` failures on s390. Most likely, the current code includes the original insn in the patchlet, because there was no infrastructure to insert new insns, only to replace the existing ones. Now that bpf_patch_insns_data() can do insertions, stop including the original insns in zext patchlets. Fixes: a4b1d3c1ddf6 ("bpf: verifier: insert zero extension according to analysis result") Reported-by: Yauheni Kaliuta Signed-off-by: Ilya Leoshkevich --- kernel/bpf/verifier.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 17c2e926e436..64a04953c631 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9911,7 +9911,7 @@ static int opt_remove_nops(struct bpf_verifier_env *env) static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, const union bpf_attr *attr) { - struct bpf_insn *patch, zext_patch[2], rnd_hi32_patch[4]; + struct bpf_insn *patch, zext_patch, rnd_hi32_patch[4]; struct bpf_insn_aux_data *aux = env->insn_aux_data; int i, patch_len, delta = 0, len = env->prog->len; struct bpf_insn *insns = env->prog->insnsi; @@ -9919,13 +9919,14 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, bool rnd_hi32; rnd_hi32 = attr->prog_flags & BPF_F_TEST_RND_HI32; - zext_patch[1] = BPF_ZEXT_REG(0); + zext_patch = BPF_ZEXT_REG(0); rnd_hi32_patch[1] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, 0); rnd_hi32_patch[2] = BPF_ALU64_IMM(BPF_LSH, BPF_REG_AX, 32); rnd_hi32_patch[3] = BPF_ALU64_REG(BPF_OR, 0, BPF_REG_AX); for (i = 0; i < len; i++) { int adj_idx = i + delta; struct bpf_insn insn; + int len_old = 1; insn = insns[adj_idx]; if (!aux[adj_idx].zext_dst) { @@ -9968,20 +9969,21 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env, if (!bpf_jit_needs_zext()) continue; - zext_patch[0] = insn; - zext_patch[1].dst_reg = insn.dst_reg; - zext_patch[1].src_reg = insn.dst_reg; - patch = zext_patch; - patch_len = 2; + zext_patch.dst_reg = insn.dst_reg; + zext_patch.src_reg = insn.dst_reg; + patch = &zext_patch; + patch_len = 1; + adj_idx++; + len_old = 0; apply_patch_buffer: - new_prog = bpf_patch_insns_data(env, adj_idx, 1, patch, + new_prog = bpf_patch_insns_data(env, adj_idx, len_old, patch, patch_len); if (!new_prog) return -ENOMEM; env->prog = new_prog; insns = new_prog->insnsi; aux = env->insn_aux_data; - delta += patch_len - 1; + delta += patch_len - len_old; } return 0;