Received: by 10.223.185.116 with SMTP id b49csp1024589wrg; Wed, 21 Feb 2018 10:45:46 -0800 (PST) X-Google-Smtp-Source: AH8x224TE9N5nmNS903BqefN0Z1gOYzXfMbg46dIqGkJtSGvYbjtQUvzLkjRNijJkWTVmMg41zoZ X-Received: by 10.98.87.68 with SMTP id l65mr4182222pfb.72.1519238745907; Wed, 21 Feb 2018 10:45:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238745; cv=none; d=google.com; s=arc-20160816; b=o6ZPkie/3fB+xV2qNfg/0x3syjpS4Y6h6J0bLJDEvNNfmQiNY4y5juJas8dARxYF+o AjtTb/FoCh4sE+yVIYXTt2ef6121nUJpKsN53Uz0Rzh9eY+P5Af7nyW7ty6cReKBciNK jcoes8Dw/cssKFHKEtHzWjqU4W5BYwKNWJuaR+IwvG6RHZ87uuPxbGO+I7/GYbRiQwbt nOuUny78Ghg05GMs8J6lITv1Aws6fWjfl6ekLU5kN5Q46dqA9xRL9aCEvZeaMmM4GCZm A7tq28fFJZXs6g60Zl/pLTauWeW6FkuYtkJhiCM2ho8+zJ0SgAYdrtU0CuDD/3KGSjpy 3Ayw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Zt11f7o1/xKfS0nwUMI5kZuxrVbo8nocck3cbpkgJG4=; b=KBCV7q0Ii278og8VDO9J9I842b65mxatogolPaiAKDKwxnXDcZ1lYI2jzIR4bxZrlJ uXemMp8jVQf6lNIvMjvajX0WwSRfp0AbIJwNRvYYS2YZdUhIosW15e3GQ/HDBc11EOzV v+moZdxoIha+iL9l32jERzRfpA5l2RslyaCPHvkPKElIGAXh/bsl83UByf3eAtbtLKEV vMxFsamhPq0EBKlwxjKLugO4DkW/ThYqjQn+QCNJ3qIox0oUnmVvyTEi8YjlMHkSiy6W TkY3hRlzJ+50GJhQYF5rlDuYkUW9NZetgQ9Pt55taEC92VePdzNS1ZneQmYye93jrbe7 5NiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si4274509pgf.460.2018.02.21.10.45.31; Wed, 21 Feb 2018 10:45:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937030AbeBUNiZ (ORCPT + 99 others); Wed, 21 Feb 2018 08:38:25 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42514 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936138AbeBUNIj (ORCPT ); Wed, 21 Feb 2018 08:08:39 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 60BA111CC; Wed, 21 Feb 2018 13:08:38 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Dominik Brodowski , Andrew Lutomirski , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH 4.15 069/163] selftests/x86: Clean up and document sscanf() usage Date: Wed, 21 Feb 2018 13:48:18 +0100 Message-Id: <20180221124534.300516334@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dominik Brodowski commit d8e92de8ef952bed88c56c7a44c02d8dcae0984e upstream. Replace a couple of magically connected buffer length literal constants with a common definition that makes their relationship obvious. Also document why our sscanf() usage is safe. No intended functional changes. Suggested-by: Ingo Molnar Signed-off-by: Dominik Brodowski Cc: Andrew Lutomirski Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-kselftest@vger.kernel.org Cc: shuah@kernel.org Link: http://lkml.kernel.org/r/20180211205924.GA23210@light.dominikbrodowski.net Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/test_vdso.c | 11 ++++++++--- tools/testing/selftests/x86/test_vsyscall.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) --- a/tools/testing/selftests/x86/test_vdso.c +++ b/tools/testing/selftests/x86/test_vdso.c @@ -26,6 +26,9 @@ # endif #endif +/* max length of lines in /proc/self/maps - anything longer is skipped here */ +#define MAPS_LINE_LEN 128 + int nerrs = 0; typedef long (*getcpu_t)(unsigned *, unsigned *, void *); @@ -37,17 +40,19 @@ static void *vsyscall_getcpu(void) { #ifdef __x86_64__ FILE *maps; - char line[128]; + char line[MAPS_LINE_LEN]; bool found = false; maps = fopen("/proc/self/maps", "r"); if (!maps) /* might still be present, but ignore it here, as we test vDSO not vsyscall */ return NULL; - while (fgets(line, sizeof(line), maps)) { + while (fgets(line, MAPS_LINE_LEN, maps)) { char r, x; void *start, *end; - char name[128]; + char name[MAPS_LINE_LEN]; + + /* sscanf() is safe here as strlen(name) >= strlen(line) */ if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", &start, &end, &r, &x, name) != 5) continue; --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c @@ -33,6 +33,9 @@ # endif #endif +/* max length of lines in /proc/self/maps - anything longer is skipped here */ +#define MAPS_LINE_LEN 128 + static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *), int flags) { @@ -98,7 +101,7 @@ static int init_vsys(void) #ifdef __x86_64__ int nerrs = 0; FILE *maps; - char line[128]; + char line[MAPS_LINE_LEN]; bool found = false; maps = fopen("/proc/self/maps", "r"); @@ -108,10 +111,12 @@ static int init_vsys(void) return 0; } - while (fgets(line, sizeof(line), maps)) { + while (fgets(line, MAPS_LINE_LEN, maps)) { char r, x; void *start, *end; - char name[128]; + char name[MAPS_LINE_LEN]; + + /* sscanf() is safe here as strlen(name) >= strlen(line) */ if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s", &start, &end, &r, &x, name) != 5) continue;