Some facts and notations before we start deriving the gradient:
- Trace and Frobenius product relation $$\left\langle A, B C\right\rangle={\rm tr}(A^TBC) := A : B C$$
- Cyclic properties of Trace/Frobenius product
\begin{align}
A : B C
&= BC : A \\
&= A C^T : B \\
&= {\text{etc.}} \cr
\end{align}
Towards this end, we rewrite your function
\begin{align}
f(x) &= a^T x b^T x\\
&= (a^Tx)^T b^Tx \\
&= a^Tx : b^T x
\end{align}
Now, we can obtain the differential first, and then the gradient of $\frac{\partial f(x)}{\partial x}$.
\begin{align}
df(x)
&= \left( a^T dx: b^T x \right) + \left( a^T x: b^T dx \right) \\
&= \left( b^T x : a^T dx \right) + \left( a^T x: b^T dx \right) \\
&= \left( ab^T x : dx \right) + \left( ba^T x: dx \right) \\
\end{align}
Thus, the gradient is
\begin{align}
\frac{\partial f(x)}{\partial x} = a b^T x + ba^T x.
\end{align}