From patchwork Mon Oct 16 09:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 153286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3343564vqb; Mon, 16 Oct 2023 02:44:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3Hm1lOwQ+1njvcf5fOafHBmVgkmIryDS7fBklpegAooQ7I401K7PbdvhnSbgf1GYsZ86j X-Received: by 2002:a05:6870:1ec7:b0:1ea:1510:d8df with SMTP id pc7-20020a0568701ec700b001ea1510d8dfmr5126116oab.4.1697449499327; Mon, 16 Oct 2023 02:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697449499; cv=none; d=google.com; s=arc-20160816; b=fyws3juXDYOWmhwcxqr26sC9HvVqE/6NfYLl1bZoJ0eBkE7FHjPsvO7a37NQDsEyVN sRWEacI6/uwZLQBGM0syEp1bIiyZM0/qlTFBFDezMLrwE3SQ3l9XJV6jupTvJ4n3uQWz dQ6zt8SiP9jKwMu3e+AzV+9UZ0h48dhjKkRF6lVqFFvDfn8yMikcXfFDknuXOG05LS7W V9rIk/E2A0PuPOVQLTklL0V92r86EW+rNC4pV0yJopjpbf7G/ryPzCHNnwKWNC7tJPhg jjFDjzNR6vbdIMdJ+aLxlv3reUJObWDAr8cyV93hcaslWvIG0aTRdRIe+C/GJIGfmHUF Os7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=XZ41LTcQ/jhuvm71U7Pu2C5REKXKw1uT35nBnDHvCi0=; fh=WlpeJ0+Nnj3aoV6/LWTyG7f1AXEbAan1Fl+nYwouLFY=; b=Apl6PgiYlz1AV0Exrvq9uNXqKxwXUuYXjqrsloqNxgOavjCHYr+sR6zPIpkp6oAUkM EbEvSE2BERxwMVQa7ld5Nl8x3JjArIOlTFqffMhQXQL1SY1BUqlByP7FJJeD3H5Lnva1 kkWgWg9EYzL8ZO+PLCR5iYVV5ta2/XpBRa+KDx8Up582hUoJYLPFslJp27U+y8ntc2dj /C6fNCPCq3gyu6IwGZLSYOAIEUkI/99z4K/0YMVguZzLuiEFQ/9oxOx02e44DyM7bIj6 LgI20p7wuAMTYmyAbwkXAaSDrBfc3PnW4rQoDO3HfuUi41kuBreVLXAKQAFGDVqyVrxI 9I6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=f8Sx9bhi; dkim=neutral (no key) header.i=@linutronix.de header.b=YOzmN1Ae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bt8-20020a632908000000b00578c9144913si10239463pgb.364.2023.10.16.02.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 02:44:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=f8Sx9bhi; dkim=neutral (no key) header.i=@linutronix.de header.b=YOzmN1Ae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1D3F9805ED0F; Mon, 16 Oct 2023 02:44:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbjJPJok (ORCPT + 18 others); Mon, 16 Oct 2023 05:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjJPJoj (ORCPT ); Mon, 16 Oct 2023 05:44:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 485FD97; Mon, 16 Oct 2023 02:44:38 -0700 (PDT) Date: Mon, 16 Oct 2023 09:44:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697449476; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XZ41LTcQ/jhuvm71U7Pu2C5REKXKw1uT35nBnDHvCi0=; b=f8Sx9bhieAcZyI5hq4fhl7cuSmF9vLGDtZFIINgWszInLTzC/pHyCgkrMWBt3YvHYri/UQ Zy+ihVWq7sm8tY/lFxgL+R61QVrH4Ho0xYabvvdNUCHIxRPP+rIy8QCTLxTl5Y7gLootYn HNxSd5qwqtc/QxFonAK9//XEUw8oXSFtElEsQiJZ8L6M8dPNOwldqr9JPTbHGmc6GmqYEt uc1XwEx+o4q831QoIu/bqREiUWx6qmZBCZbBTbh78lhh1d9XfAvUMAApIIwgx6hOiM53F6 Sz1uG8bA6sBUWd9ro6Vh8R9l9CLpKtPCUfmD8a2dbGXEn8aRthgLovnQPEvdgg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697449476; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XZ41LTcQ/jhuvm71U7Pu2C5REKXKw1uT35nBnDHvCi0=; b=YOzmN1AeiqI03bRgedwEgMEnFx/eR/QGwRsv0tHSAPG0/kavTeLjFo7GnD967fJAU6Ns9z J21pziET1LAWDyAw== From: "tip-bot2 for Binbin Wu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] selftests/x86/lam: Zero out buffer for readlink() Cc: Binbin Wu , Ingo Molnar , "Kirill A. Shutemov" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231016062446.695-1-binbin.wu@linux.intel.com> References: <20231016062446.695-1-binbin.wu@linux.intel.com> MIME-Version: 1.0 Message-ID: <169744947512.3135.5098809828724848406.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 16 Oct 2023 02:44:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779892248812890152 X-GMAIL-MSGID: 1779904806096898053 The following commit has been merged into the x86/mm branch of tip: Commit-ID: 29060633411a02f6f2dd9d5245919385d69d81f0 Gitweb: https://git.kernel.org/tip/29060633411a02f6f2dd9d5245919385d69d81f0 Author: Binbin Wu AuthorDate: Mon, 16 Oct 2023 14:24:46 +08:00 Committer: Ingo Molnar CommitterDate: Mon, 16 Oct 2023 11:39:57 +02:00 selftests/x86/lam: Zero out buffer for readlink() Zero out the buffer for readlink() since readlink() does not append a terminating null byte to the buffer. Also change the buffer length passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string is always null terminated. Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking") Signed-off-by: Binbin Wu Signed-off-by: Ingo Molnar Reviewed-by: Kirill A. Shutemov Link: https://lore.kernel.org/r/20231016062446.695-1-binbin.wu@linux.intel.com --- tools/testing/selftests/x86/lam.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c index eb0e469..8f9b06d 100644 --- a/tools/testing/selftests/x86/lam.c +++ b/tools/testing/selftests/x86/lam.c @@ -573,7 +573,7 @@ int do_uring(unsigned long lam) char path[PATH_MAX] = {0}; /* get current process path */ - if (readlink("/proc/self/exe", path, PATH_MAX) <= 0) + if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0) return 1; int file_fd = open(path, O_RDONLY); @@ -680,14 +680,14 @@ static int handle_execve(struct testcases *test) perror("Fork failed."); ret = 1; } else if (pid == 0) { - char path[PATH_MAX]; + char path[PATH_MAX] = {0}; /* Set LAM mode in parent process */ if (set_lam(lam) != 0) return 1; /* Get current binary's path and the binary was run by execve */ - if (readlink("/proc/self/exe", path, PATH_MAX) <= 0) + if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0) exit(-1); /* run binary to get LAM mode and return to parent process */