mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-27 10:50:35 +00:00
Bug 1693534 - Avoid leaking the kernel version to the Web with amdgpu. r=jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D105636
This commit is contained in:
parent
63e49eada8
commit
4f51a00c2e
@ -11,6 +11,7 @@
|
||||
#include "HostWebGLContext.h"
|
||||
#include "js/ScalarType.h" // js::Scalar::Type
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/SanitizeRenderer.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/WebGLContextEvent.h"
|
||||
#include "mozilla/dom/WorkerCommon.h"
|
||||
@ -2055,7 +2056,9 @@ void ClientWebGLContext::GetParameter(JSContext* cx, GLenum pname,
|
||||
|
||||
const auto maybe = GetString(driverEnum);
|
||||
if (maybe) {
|
||||
retval.set(StringValue(cx, *maybe, rv));
|
||||
std::string renderer = *maybe;
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
retval.set(StringValue(cx, renderer, rv));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
56
dom/canvas/SanitizeRenderer.h
Normal file
56
dom/canvas/SanitizeRenderer.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_RendererSanitizer_h
|
||||
#define mozilla_RendererSanitizer_h
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
inline static void SanitizeRenderer(std::string& aRenderer) {
|
||||
// Remove DRM, kernel, and LLVM versions exposed by amdgpu.
|
||||
// The string looks like this:
|
||||
//
|
||||
// AMD Radeon (TM) GPU model Graphics (GPUgeneration, DRM
|
||||
// DRMversion, kernelversion, LLVM LLVMversion)
|
||||
//
|
||||
// e.g. AMD Radeon (TM) RX 460 Graphics (POLARIS11,
|
||||
// DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)
|
||||
//
|
||||
// OR
|
||||
//
|
||||
// AMD Radeon GPU model (GPUgeneration, DRM DRMversion, kernelversion, LLVM
|
||||
// LLVMversion)
|
||||
//
|
||||
// Just in case, let's handle the case without GPUgeneration, i.e.
|
||||
//
|
||||
// AMD Radeon GPU model (DRM DRMversion, kernelversion, LLVM LLVMversion)
|
||||
//
|
||||
// even though there's no existence proof of this variant.
|
||||
if (aRenderer.empty()) {
|
||||
return;
|
||||
}
|
||||
if (aRenderer.back() != ')') {
|
||||
return;
|
||||
}
|
||||
auto pos = aRenderer.find(", DRM ");
|
||||
if (pos != std::string::npos) {
|
||||
aRenderer.resize(pos);
|
||||
aRenderer.push_back(')');
|
||||
return;
|
||||
}
|
||||
pos = aRenderer.find(" (DRM ");
|
||||
if (pos != std::string::npos) {
|
||||
aRenderer.resize(pos);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace mozilla
|
||||
|
||||
#endif // mozilla_RendererSanitizer_h
|
59
dom/canvas/gtest/TestSanitizeRenderer.cpp
Normal file
59
dom/canvas/gtest/TestSanitizeRenderer.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "mozilla/dom/SanitizeRenderer.h"
|
||||
|
||||
TEST(SanitizeRenderer, TestRadeonTM)
|
||||
{
|
||||
std::string renderer(
|
||||
"AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, "
|
||||
"5.4.0-65-generic, LLVM 11.0.0)");
|
||||
std::string expectation("AMD Radeon (TM) RX 460 Graphics (POLARIS11)");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
||||
|
||||
TEST(SanitizeRenderer, TestRadeon)
|
||||
{
|
||||
std::string renderer(
|
||||
"AMD Radeon RX 5700 (NAVI10, DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)");
|
||||
std::string expectation("AMD Radeon RX 5700 (NAVI10)");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
||||
|
||||
TEST(SanitizeRenderer, TestRadeonWithoutGeneration)
|
||||
{
|
||||
std::string renderer(
|
||||
"AMD Radeon RX 5700 (DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)");
|
||||
std::string expectation("AMD Radeon RX 5700");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
||||
|
||||
TEST(SanitizeRenderer, TestVega)
|
||||
{
|
||||
std::string renderer("Radeon RX Vega");
|
||||
std::string expectation("Radeon RX Vega");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
||||
|
||||
TEST(SanitizeRenderer, TestIntel)
|
||||
{
|
||||
std::string renderer("Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)");
|
||||
std::string expectation("Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
||||
|
||||
TEST(SanitizeRenderer, TestPipe)
|
||||
{
|
||||
std::string renderer("llvmpipe (LLVM 11.0.0, 256 bits)");
|
||||
std::string expectation("llvmpipe (LLVM 11.0.0, 256 bits)");
|
||||
mozilla::dom::SanitizeRenderer(renderer);
|
||||
EXPECT_EQ(renderer, expectation);
|
||||
}
|
15
dom/canvas/gtest/moz.build
Normal file
15
dom/canvas/gtest/moz.build
Normal file
@ -0,0 +1,15 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
"/dom/canvas",
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"TestSanitizeRenderer.cpp",
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = "xul-gtest"
|
@ -62,6 +62,7 @@ EXPORTS.mozilla.dom += [
|
||||
"IpdlQueue.h",
|
||||
"OffscreenCanvas.h",
|
||||
"QueueParamTraits.h",
|
||||
"SanitizeRenderer.h",
|
||||
"TextMetrics.h",
|
||||
"WebGLChild.h",
|
||||
"WebGLCommandQueue.h",
|
||||
@ -177,6 +178,10 @@ IPDL_SOURCES += [
|
||||
"PWebGL.ipdl",
|
||||
]
|
||||
|
||||
TEST_DIRS += [
|
||||
"gtest",
|
||||
]
|
||||
|
||||
# Suppress warnings from third-party code.
|
||||
if CONFIG["CC_TYPE"] in ("clang", "gcc"):
|
||||
SOURCES["MurmurHash3.cpp"].flags += ["-Wno-implicit-fallthrough"]
|
||||
|
Loading…
Reference in New Issue
Block a user